Skip to content

Light profiles#114

Closed
basnijholt wants to merge 14 commits into
claytonjn:devfrom
basnijholt:light-profile
Closed

Light profiles#114
basnijholt wants to merge 14 commits into
claytonjn:devfrom
basnijholt:light-profile

Conversation

@basnijholt

@basnijholt basnijholt commented Sep 6, 2020

Copy link
Copy Markdown
Contributor

@markianwallace and @iamcagn, could you guys try the code of #114?

It works like this:

circadian_lighting:
  - profile: default
    min_colortemp: 2000
    interval: 30
  - profile: early
    min_colortemp: 3000
    interval: 10
    sunset_time: "16:00:00"

and

switch:
  - platform: circadian_lighting
    profile: early  # <----------------profile
    lights_rgb:
      - light.ceiling_kitchen
    lights_ct:
      - light.stairs_up
      - light.stairs_down

Note that

circadian_lighting:
  min_colortemp: 2000
  interval: 30

is internally converted to

circadian_lighting:
  - profile: default
    min_colortemp: 2000
    interval: 30

So it's fully backward compatible.

@basnijholt basnijholt changed the base branch from master to dev September 6, 2020 09:55
@basnijholt basnijholt changed the title Light profiles WIP: Light profiles Sep 6, 2020
@basnijholt basnijholt changed the title WIP: Light profiles Light profiles Sep 7, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the service_call because I am not sure how to best do it once there are multiple sensors. Also I think it's not really needed. If you want frequent updates, just decease the interval?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how much the service call is used, TBH. Off the top of my head I could imagine it would be useful with the only_once option where a user may want to control exactly when a light adjusts (e.g. any time there's motion).

@itsanib

itsanib commented Sep 10, 2020

Copy link
Copy Markdown

Hi @basnijholt and @claytonjn, I'm implimenting this now and will report back after a day or two of use 👍

@itsanib

itsanib commented Sep 10, 2020

Copy link
Copy Markdown

Just a quick update to say so far I've had no problems. I setup profiles per room and applied them to the light groups without issue. I also got around to setting up my auto-disable system where it checks if the light is ~ the correct temp. It works even if I adjust the lights using the Google Home or apps outside of Home Assistant.

- profile: loungeroom
  min_colortemp: 2800
  max_colortemp: 4000
  sunset_offset: -00:30:00
  interval: 300
  transition: 2
- platform: circadian_lighting
  name: Loungeroom
  profile: loungeroom
  min_brightness: 60
  max_brightness: 100
  initial_transition: 5
  disable_entity: sensor.loungeroom_circadian_lighting_enabled
  disable_state: false
  lights_ct:
    - light.loungeroom_downlight_left_1
    - light.loungeroom_downlight_left_2
    - light.loungeroom_downlight_left_3
    - light.loungeroom_downlight_left_4
    - light.loungeroom_downlight_right_1
    - light.loungeroom_downlight_right_2
    - light.loungeroom_downlight_right_3
    - light.loungeroom_downlight_right_4
- platform: template
   sensors:
     loungeroom_circadian_lighting_enabled:
       friendly_name: Loungeroom circadian lighting enabled
       value_template: >-
         {% set sensor_current_mirds  = (1000000 / state_attr('sensor.circadian_values_loungeroom', 'colortemp')) | int %}
         {% set light_current_mirds = state_attr('light.loungeroom_downlights', 'color_temp') | int %}
         {% set offset = 5 %}
         {% set range_low = sensor_current_mirds - offset %}
         {% set range_high = sensor_current_mirds + offset %}
         {% if not light_current_mirds >= range_low and light_current_mirds <= range_high %}
         false
         {% else %}
         true
         {% endif %}

I had to add an offset as sometimes what the sensor value is and what the light reports are different, I assume as it depends on what the light can actually produce.

@itsanib

itsanib commented Sep 13, 2020

Copy link
Copy Markdown

@basnijholt and @claytonjn

Now when I restart HASS, I get a notification with:

The following integrations and platforms could not be set up:

