Circadian Lighting: Possible fix to keep light groups off

Thanks for confirming that. Hope HA will get improvments in this area.

I have a feeling your approach works only for detached buttons / smart bulbs . If one is using switches which directly turns lights on, the only way is to intercept turning on the light and send proper settings afterward.

It wouldn’t be a case if there were no devices which can change light settings being turned off. But it’s opposite so there is opportunity to fully use this feature instead of working around. But tbh I’m not sure this idea will get any traction in HA. Maybe after circadian integration being official component it has better chances

Just define these template sensors: https://github.com/basnijholt/home-assistant-config/blob/93d42dba1fc0d1eeaf33e1c2260807bc3cc6d7b4/includes/sensors.yaml#L264-L282

1 Like

You are using NR already so stick with it.
Here is fragment of my flow which extracts brightness and warmth from circadian sensor and switch. Then store those values into sensors created from within NodeRed.
Also you can see how I joined those values into one payload in order to distribute them later on to my mqtt lights.

[{"id":"ecd4dcfe.33461","type":"trigger-state","z":"1fa6fb07.b08b25","name":"","server":"6cdd0bc8.b8e434","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.circadian_values","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":310,"y":260,"wires":[["51aef3ce.b37ab4","ca2c2e51.85c0a8"],[]]},{"id":"51aef3ce.b37ab4","type":"function","z":"1fa6fb07.b08b25","name":"WW CW","func":"var colortemp = msg.data.event.new_state.attributes.colortemp;\nvar rgb = msg.data.event.new_state.attributes.rgb_color;\nvar newmsg = \n{\n    payload: {\n        red: Math.round((1000000 / colortemp - 153) * 0.734870317),\n        green: Math.round((500 - (1000000 / colortemp)) * 0.734870317),\n        blue: 0 /*,\n        gain: Math.round(100 * (rgb[0] + rgb[1] + rgb[2]) / 765)*/\n    }\n    \n}\nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":240,"wires":[["6dd6c462.eb32a4"]]},{"id":"2ff51749.a5b8a","type":"trigger-state","z":"1fa6fb07.b08b25","name":"","server":"6cdd0bc8.b8e434","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"switch.circadian_lighting_circadian_lighting","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":250,"y":180,"wires":[["6dd15362.a10fe4","c8eac31d.c5117"],[]]},{"id":"6dd15362.a10fe4","type":"function","z":"1fa6fb07.b08b25","name":"Gain","func":"var brightness = msg.data.event.new_state.attributes.brightness;\nvar newmsg = \n{\n    payload: {\n        gain: Math.round(brightness)\n    }\n    \n}\nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":180,"wires":[["6dd6c462.eb32a4"]]},{"id":"c8eac31d.c5117","type":"ha-entity","z":"1fa6fb07.b08b25","name":"sensor: cl_brightness","server":"6cdd0bc8.b8e434","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"cl_brightness"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"%"}],"state":"data.event.new_state.attributes.brightness","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":600,"y":100,"wires":[[]]},{"id":"ca2c2e51.85c0a8","type":"ha-entity","z":"1fa6fb07.b08b25","name":"sensor: cl_warmth","server":"6cdd0bc8.b8e434","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"cl_warmth"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"K"}],"state":"data.event.new_state.attributes.colortemp","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":590,"y":300,"wires":[[]]},{"id":"6dd6c462.eb32a4","type":"join","z":"1fa6fb07.b08b25","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"0","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":710,"y":200,"wires":[["86ebcdea.c559c8","94776893.663ee"]]},{"id":"6cdd0bc8.b8e434","type":"server","z":"","name":"Home Assistant"}]

The result is obvious :slight_smile:

1 Like

