The two scenarios I have come across include motion light timers and “wait for trigger” functions. If the automation is running but waiting on a timer or trigger and HA restarts, the automation does not pick up where it left off.
I think what this comes down to is, does the automation maintain some kind of internal state for a prolonged period? For example, does the automation wait for something during the Action section? This could be wiating for a time delay for turning something off after the same automation has turned it on.
If the automation has no internal state (it doesn’t need to remember anything that isn’t available as the state of some entity) or it runs for a very short time (and would be unlucky to be interrupted by a restart) then there is little need to worry.
If the automation needs to store information that isn’t the state of some entity then it may be safest to create a Helper entity to store this information.
To avoid having the automation run for a long time it is probably best to have anything that causes the automation to run, or change it’s internal state, as a trigger in the Triggers section, rather than using Wait for Trigger actions. Then, the combination of Choose actions and any internal state stored in helper entities could be used to decide what to do.
In simple terms, this turns on the light inside a cupboard when the cupboard door is opened. It turns off the light when the cupboard door is closed. In addition, it turns off the light if the door is open for more than 10 minutes. It uses a Timer Helper (with restore enabled) to ensure the ‘state’ of the automation is preserved across restarts.
Thank you @123 and @templeton_nash! I’ll chew, swallow, and digest this and return with any questions. YAML is foreign to me, but I am able to [mostly] look at a script and replicate it using UI. Where UI is not supported, I am able to implement that section using YAML (thank you, @123!).
For the most part, I would like to understand why something works the way it does. For example, the idea of a service call rather than an event trigger, where the service call can properly handle a restart.
It’s unclear what you’re asking because a service call and an event trigger are completely different animals.
A service call is an action, not a trigger.
An event trigger is a trigger, not an action.
The linked post (above) demonstrates, in stages, how to make a fairly straightforward application (turn on a light at sunset and turn it off at sunrise) from something ultra basic to something robust that always sets the light to the correct state even if it missed triggering at sunrise/sunset due to a restart.
Thanks for the explaination. I finally had some time to look at the example that I listed in the first post of this thread (provided by you), and I see the difference now. The service call is responding to a condition so it does not matter if HA restarted, as long as the condition is met, the service call is placed and the action is executed.
On the other hand, a “wait for trigger” function occurs mid-automation. After a restart, the automation does not return to that stage, which causes the intended action to fail.
Many have said that HA’s utility is only limited by one’s imagination. To me, automation scripts are only limited by one’s creativity and logic. Some automations’ construction and efficiency are very impressive indeed.
Thanks again, @123. I will dig in to the other examples you provided.