Circadian Lighting [Custom Component]

Thanks, I couldn’t find it in there, but I managed to work it out.
Needed to create an input Boolean, so I can mark when I’m asleep and later automate that Boolean.
I also noticed the disable_entiry feature so I’m going to try using that to determine if the lights are on, rather than using the automations I set up earlier.
The learning curve is quite steep with Hass, but it starting to level out, I expect it gets steep again with more advanced use.
I’m impressed how instantaneous it all works.
If I tap the sleep Boolean, the lights respond immediately.

Yes indeed, steep learning curve, that’s my experience too!

From NodeRed I’m pretty sure I’m able to change both brightness and temperature in the same call for my Tradfri lights:

{"color_temp":"454","transition":"1","brightness_pct":"10"}

What’s the difference here?

Would swapping Tradfri Gateway for Zigbee2mqtt help with these issues?

Cheers! and @claytonjn thanks for a great component!

And does it actually change both temperature and brightness on your bulb? I can make the call containing both brightness and temperature, but only brightness changes. Zigbee2mqtt: I just installed it, will check soon.

Interesting. I’m pretty sure it does both - at least this automation has been running for a long time and I’ve never noticed! - but I’ll have to check when I’m home now.

R.E. Zigbee2mqtt thanks! I have a Zigbee USB stick, but I haven’t yet implemented it. This could be the motivation I need!

@KGigi, please try enabling debug logging and look for circadian_lighting entries when the binary_sensor.living_room_rgb is both on and off.

I may be wrong but I think the in the disable_state field on should be “on”

That was what was stopping sleep mode from working for me. Can anyone confirm this?

@claytonjn @samnewman86, thanks for your help. Putting the state in quotes got the disable state working however it did not fix the original issue. Based on the logs the state is reset before the disable state is read:

2019-07-30 11:33:21 DEBUG (SyncWorker_0) [custom_components.circadian_lighting.switch] light.living_room_aux CT Adjusted - color_temp: 184, brightness: None, transition: 1
2019-07-30 11:33:21 DEBUG (SyncWorker_5) [custom_components.circadian_lighting.switch] Living Room AUX disabled by binary_sensor.living_room_rgb

What is really interesting is that even after the color is reset I still get lines saying that the switch is disabled even though the binary sensor is no longer on.

That’s definitely not happening, but it is interesting that the two entries show two different SyncWorkers…is it possible you have this light set up under multiple CL switches?

That also shouldn’t be the case, but CL only knows what HA tells it…not sure why it would be getting bad information.

You might be better off just using an automation to turn the CL switch on/off, rather than dealing with the template sensor.

@claytonjn My lights are groupped into several virtual lights so they would be easier to use. After reading what you wrote I simplified my CL configuration like this and added the suggested automation:

switch:
  - platform: circadian_lighting
    name: Living Room Circadian
    disable_brightness_adjust: true
    lights_ct:
      - light.living_room_lights

light:
  - platform: lifx
  - platform: group
    name: Living Room Ceiling
    entities:
      - light.lrc1
      - light.lrc2
      - light.lrc3
      - light.lrc4
      - light.lrc5
  - platform: group
    name: Living Room AUX
    entities:
      - light.lrw
      - light.lamp
  - platform: group
    name: Living Room Lights
    entities:
      - light.lrc1
      - light.lrc2
      - light.lrc3
      - light.lrc4
      - light.lrc5
      - light.lrw
      - light.lamp

automation:
  - alias: Living Room RGB
    initial_state: true
    trigger:
      platform: state
      entity_id: binary_sensor.living_room_rgb
      from: 'off'
      to: 'on'
    action:
      service: switch.turn_off
      data:
        entity_id: switch.circadian_lighting_living_room_circadian

To test I set the currently turned on Living Room AUX light to red. What happens is that the circadian switch turns off (so the automation is working as expected) however not only do my AUX lights get reset to white color but my turned off ceiling lights get turned on with a white color as well.

If I only use the Living Room Lights entity to match what is used in the CL component and the automation the lights turn red then immidiately turn back to white even though the CL switch is disabled. Is it possible that the switch has a delay until it realises that it is turned off and should no longer control the lights? If I set the lights back to red after a couple of seconds they stay that way as expected.

The same happens if I don’t use the binary sensor and I wire the state directly into the automation:

- alias: Living Room RGB
  initial_state: true
  trigger:
    platform: template
    value_template: "{{ state_attr('light.living_room_lights', 'rgb_color') != None }}"
  action:
    service: switch.turn_off
    data:
      entity_id: switch.circadian_lighting_living_room_circadian

No, but I think it just occurred to me what’s happening. In order for CL to quickly adjust a light when it’s turned on, CL “listens” for state changes. So I believe when you set the light to red CL is reacting moments before the automation fires to disable CL.

I have some ideas on how to fix this…what is your end goal? Do you want to be able to set the color of the light through the frontend, or do you want to set the color in an automation?

@claytonjn I would like to use the LIFX lights to their full potential (e.g. music visualizer) without manually turning CL on and off. So it should adjust the lights when they are not in color mode but leave them alone when they are. That’s why I tried to use the disable entity feature at first.

I understand that, but I’m asking how you’re planning on using features like music visualizer. I assume you mean that you want to be able to just open the LIFX app and use a music visualizer feature? How do you plan on re-enabling CL when you’re no longer using those features?

The music visualizer only works from the LIFX app, some other effects work directly from Home Assistant. But it doesn’t really matter. I just want to be able to disable CL while the lights are in color mode. I already know that the rgb_color and other color attributes are set to “None” when they are in white mode so I can use that to turn the switch on or off. Unfortunately that doesn’t work because the switch resets/updates the lights’ state before it is turned off. It looks like I cannot use the lights’ state as a condition for CL.

Like I said, I have some ideas. I just need to know exactly what you want to do so I don’t waste my time making changes that won’t solve your issue.

So assuming that you can use the rgb_color attribute to disable CL when the lights are in color mode, how do you want to be able to re-enable CL?

Thank you very much for taking the time to look into this. My plan to re-enable CL is the same backwards. When rgb_color is set back to “None” I just turn it back on. But this is an absolutely nice to have feature as it can be done with a few lines of automation. The problematic part is turning CL off by using the state of the light it is controlling.

I just pushed 1.0.8b, try that. You should be able to use the template sensor or the template in the automation to disable CL. The only issue you may still have is if you’re turning the light on and setting it to a color mode at the same time - if the light is already on and you switch it to a color mode then hopefully this fixes the issue. Let me know how it goes.

I’ve been trying to fix the issue I’ve long had with the transition and interval not working. I got the latest updates installed, configured 300/30 as times and just now tried splitting up the switches. There’s now a seperate switch for brightness and for color. Sadly this still doesn’t work properly on my gen1 lights with the gen2 hub. No transitions at all. It just seems to fire non stop, correcting the lights instantly. Is there anything I can do to perhaps resolve this issue? This custom component rocks and with the right transition times it would be boss.

Interval and transition only apply for adjusting lights throughout the day; when you turn a light on CL will immediately change the light to the proper value. I could add a configuration option for something like “initial transition” but I hesitate to do so because the CL configuration is already relatively complex.

I believe you’re the first person to bring this up, but I added an issue in GitHub so people can comment or +1 it if they’re also interested in this option.

Thank you!
Should it also instantly update when then lights are already on but I pick a different scene? Just so I know when testing.