If Home Assistant is off during a power outage at either 23:00 or 17:30, it wont be able to trigger at the specified times. When starts later, it will have missed the trigger time and so will not set the switch to the correct state.
The automation needs to be redesigned to handle a third trigger that occurs when Home Assistant starts. Add the following trigger to your automation:
- platform: homeassistant
event: start
Change the template to this:
service: "switch.turn_{{ 'on' if 17 <= now().hour < 23 else 'off' }}"
That ensures the switch is set to the correct state whenever Home Assistant starts.
NOTE:
The template I have suggested will work accurately for 99% of all cases. However, if Home Assistant starts between 17:00 and 17:30, the template will turn on the switch. That’s because the template only concerns itself with checking the current hour, not minutes. That’s not a problem when the automation normally triggers at 17:30. It will only occur if Home Assistant restarts during that half-hour “window” between 17:00 and 17:30.
If that’s unacceptable to you, I can show you how to enhance the template so that it also considers minutes. However, in my opinion, the extra complexity isn’t worth it and the suggested template is neat, simple, and will handle 99% of restarts accurately.
If you want to learn more about this technique, you may wish to read the following post: