Circadian Lighting [Custom Component]

Just got stuck now. I’d like to update my Node-Red automations with the circadian light values.
So I called the attributes whenever I turn on a light as followed:

kelvin: “{{ state_attr(‘sensor.circadian_values’, ‘colortemp’) | int }}”
brightness_pct: “{{ state_attr(‘switch.circadian_lighting_circadian_lightning’, ‘brightness’) | int }}”

NodeRed node:

[{"id":"adbf97df.f01828","type":"api-call-service","z":"69fe71a0.9c25d","name":"Schalte Ganglicht an","server":"4d6df871.899408","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.tradfri_gang_1, light.tradfri_gang_2, light.tradfri_gang_3, light.tradfri_gang_4, light.tradfri_gang_5, light.tradfri_gang_6","data":"{\"kelvin\":\"{{ state_attr('sensor.circadian_values', 'colortemp') | int }}\",\"brightness_pct\":\"{{ state_attr('switch.circadian_lighting_circadian_lighting', 'brightness') | int }}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":260,"y":260,"wires":[[]]},{"id":"4d6df871.899408","type":"server","z":"","name":"Home Assistant"}]

ending up in the following error msg:

Call-service API error. Error Message: expected int for dictionary value @ data[‘kelvin’]

Although the colortemp value of circadian_values sensor is a int vlaue… :frowning:
Also the same error happen with brightness and float expected, when I put kelving to a fixed value (e.g. 5000) for testing purpose.

Anyone an idea?

Is there a way to restore the light setting the light was set on before, after turning off the module?

Create a scene before you toggle the switch

Hi there, this is my first post here. I’m super new to home assistant and only installed it for this integration. I’ve managed to make circadian lighting work and now I have a few noobish questions. So please be patient with me :smiley:

  1. Is it possible to make the app stop adjusting lights when there was a manual adjustment of brightness and/or temperature/color? (So basically I don’t want the app to kick in when my wife consciously changed brightness via a hardware switch). Also I would like to make the app resume as soon as the lights are turned off again (or turned on again…whatever works best).

  2. Does this integration somehow support what some people call “prestaging”? Which would be setting the lights to the desired values when they are still off? However I fear that this would automatically turn on my philips hue lights…

  3. Total stupid question as I’m still not quite sure: Does circadian lighting change values only after a light got turned on? Or will it change values by some sort of automatic rhythm? (So that a light can stay on all day and still change accordingly).

Best regards and please excuse my ignorance!

Hi @janhub,

there’s a newer component, based on circadian lighting, called adaptive lighting which sooner or later will be natively integrated into Home Assistant:

There you can change and customize the behaviour for point 1 & 3 relatively easy.
(It also supports configuration via GUI & yaml at the same time).

Don’t know if your point 2 is possible t.b.h.

Greetings

1 Like

You could potentially do this via some automation logic but it’s in-built to this component.

I think this comes down to your lights ability, not the CL component.

This component will keep updating your light as per your setting for update interval such that a light which is ON will change it’s brightness / colour temp throughout the day

AFAIK it comes down to HA limitations too. If light is driven by HA (which internally uses light service calls) there is no option currently to feed light with light oarams when light is in off state (I think only light.turnon service call accepts light parameters)

You can workaround it if your lights can communicate through other api, like mqtt. then it’s possible to take params from circadian and send them to the bulb/strip circumventing HA.

This is how Ive done it with my Shellies RGBW. It ensures me that everytime I turn on the light using wall switch, it is already set to expected values.

My guess is that OP wants to minimize flickering resulted from frequent changes and turn the lights on with the desired values.

Considering that most light platforms turn on with last known values before turning off while very few can have a preset value at turning on (Philips Hue can use both), I set brightness level to 1 before turning them off.

I know this is an additional step added to turning off sequence however, with lower flickering (as light will turn on initially at brightness 1 then ramp up to the provided RGB and brightness levels) it can also reduce strain on the eyes when turning light on in a dark room.

Even if - extreme case - light was at full red before turning it off then going to full green at the turn on, if the brightness level before off is 1 then this won’t result in huge flickering and would allow the eyes to adjust.

For point one I use automations and an input helper.

1st automation:
If the brightness and/or color is changed via the hardware switch the input helper is switched on and will be switched of after a delay of 45 minutes.

2nd & 3rd automation:
If the input helper is switched on/off, Circadian will be switched on/off.

- alias: Circadian temporär aus
  id: licht1
  trigger:
  - platform: state
    entity_id: light.kueche_decke
    attribute: color_temp
  - platform: state
    entity_id: light.kizi_decke
    attribute: color_temp
  - platform: state
    entity_id: input_boolean.circadian_zeitweise_aus
    to: 'on'
  mode: restart
  condition:
  - condition: state
    entity_id: input_boolean.dimmer_hue_nutzung
    state: "on"
  action:
  - service: switch.turn_off
    entity_id: switch.circadian_lighting_circadian_lighting
  - service: input_boolean.turn_on
    data:
      entity_id: input_boolean.circadian_zeitweise_aus
  - delay:
      minutes: 45
  - service: switch.turn_on
    entity_id: switch.circadian_lighting_circadian_lighting
  - service: input_boolean.turn_off
    data:
      entity_id: input_boolean.circadian_zeitweise_aus

