question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

question about disabling circadian lighting

See original GitHub issue

Hi, I just discovered this component and I love it! That said, having said that, I sometimes might not want to use it 😃

If I’m writing an automation to manually adjust brightness or color temperature, I can turn off the switch for CL. I also know there is a disable_entity and disable_state option that I can use to monitor another entity. But is there any way to intercept a change to, say, brightness that is done via the Alexa integration in HA and use that to tell CL to stop controlling a particular light? If someone explicitly sets the light configuration, it’s a pretty good sign that they want control (probably with a timeout; that’s for later), and not have the automatic CL.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
mikeagecommented, Nov 2, 2019

So first of all, I’m an idiot 😃 The two changes I was seeing was because I’m toggling a light group… with two bulbs. Didn’t dawn on me until I started looking at the CL logs that it’d toggle the lights individually; the first arrived when only one light had changed, so the group’s change was effectively half (the average…) of what it desired. Anyway…

I did see the link, and I’m using it now (there’s a typo there; service.cancel should be service.turn_off). I chose to cancel the first and use the second, figuring that if it needs a delay, best to use the delay after the last change. In any case, it seems like 5 seconds is far too much, but that’s all right for now.

Ideally, though, I’d love if there was some way to have both scripts run to completion. The reason is that I want to template this and apply it to a bunch of lights and groups, and if I change multiple lights in close succession, canceling the script for light 1 just because light 2 changed isn’t the right thing to do. But worst case, copy paste.

Here’s what I’m using now (slightly improved over the original, where I use an input_select to have a tristate “On / Temporarily Off / Off” for CL rather than just On/Off. This will let me reset it as needed if there was a manual override (maybe on the next off, maybe after 60 minutes, maybe the next day, whatever):

configuration.yaml

light:
  - platform: group
    name: Parents' Room Lights
    entities:
      - light.yeelight_ct2_7c49eb1a8ee6
      - light.yeelight_ct2_7c49eb1a8f09
switch:
  - platform: circadian_lighting
    name: parents_room
    lights_ct:
      - light.yeelight_ct2_7c49eb1a8ee6
      - light.yeelight_ct2_7c49eb1a8f09

input_select:
  circadian_lighting_parents_room:
    name: Circadian Lighting Parents Room
    options:
      - 'On'
      - 'Overridden'
      - 'Off'
    icon: mdi:theme-light-dark

automation.yaml (still has some debug left in)

- id: cl_disable_parents
  alias: 'Disable Circadian Light on manual change'
  trigger:
    platform: state
    entity_id: light.parents_room_lights
  condition:
  - condition: state
    entity_id: switch.circadian_lighting_parents_room
    state: 'on'
  - condition: template
    value_template: "{{ trigger.from_state.state == 'on' }}"
  - condition: template
    value_template: "{{ trigger.to_state.state == 'on' }}"
  action:
  - service: script.turn_off
    entity_id: script.cl_disable_parents
  - service: script.cl_disable_parents
    data_template:
      trigger_to_state_object_id: "{{ trigger.to_state.object_id }}"

- id: cl_disable_parents_internal
  alias: 'Disable Circadian Light on manual change (internal)'
  trigger:
  - platform: state
    entity_id: input_select.circadian_lighting_parents_room
  action:
  - service_template: "switch.{% if is_state('input_select.circadian_lighting_parents_room', 'Off') or is_state('input_select.circadian_lighting_parents_room', 'Overridden') %}turn_off{% else %}turn_on{% endif %}"
    data:
      entity_id: switch.circadian_lighting_parents_room

script.yaml:

cl_disable_parents:
  alias: Disable Circadian Lighting Parents Room
  sequence:
  - service: system_log.write
    data_template:
      message: "CL Disable triggered. Comparisons will be: {{ ((1000000 / states['light'][trigger_to_state_object_id].attributes.color_temp) | int) }} -  {{ state_attr('sensor.circadian_values', 'colortemp') }} and {{ ((100 * states['light'][trigger_to_state_object_id].attributes.brightness / 255) | int) }} - {{ state_attr('switch.circadian_lighting_parents_room', 'brightness') }}. Now waiting"
      level: info
  - delay: 00:00:05
  - service: system_log.write
    data_template:
      message: "After the delay. Comparisons are: {{ ((1000000 / states['light'][trigger_to_state_object_id].attributes.color_temp) | int) }} -  {{ state_attr('sensor.circadian_values', 'colortemp') }} and {{ ((100 * states['light'][trigger_to_state_object_id].attributes.brightness / 255) | int) }} - {{ state_attr('switch.circadian_lighting_parents_room', 'brightness') }}. Now checking..."
      level: info
  - condition: or
    conditions:
    - condition: template
      value_template: "{{ (((1000000 / states['light'][trigger_to_state_object_id].attributes.color_temp) | int) - state_attr('sensor.circadian_values', 'colortemp')) | abs > 200 }}"
    - condition: template
      value_template: "{{ (((100 * states['light'][trigger_to_state_object_id].attributes.brightness / 255) | int) - state_attr('switch.circadian_lighting_parents_room', 'brightness')) | abs > 5 }}"
  - service: input_select.select_option
    data:
      entity_id: input_select.circadian_lighting_parents_room
      option: "Overridden"
2reactions
TravelinMaxcommented, Oct 31, 2019

How about an automation like this: trigger: state change of your lights condition: color and brightness of lights doesn’t equal color and brightness of CL component AND light is not off (so you don’t turn off CL when you turn off a light) action: turn off CL

You might have to add a delay before you check the color and brightness if your lights don’t turn on to the right color immediately. You also might have to add a range to the color and brightness check (within 1 or 2%).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Circadian pioneer says we're not ready for ...
Ask circadian science expert Russell Foster to comment on the ways in which LED lighting can buoy human health by mimicking the sun's ......
Read more >
Turn off all the lights at night: Your heart will thank you - NHLBI
Turning off all the lights at bedtime may improve your heart health by reducing the risk of obesity, diabetes, and high blood pressure....
Read more >
5 Big Questions: Circadian Lighting
If circadian lighting is science-based, why are there such vastly different approaches to circadian-focused lighting solutions in the market. (4 ...
Read more >
Circadian Lighting: Possible fix to keep light groups off
The problem occurs while the bulbs fade to black. The light group briefly ... Disable the circadian switch where this light belongs to...
Read more >
5 Answers About Human-Centric Lighting
For the past century, lighting—from fixtures and device screens alike—has significantly impacted our circadian rhythms. Electric light has ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found