Hey all,
I have this automation that turns on my front door light and landscape lights at sunset, then off at sunrise. however, periodically, they won’t be turned off at sunrise. I can’t seem to figure out what causes it to fail as it only happens every once in a while (once every 10 days or so). Here’s my config:
alias: Lights on at sunset
description: ""
trigger:
- platform: sun
event: sunset
offset: 0
condition: []
action:
- service: light.turn_on
target:
entity_id:
- light.tp_link_under_stair_outlet_landscape_lights
- light.front_door_light
- light.front_yard_outlet_front_yard_outlet_top
data: {}
- alias: Wait for 22:00
wait_for_trigger:
- platform: time
at: "22:00:00"
- alias: Turn off Peace Sign Box
service: light.turn_off
data: {}
target:
entity_id: light.front_yard_outlet_front_yard_outlet_top
- wait_for_trigger:
- platform: time
at: sensor.sun_next_rising
alias: Wait for Sunrise
- service: light.turn_off
target:
entity_id:
- light.tp_link_under_stair_outlet_landscape_lights
- light.front_door_light
data: {}
alias: Devices to turn off at Sunrise
mode: single
It’s inadvisable to create an automation that lingers in its action for any extended period of time.
Why not? Because whenever Home Assistant is restarted it terminates any automations that are “in progress”.
Your automation remains “in progress” from sunset until sunrise. Throughout those many hours, it is vulnerable to being terminated by a restart.
Whether or not a restart is the actual cause of the automation’s periodic failures, it’s simply not a good practice to remain “in progress” for so long.
The following automation triggers at sunrise, sunset, and 22:00. When it triggers, depending on the value of the variable command it will either turn on or off the lights listed in the lights variable.
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.