If you use light groups (https://www.home-assistant.io/integrations/light.group/) then the integration will work with it!

Can you share the settings for that Lovelace card?

edit: nevermind

type: vertical-stack
cards:
  - color_thresholds_transition: smooth
    entities:
      - entity: sensor.adaptive_lighting_brightness
        name: Brightness
        show_state: true
      - entity: sensor.adaptive_lighting_color_temp_kelvin
        name: Color temperature (Kelvin)
        show_state: true
        y_axis: secondary
    font_size: 100
    group: false
    name: Brightness vs color temperature
    hours_to_show: 48
    line_width: 6
    points_per_hour: 1
    lower_bound: 60
    upper_bound: 105
    lower_bound_secondary: 0
    upper_bound_secondary: 5500
    show:
      extrema: false
      fill: fade
      labels: false
      name: true
      state: true
    type: 'custom:mini-graph-card'
  - color_thresholds_transition: smooth
    entities:
      - entity: sensor.adaptive_lighting_brightness
        name: Brightness
        show_state: true
      - entity: sensor.adaptive_lighting_sun_position
        name: Sun position
        show_state: true
        y_axis: secondary
    font_size: 100
    group: false
    name: Brightness vs sun position
    hours_to_show: 48
    line_width: 6
    points_per_hour: 2
    lower_bound: 40
    upper_bound: 100
    lower_bound_secondary: -100
    upper_bound_secondary: 100
    show:
      extrema: false
      fill: fade
      labels: false
      name: true
      state: true
    type: 'custom:mini-graph-card'
  - color_thresholds_transition: smooth
    entities:
      - entity: sensor.adaptive_lighting_color_temp_kelvin
        name: Color temperature
        show_state: true
      - entity: sensor.adaptive_lighting_sun_position
        name: Sun position
        show_state: true
        y_axis: secondary
    font_size: 100
    group: false
    hours_to_show: 48
    name: Color temperature vs sun position
    line_width: 6
    points_per_hour: 2
    lower_bound: 0
    upper_bound: 5500
    lower_bound_secondary: -100
    upper_bound_secondary: 100
    show:
      extrema: false
      fill: fade
      labels: false
      name: true
      state: true
    type: 'custom:mini-graph-card'

Here is:

type: 'custom:mini-graph-card'
name: Circadian Light
show:
  icon: false
  labels: false
font_size: 80
font_size_header: 10
hour24: true
hours_to_show: 72
line_width: 2
lower_bound: 1
lower_bound_secondary: ~2000
higher_bound: 100
higher_bound_secondary: ~7000
smoothing: true
entities:
  - entity: sensor.cl_brightness
    name: Brightness
  - entity: sensor.cl_warmth
    name: Warmth
    show_state: true
    y_axis: secondary

However when I was copying this code for you. I figured out that the defualt graph resolution is not enough to represent actual changes. Adding points_per_hour: 60 changes a bit the look (see below). TBH I liked more the view before changes :wink:

obrazek

Btw proper support for Dual ID RGBW controllers would be nice (like fls-pp that exposes a separate entity for W and or RGB) so it’s treated as one device where depending on the current color temp either the W device, the RGB device or both are on and adjusted accordingly.

Most bulbs controlled by Smart Switches in my house are dumb dimmable led bulbs. The only thing to change there is brightness, but that’s all handled. Any switches with smart bulbs attached are bypassed to have constant power with any button presses being handled by Home Assistant.

Before I gave control over to Adaptive/Circadian Lighting I had an automation set to intercept any light turn ons and send the brightness based arbitrarily on the time of day. In those days I remember there being a brief delay between rapidly heading to 100% brightness and the automation dimming the light. But, I was running Home Assistant on a Raspberry Pi back then, and both my code and Home Assistant have been optimized since then. I don’t notice any delay with Adaptive Lighting.

Yeah. I believe in that otherwise you would stop using it :wink:
But potentially it’s possible especially in hands of less skilled home automation owners. This is why I would expect ability to set light attrs while the lights is turned off. Personally I can achieve it by feeding my devices through mqtt (btw mqtt gives a lot more flexibility in that than built-in integrations). I really like what I achieved, because changing circadian related attributes is completely separated process than turning lights on/off. It perfectly matches Single responsibility principle.

I however suppose, that not all smart appliances sport such feature. I know about Shellies because I’m using them. I’ve read that Lifx too. Don’t know about others. And if there are no more, it might be the reason why there is no such service call in HA.

So I am quite happy with it and I think I can retire the circadian solution I built with NodeRed.
BUT: it only works for my RGB bulbs, not for my Philips Hue tunable whites (connected via Zigbee2Mqtt), which work perfectly fine with my custom NodeRed solution, where I periodically send color and brightness to all lamps that are currently on.

any Idea?

not for my Philips Hue tunable whites (connected via Zigbee2Mqtt),

Could you be more specific about what doesn’t work? Does it give an error? Does the light not change? Only brightness, only color?

Ah sorry that’s not obvious of course.
It only changes brightness, not color.

No errors, sending separate commands also does not help, as expected.

works by now. A HA restart fixed it, maybe just an issue with talking to the lamp

Bas, would it be possible to support updating lights while off for those that support it, like the Shelly Duo for example? That would be nice and save me some Node Red flows.

No until HA will provide infrastructure for that. Simply there is no service call other than turn_on which can handle sending light attributes.
The only way is to go around HA, using either mqtt or HTTP API calls.

BTW while this feature is not exclusive to Shelly, it’s very rare. Shelly devices are superior in several cases

1 Like

thanks a lot, then I will do this with Node Red for all bulbs that are off, no big deal.
I hope shelly releases a 800 lumen RGB bulb at some point.

Just found this and hoping to use it for my Zigbee Groups.

Wanted to say that I think it’s possible to set light attributes for some lights, without actually turning them on, by calling light.turn_on with brightness 0.

Might work with the Shelly lights.