circadian_lighting
circadian_lighting.switch
Please check your config.

I also get the following error in my logs:

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 191, in _async_setup_component
result = await task
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/circadian_lighting/init.py", line 120, in setup
hass.data[DOMAIN][profile] = CircadianLighting(
File "/config/custom_components/circadian_lighting/init.py", line 173, in init
self._percent = self.calc_percent()
File "/config/custom_components/circadian_lighting/init.py", line 312, in calc_percent
a = (y - k) / (h - x) ** 2
UnboundLocalError: local variable 'k' referenced before assignment

I commented out the disable_entity/disable_state just in case they were the cause but still get the error.

@itsanib

itsanib commented Sep 14, 2020

Copy link
Copy Markdown

After regrabbing #114 and replacing the folder under custom_components it appears to be working again.

@itsanib

itsanib commented Sep 18, 2020

Copy link
Copy Markdown

So I've still been getting those errors, and it occurs after I update the sunrise_offset and restart HASS. If I reboot the Pi, it loads fine.

@basnijholt

Copy link
Copy Markdown
Contributor Author

Are you sure you used the updated code? I rebased and force pushed here. So you need to download a new copy of the repo.

@itsanib

itsanib commented Sep 19, 2020

Copy link
Copy Markdown

@basnijholt I downloaded #114 from this page, using the "Open With" button and then "Open in Desktop". Once pulled, I removed Circadian Lighting from HACS and installed this one manually by copying it into the custom_components. I think that's all correct and I have the updated files, but if not please let me know. Profiles are working, so I assume it is.

I'm able to replicate the issue pretty reliably. I have the following profile for a room:

- profile: office
  min_colortemp: 2800
  max_colortemp: 4000
  sunrise_offset: -01:30:00
  sunset_offset: 01:00:00
  interval: 300
  transition: 2

I then commented the sunrise offset out:

- profile: office
  min_colortemp: 2800
  max_colortemp: 4000
  # sunrise_offset: -01:30:00
  sunset_offset: 01:00:00
  interval: 300
  transition: 2

After restarting HASS from Configuration -> Server Control -> Restart, I get the follow notification and error log:

Invalid config
The following integrations and platforms could not be set up:

circadian_lighting
circadian_lighting.switch
Please check your config.

Log Details (ERROR)
Logger: homeassistant.setup
Source: custom_components/circadian_lighting/init.py:312
First occurred: 8:52:43 AM (1 occurrences)
Last logged: 8:52:43 AM

Error during setup of component circadian_lighting
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 213, in _async_setup_component
result = await task
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/circadian_lighting/init.py", line 120, in setup
hass.data[DOMAIN][profile] = CircadianLighting(
File "/config/custom_components/circadian_lighting/init.py", line 173, in init
self._percent = self.calc_percent()
File "/config/custom_components/circadian_lighting/init.py", line 312, in calc_percent
a = (y - k) / (h - x) ** 2
UnboundLocalError: local variable 'k' referenced before assignment

I've had mixed success getting it back working, just now I had to roll back to an earlier backup as rebooting the Pi, disabling and reenabling the config as well as re-pulling the code didn't fix it.

Update: rolling back didn't fix it either.

@itsanib

itsanib commented Sep 20, 2020

Copy link
Copy Markdown

I saw https://github.com/claytonjn/hass-circadian_lighting/pull/119/files was mentioned as a possible fix for another user, modified the init file as I can see that #119 doesn't have the profile feature and it appears to have solved my issue too.

@basnijholt

Copy link
Copy Markdown
Contributor Author

@iamcagn, I have added that fix to this PR too now 😄

basnijholt added a commit to basnijholt/home-assistant that referenced this pull request Sep 26, 2020
basnijholt added a commit to basnijholt/home-assistant that referenced this pull request Dec 19, 2020
@Sergiodiaz53

Copy link
Copy Markdown

Hi there!

Is this still working? I'm really interested in adjusting temperature by group because I have different types of bulb.

Thanks in advance!

@claytonjn claytonjn closed this Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants