hass-circadian_lighting icon indicating copy to clipboard operation
hass-circadian_lighting copied to clipboard

Light profiles

Open basnijholt opened this issue 3 years ago • 10 comments

@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 avatar Sep 06 '20 09:09 basnijholt

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

iamcagn avatar Sep 10 '20 04:09 iamcagn

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.

iamcagn avatar Sep 10 '20 09:09 iamcagn

@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.

iamcagn avatar Sep 13 '20 22:09 iamcagn

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

iamcagn avatar Sep 14 '20 00:09 iamcagn

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.

iamcagn avatar Sep 18 '20 01:09 iamcagn

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.

basnijholt avatar Sep 18 '20 13:09 basnijholt

@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.

iamcagn avatar Sep 19 '20 23:09 iamcagn

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.

iamcagn avatar Sep 20 '20 23:09 iamcagn

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

basnijholt avatar Sep 21 '20 10:09 basnijholt

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!

Sergiodiaz53 avatar Apr 28 '22 06:04 Sergiodiaz53