Just in the beginning process of setting up my system and I’ve come to Automation, when i arrived home today the window lights were lit, so it seems i got that right.
I added a second automation to start the interior lights with no delay.
To test it out i turned off all lights manually and restarted the server, expecting all the lights to come on, but no. Dark as a dungeon in here.
Don’t be fooled by the thread time stamp, it was prior to 22:00:00 so the mood lights should’ve come on.
- id: window_lights_on
alias: "Turn on window lights"
trigger:
platform: sun
event: sunset
offset: '-00:45:00'
condition:
condition: time
before: "21:00:00"
action:
service: switch.turn_on
entity_id:
- group.fonster
- id: punkt_lights_on
alias: "Turn on mood light"
trigger:
platform: sun
event: sunset
offset: '00:00:00'
condition:
condition: time
before: "22:00:00"
action:
service: switch.turn_on
entity_id:
- group.punktbelysning
I assume that the sun had set already when you restated HA.
This means that the trigger event ‘sunset’ was never invoked because the sun was already down.
You could run a test that makes use the offset you have already in there - look up when the sunset was for today, add the delta from that time to now to the offset in the trigger (plus another 5ish minutes, maybe), restart your server and see what happens within the next 5ish minutes.
You have to look at it from this point:
A trigger kicks off the action at only one point in time - in your case that is exactly at sunset.
If you reboot the system after sunset there is no trigger, the trigger event has come and gone.
The system will not evaluate what should have happened in the past when the sun set.
For your case - power failure and desired state afterwards - I would recommend an additional automation that’s triggered at the start of homeassistant, checks if it’s after sunset and turns on the lights based on that.
Here’s an example that I use - it has to do with the fact that my cheap etekcity switches do not report their current state, so I inquire if the printer is online when HA starts and set the status of the switch accordingly for my UI:
That’s still not going to trigger if the trigger has already gone when it restarts. You could do a trigger that fires every, say, five minutes and then checks the conditions but that will probably make other problems for you if the conditions aren’t very complex. Like if you want to turn them off manually they will turn on again within five minutes when the trigger fires the next time.
The suggestion for checking conditions when hass starts are probably the way to go for you.
Thanks for the input, I’ve added the following to automations.yaml, seemt to be working fine
I guess that if i get a loss of power between 45 minutes prior to sunset and sunset it wont work. That can be adressed by adding an OR condition to the lights on, if i feel that i need it.
- id: Lights_at_reboot
alias: "Lights on at reboot"
trigger:
platform: homeassistant
event: start
condition:
condition: and
conditions:
- condition: state
entity_id: sun.sun
state: below_horizon
- condition: time
before: "22:00:00"
action:
service: switch.turn_on
entity_id:
- group.fonster
- group.punktbelysning_vrum