What this does
It gives you cool lights during the day that get gradually warmer around sunset and overnight. The changes are so slow you are unlikely to notice them whilst they are happening. This may even help your circadian rhythm and sleep!
This blueprint updates the color temperature of your lights to match the outside color temperature calculated from the elevation of the sun. See the discussion here on how this calculation came about.
To ensure lights stay in sync it updates lights when they turn on, whenever the sun elevation changes and every 5 minutes.
Requirements
- A working
sun.sun
entity, read the docs. This comes auto-configured on most Home Assistant installations so it is probably there unless you’ve disabled it. - At least one bulb that reports
color_temp
amongst itsattributes.supported_color_modes
Notes
- On the bulbs I tested it on (IKEA Tradfri via ZHA) telling the bulb to change color temperature as it turns on would stop it coming on at full brightness, as such a separate action to restore the brightness is called after setting the color temperature. I have exposed this for editing in-case it interferes with any other of your automations, e.g I make my brightness come on low overnight and 100% in the morning.
- You have to select every light you want to target - it is monotonous but you will only have to do it once.
-
Be careful about including light groups. If you do, when you turn on 1 light in the group, every light in the group will be turned on because the automation has to call
light.turn_on
at the group to change its color temperature - for light fixtures with multiple bulbs this may be a feature, for multiple lights + lamps in a room it will be a bug. - Max and min color temp: There is probably no harm in taking the slider to the extremes. I assume most bulbs will just change to their maximum/minimum if they get a request to change to a color temp that is out of range.
- You can see which bulbs support color temp by going to
developer tools > states > type "color_temp" into filter attributes
. This will probably also show you the max and minimum supported color temp. - If you live at extremes of latitude (e.g Iceland) where the sun elevation never gets very high you may find the the bulbs never get ‘cool’ if this is annoying let me know and maybe we can find a way to normalise the values.
blueprint:
name: Match Outside Colour Temperature
description: When a light turns on or the sun elevation changes match the outside colour temperature. It will apply to any bulb that supports color temperature. It triggers whenever a bulb turns on, on sun elevation changes and every 5 minutes.
domain: automation
input:
target_lights:
name: Lights
description: The lights to be controlled
selector:
entity:
domain: light
multiple: true
min_color_temp:
name: Minimum Color Temperature
description: The coolest color your bulbs will be set to
default: 250
selector:
color_temp:
min_mireds: 153
max_mireds: 500
max_color_temp:
name: Maximum Color Temperature
description: The warmest color your bulbs will be set to
default: 454
selector:
color_temp:
min_mireds: 153
max_mireds: 500
brightness_action:
name: Brightness
description: When a device turns on its color temperature will be set, this may interfere with the brightness, this action will run half a second later to set the light's brightness.
selector:
action:
default:
- service: light.turn_on
data:
brightness: >-
{{max(trigger.to_state.attributes.brightness,2)}}
target:
entity_id: >-
{{trigger.entity_id}}
alias: Default - Set light to its original brightness, don't use brightness 1 as it causes issues with some bulbs
variables:
target_lights: !input target_lights
target_on_lights: >-
{{states.light | selectattr('state','eq','on') |
selectattr('attributes.supported_color_modes','match',".*color_temp.*")
| map(attribute='entity_id') | select("in",target_lights) | list }}
min_color_temp: !input min_color_temp
max_color_temp: !input max_color_temp
color_temp: >-
{{ [([((1000000/(4791.67 - 3290.66/(1 + 0.222 *
([([0,state_attr('sun.sun',
'elevation')]|max),90]|min**0.81))))|int),min_color_temp]|max),max_color_temp]|min}}
trigger:
- platform: state
entity_id: !input target_lights
to: "on"
id: single_light_on
- platform: state
entity_id:
- sun.sun
attribute: elevation
id: elevation_change
- platform: time_pattern
minutes: "5"
id: every_5_min
condition:
- condition: template
value_template: >-
{{ (states.light | selectattr('state','eq','on') |
map(attribute='entity_id') | list)!= [] }}
action:
- choose:
- conditions:
- condition: trigger
id: single_light_on
sequence:
- service: light.turn_on
data:
color_temp: "{{color_temp}}"
transition: 0
target:
entity_id: "{{trigger.entity_id}}"
- delay:
milliseconds: 500
- choose:
default: !input brightness_action
- conditions:
- condition: or
conditions:
- condition: trigger
id: every_5_min
- condition: trigger
id: elevation_change
sequence:
- service: light.turn_on
data:
color_temp: "{{color_temp}}"
transition: 5
target:
entity_id: "{{target_on_lights}}"
mode: parallel
Example graph of how the color temperature varies over the day.
Change log
2022-10-08 Version 1.1, ensure transition time is 0 for single light turn on
2022-11-23 Version 2.0. Uses Kelvin, link to the old mired version 1.1 is preserved
Help wanted /To Do
- Make sure it supports other bulbs - needs your testing
- Will use the color temperature selector when fixed and enabled for Kelvin. Color Temperature Selector not working · Issue #14440 · home-assistant/frontend · GitHub
- How to add an optional and user-configurable condition?
- User experience in extremes of latitude