- alias: Circadian Boolean Schalter an
  id: licht2
  trigger:
  - platform: state
    entity_id: input_boolean.circadian_zeitweise_aus
    from: 'off'
    to: 'on'
  action:
  - service: switch.turn_off
    entity_id: switch.circadian_lighting_circadian_lighting
  - service: notify.***
    data_template:
      title: '*Circadian für 45 Minuten ausgeschaltet*'
      message: Die Lichttemperatur wurde manuell geändert oder der entsprechende Schalter
        betätigt. Daher wurde die automatische Lichttemperaturjustierung temporär
        abgeschaltet.

- alias: Circadian Boolean Schalter aus
  id: licht3
  trigger:
  - platform: state
    entity_id: input_boolean.circadian_zeitweise_aus
    from: 'on'
    to: 'off'
  - platform: state
    entity_id: switch.circadian_lighting_circadian_lighting
    from: 'off'
    to: 'on'
  action:
  - service: switch.turn_on
    entity_id: switch.circadian_lighting_circadian_lighting
  - service: notify.***
    data_template:
      title: '*Circadian angeschaltet*'
      message: Die Lichttemperatur wird (wieder) automatisch nach der Tageszeit justiert.

Is there any way to have different settings for different lights? For example, I don’t want to have the brightness for the lights in the kitchen adjusted but for the other lights in my house.

Is it, therefore, possible to have more than one circadian switch configured in the configuration.yaml?

Yes, you can define CL Switches per light or lightgroup

1 Like

Hi all,

first of all a huge Thank you to @claytonjn for creating this component. The whole concept of circadian lighting is the only reason I wanted to install smart lighting all over my flat in the first place. I’m glad I finally found the time to set up Home Assistant and Circadian Lighting to actually use all of my smart bulbs as intended.
And in terms of color temperature adjusment the custom component works perfect!
The only issue I’m experiencing (and this is half of the whole goodness of cl) is the fact that the brightness adjustment doesn’t work at all. I don’t have a clue as to why this is, which is why I’m writing this reply. I hope someone here can solve my problem. Many thanks in advance for any ideas you guys might have. Here is my configuration.yaml:

circadian_lighting:
  max_colortemp: 4000 
  min_colortemp: 2200

switch:
  - platform: circadian_lighting
    lights_ct:
      - light.bad_deckenlampe
      - light.spiegel
      - light.esstisch_rechts
      - light.esstisch_links
      - light.flur_deckenlampe
      - light.herd_mitte_2
      - light.herd_links
      - light.spule_links
      - light.herd_rechts
      - light.spule_rechts
      - light.herd_mitte_1
      - light.spule_mitte
      - light.kuche_deckenlampe
      - light.wohnzimmer_bogenlampe
      - light.kamin_rechts_oben
      - light.kamin_rechts_unten
      - light.gummibaum
      - light.kamin_links_unten
      - light.kamin_links_oben
    min_brightness: 1
    max_brightness: 100
    disable_brightness_adjust: False

Greetings

Brightness will stay at 100% until after sunset, are you sure this isn’t the behavior you’re seeing?

Hey clay,

Thanks for your quick reply!
It’s pitch black outside where I’m at and all my lights are still at 100%. sun.sun detects that the sun is being below horizon since two hours.
All my lights are Tradri by IKEA if that’s of any relevance…

Take a look at the debug logs, that should help indicate what’s going on.

Using the ‘Adaptive Lighting’ component solved my issue… If you want to I could turn on debug logging a few hours before tomorrows dusk and provide the data anyways.

This exactly. I still don’t like the effect that after turning my lights on it takes a couple of seconds for them to adjust - especially when lights haven’t been turned on for a while.

Do philips hue lights really support pre-staging? Because I think the lights would just turn on if you were to change their states when they are still off.

I like the idea of your approach with setting brightness to 1%…however wouldn’t that cause a visible delay to ones perception of lights turning on? With adaptive lighting (new integration) it mostly takes around 2-3 seconds for my lights to adjust…so turning the lights on would have them stay at a brightness level of 1% for those 2-3 seconds before they visibly “turn on” (that is adjust according to adaptive lights parameters)

Hope you get my point.

Best regards

Yes, I’m seeing that in the Adaptive-Lighting component: as the switches that determine the color and brightness are always on, the lights are turned on with the correct preset.
It is required then to set the initial transition value to 0.

Setting the initial transition value to 0 in my case just removes the transition. So the when turned on, the lights will remain with the old values for a couple of seconds and then adjust to the new settings without transition. This is even “more exhausting” for the eyes…in my opinion.

Unfortunately not, when using api to change light properties for a light that is off (Get Started - Philips Hue Developer Program) it throws an error that the light is off and properties cannot be changed.

Summary

[details="Summary"]
[
	{
		"error": {
			"type": 201,
			"address": "/lights/7/state/hue",
			"description": "parameter, hue, is not modifiable. Device is set to off."
		}
	},
	{
		"error": {
			"type": 201,
			"address": "/lights/7/state/sat",
			"description": "parameter, sat, is not modifiable. Device is set to off."
		}
	},
	{
		"error": {
			"type": 201,
			"address": "/lights/7/state/bri",
			"description": "parameter, bri, is not modifiable. Device is set to off."
		}
	},
	{
		"success": {
			"/lights/7/state/on": false
		}
	}
]
[/details]