Update: You might consider using @basnijholt’s new and improved Circadian Lighting fork named “Adaptive Lighting” instead. It has a lot more intelligence built in to avoid issues like this.
However, if you still have problems with Zigbee light groups not turning off every bulb, then look at this much simplified automation instead.
Circadian Lighting: Possible fix to make light groups stay turned off
Difficulty: Advanced
The problem
I have multiple light fixtures which have more than one Zigbee bulb. So I created Zigbee groups for each fixture. Unfortunately, with Circadian Lighting enabled for these light groups, the bulbs all turn back on within 2 seconds - 2 minutes. This is a known issue without a documented fix so far.
The problem occurs while the bulbs fade to black. The light group briefly itself off
to Home Assistant, but then realizes bulbs in the group have a brightness > 0%, so it changes the state back to on
. Well, Circadian Lighting now sees a light
which has just turned on
, so it dutifully starts adjusting the light colors/brightness appropriate for the current time of day. <sarcasm>How helpful!</sarcasm>
Now that we know the problem, I managed to come up with a solution which took some extra work to pull off. In the end I think the effort is work it (so long as it ends up being as reliable as I hope it is).
Proposed solution
I have put together an automation which triggers when one of my light groups turn off. It relies on several of the features added in 0.113: mode: parallel, and an until loop!
Home Assistant group of lights
Unfortunately ZHA doesn’t provide a list of entity_id’s in the light group, so I created light fixture groups for all four of my fixtures. Here is one such example.
group:
name: Family Room Floor Lamp Fixture
entities:
- light.family_room_floor_lamp1
- light.family_room_floor_lamp2
- light.family_room_floor_lamp3
Circadian Lighting switches
I broke my Circadian Lighting mode switches up. Here is are two examples.
switch:
- platform: circadian_lighting
name: Dining Room
lights_ct:
- light.dining_room
- platform: circadian_lighting
name: Family Room Floor Lamp
lights_brightness:
- light.family_room_floor_lamp
Light group turns off automation
Here I break down what happens when I turn my Family Room Floor Lamp off.
- This automation is triggered when the Floor Lamp’s state changes to
off
(ie.light.family_room_floor_lamp
). - Don’t bother preforming any actions if Circadian Lighting mode is disabled for the Floor Lamp (ie.
switch.circadian_lighting_family_room_floor_lamp
). - Temporarily disables Circadian Lighting mode only for the Floor Lamp.
- Delay for 5 seconds.
- Tell Home Assistant to turn off the Floor Lamp’s “Home Assistant group of lights” (ie.
group.family_room_floor_lamp_fixture
). - Are the lights actually off now? If not, return to step #4.
- Delay for 5 seconds.
- Enable Circadian Lighting mode for the Floor Lamp.
alias: "Circadian Lighting: Force Light Groups To Stay Off"
id: circadian_light_group_turn_off
initial_state: true
mode: parallel
trigger:
- platform: state
entity_id:
- light.brian
- light.dining_room
- light.family_room_floor_lamp
- light.play_room_floor_lamp
to: "off"
condition:
# Only when circadian lighting is enabled for this light group.
- condition: template
value_template: "{{ is_state(trigger.entity_id|replace('light.','switch.circadian_lighting_'), 'on') }}"
action:
# Temporarily disable the circadian lighting mode for this fixture.
- service: switch.turn_off
data_template:
entity_id: "{{ trigger.entity_id|replace('light.','switch.circadian_lighting_') }}"
- alias: Turn the light group off repeatedly until it stays off.
repeat:
sequence:
- delay:
seconds: 5
# Turn the light group off, again.
- service: homeassistant.turn_off
data_template:
entity_id: "{{ trigger.entity_id|replace('light.','group.') + '_fixture' }}"
until:
- condition: template
value_template: "{{ is_state(trigger.entity_id, 'off') }}"
- delay:
seconds: 5
# Turn the circadian lighting mode back on.
- service: switch.turn_on
data_template:
entity_id: "{{ trigger.entity_id|replace('light.','switch.circadian_lighting_') }}"
Conclusion
I have only has this solution in place for a couple of hours so I don’t know how reliable it will be in the long run. Thus far it is a massive improvement over the failure I was experiencing before this fix.
Honestly this solution is complex. You could probably simplify the code a bit by avoiding the ZHA and Home Assistant Light Groups (ie. light.family_room_floor_lamp
), and directly controlling the lights GROUP (ie. group.family_room_floor_lamp
).