Just a little bit more than 3 years ago, we began with HA. One of the first things I did to win over “Spouse Support” was set out to create some of the first conveniences specifically for my wife.
Since she’s a Sun & Sunset Worshipper, but we live in Northern Europe where the summer days are super long and the winter days are super short, and the time sunset occurs can change by 15 minutes in one week during Spring or Fall, I created a Sunset Simulation & Alarm function using Home Assistant.
This has become one of her single biggest loves of Home Assistant. And now that she’s working from home along with the rest of us during these Corona Times, and we just built out her dedicated new Home Office in our loft, I’ve also instituted this Sunset Simulation & Alarm function in her office (it originally only ran downstairs, in an open-plan Living Room / Dining Room / Kitchen.)
I’ve had others ask me how I did this, and thought I’d share my scripts and automations for this.
Pre-requisites: Any room with multiple RGB(W) lights. More is better, but not required. Downstairs, we have over 32 Hue bulbs, Living Color Lamps and ESP-based Bulbs, but in my wife’s office, there’s only 4.
It’s not required to have your lights organised East-to-West, but that’s how we did it, as it lends to the effect.
First, we have the automation, which is pretty simple and triggers everything else. You can see in ours, we trigger it across 3 floors, and call a script for each floor. This is done, because it’s possible to cancel the program simply by turning off the lights, but perhaps we want to leave it running on another floor.
- alias: "Sunset: Two Hour Warning"
initial_state: true
trigger:
platform: sun
event: sunset
offset: '-02:00:00'
action:
- service: script.turn_on
entity_id: script.sunset_warning_downstairs
- service: script.turn_on
entity_id: script.sunset_warning_upstairs
- service: script.turn_on
entity_id: script.sunset_warning_loft
Then we have the scripts. Our Kitchen is the east-most side of the house, and our living room is on the westmost side of the house. The Dining room is in-between the two. I roll the colors across the room from East to West.
Each script, and the scenes they call, are customised for each floor and the lights on that floor, but since they are all basically the same, I’ll just use the downstairs script as the example:
sunset_warning_downstairs:
sequence:
# This is to conduct a TTS voice announcement, and is optional if you don't use TTS.
- service: mqtt.publish
data_template:
topic: "homeassistant/say/all"
payload_template: "Two hours until sunset."
- delay: "00:00:02"
# This brings up the lights on bright white slowly to match the outside daylight conditions
- service: scene.turn_on
entity_id: scene.sunset_white_downstairs
- delay: '00:15:00'
# This conditional statement is to ensure the lights haven't been manually turned off, and if not, continue running the script.
# this repeats at various stages through the entire script.
- condition: state
entity_id: light.dining_room_spot_1
state: 'on'
- service: scene.turn_on
entity_id: scene.sunset_yellow_downstairs
- delay: '00:30:00'
- condition: state
entity_id: light.dining_room_spot_1
state: 'on'
- service: scene.turn_on
entity_id: scene.sunset_orange_downstairs
- delay: '00:45:00'
# This is final TTS warning to my wife - she's got 30 minutes if she wants to go on the terrace to make sunset photographs.
- service: mqtt.publish
data_template:
topic: "homeassistant/say/all"
payload_template: "30 minutes until sunset."
- delay: "00:00:02"
- condition: state
entity_id: light.dining_room_spot_1
state: 'on'
- service: scene.turn_on
entity_id: scene.sunset_red_downstairs
- delay: '00:30:00'
- condition: state
entity_id: light.dining_room_spot_1
state: 'on'
- service: scene.turn_on
entity_id: scene.sunset_violet_downstairs
- delay: '00:15:00'
- condition: state
entity_id: light.dining_room_spot_1
state: 'on'
- service: scene.turn_on
entity_id: scene.sunset_blue_downstairs
- delay: '00:15:00'
- condition: state
entity_id: light.dining_room_spot_1
state: 'on'
- service: scene.turn_on
entity_id: scene.sunset_dim_downstairs
- delay: '00:05:00'
- condition: state
entity_id: light.kitchen_spot_oven
state: 'on'
- service: light.turn_off
entity_id: group.kitchen_all
- delay: '00:05:00'
- condition: state
entity_id: light.dining_room_spot_1
state: 'on'
- service: light.turn_off
entity_id: group.diningroom
- delay: '00:05:00'
# Notice my light I use to see if the lights were manually shutdown is different now, because the lights on the east side of the house are already switched off, so I check a different light on the west side of the house.
- condition: state
entity_id: light.tasmota1_light
state: 'on'
- service: light.turn_off
entity_id: group.livingroom
And finally, the scenes.yaml content for the sunset simulation & alarm. Originally I used xy_color because originally our room was only Living Color & Hue lights…since then, we’ve added RGBW ESP based bulbs and it seems HA does the translation to RGB for those lamps automatically, so I didn’t need to switch to using RGB values, but think it should work if you prefer to use that.
# Good Hue xy_color translator: http://colorizer.org
# Use the HSV/HSB profile with Saturation = X and Hue = Y
# 2 hours before
- name: sunset_white_downstairs
entities:
group.lights_downstairs:
state: on
transition: 900
brightness: 255
xy_color: [0.5425, 0.4196]
## 1:45 before
- name: sunset_yellow_downstairs
entities:
group.lights_downstairs:
state: on
transition: 1800
# brightness: 255
xy_color: [0.5425, 0.4196]
## 1:15 before
- name: sunset_orange_downstairs
entities:
group.lights_downstairs:
state: on
transition: 2700
# brightness: 255
xy_color: [0.4524, 0.4355]
## 0:30 before
- name: sunset_red_downstairs
entities:
group.livingroom:
state: on
transition: 1800
# brightness: 255
xy_color: [0.5425, 0.4196]
group.diningroom:
state: on
transition: 1800
# brightness: 255
xy_color: [0.3972, 0.4564]
group.kitchen_all:
state: on
transition: 1800
# brightness: 255
xy_color: [0.6679, 0.3181]
## 0:15 before
- name: sunset_violet_downstairs
entities:
group.kitchen_all:
state: on
transition: 900
# brightness: 255
xy_color: [0.4149, 0.1776]
group.diningroom:
state: on
transition: 900
# brightness: 255
xy_color: [0.6679, 0.3181]
group.front_windows:
state: on
transition: 900
# brightness: 255
xy_color: [0.5425, 0.4196]
## Zero Hour
- name: sunset_blue_downstairs
entities:
group.kitchen_all:
state: on
transition: 900
# brightness: 255
xy_color: [0.1691, 0.0441]
group.diningroom:
state: on
transition: 900
# brightness: 255
xy_color: [0.1691, 0.0441]
group.livingroom:
state: on
transition: 900
# brightness: 255
xy_color: [0.4149, 0.1776]
## 0:15 After
- name: sunset_dim_downstairs
entities:
group.lights_downstairs:
state: on
transition: 1800
brightness: 0
xy_color: [0.1691, 0.0441]
That’s pretty much it. You can play with the transition times in the scene section & the delays in the script if you want to extend your day even further (this is something my wife asked just yesterday if I could do, as the days get shorter approaching 4:30pm sunset in the middle of December).
Also, if you have other scripts / automations / scenes that run, you might want to add some conditions to not run when the sunset program is running, just to save from conflicts and funny behaviour.
Further ideas on offer: I see no reason why one couldn’t use some light spectrum sensors outside to feed values to this solution inside, so one gets even more dynamic and accurate rendition of actual sunset skylight conditions. For instances, if it’s a rainy day, you get rainy cloudy day sunset colors.
One could also run this backwards to create a sunrise alarm, in say a bedroom, to wake up by, including a seasonal offset (i.e.- here in Northern Europe - sunrise in middle of summer begins around 4:30am, thus the seasonal or monthly offset variation, or just static wake up times is better trigger.)
One could also not use groups, but call each individual light with even greater variance of RGB / brightness values each, giving even more dynamic and stunning effects.
If you end up using this, just let me know how it goes for you, and if you like it.