How can I trigger an automation so that it will also trigger after a restart or if it finished during the restart (new function in 2022.4)?
There is a checkbox in the settings of a timer helper to save the state during reboots. If you turn that on, the rest should take care of itself.
Looks like I have to delete my old timers from configuration.yaml and make them again in the UI. The old ones do not have this checkbox…
In yaml, just add the restore field. You don’t need to recreate them in the ui.
You can also decide how you actually want to act on the restored timer’s finished
event.
For example, assume the timer’s duration is 5 minutes. However, due to a power failure, Home Assistant stopped before the timer finished. One hour later, Home Assistant starts, the 5-minute timer is restored, and its finished
event is generated. It’s now about an hour later than when the timer should have finished. The action it’s supposed to perform may no longer be relevant and may even be undesirable.
Given this situation, you need to know if the timer finished normally (precisely after 5 minutes) or finished only after being restored after a long passage of time. To make this determination, you can use finished_at
.
The
finished_at
property in the event data will provide you with the time that the timer was actually supposed to fire which you can use in automation conditions to decide whether or not to act on it.
So at the moment the finished
event occurs, if the value of finished_at
is not recent it means there has been a longer passage of time than the timer’s duration. Depending on the length of that time, you can now determine what to do next (proceed as normal, do something different, or nothing at all).