So… go easy on me as I’m a complete noob, still trying to get a grip on the idiosyncrasies of templates.
I don’t understand enough about Home Assistant to know how to get the automation to keep running for the duration of time that I want the updating to continue, nor to get it to compute and ‘write’ the update once per minute.
Do I use a ‘repeat’ action with a while ‘loop’ for this?
Perhaps start by describing the actual real world problem you want to solve. There may be a better way to accomplish it using state changes rather than loops. This may avoid an XY Problem.
Thanks Tom. As is often the case with extreme noobness, my question was a bit daft and I figured it out eventually. May not be the best solution, but I’ll describe what I was doing and let me know what you think.
As an exercise for understanding how it all works, I wanted to create a helper assisted timer, where the current date/time is saved as a helper, then a helper defined time is added to that date/time, to define an end time for the timer. Then I wanted a third helper to be updated every minute to reflect the time remaining on the timer. Placing all these in Lovelace, I figured this would be a good little exercise to get on top of some of the basics and see exactly what my tinkering was producing.
So I ended up using a repeat action, with the while defined with a template condition checking the endtime minus the now() time remained larger than 1. I got the sequence to first update the remaining time helper, then popped a delay of 60 seconds after that.
Another way to do it is with some helpers, a template sensor and some state triggered automations. I have this timer that switches on my porch light if I’m expecting a food delivery at night:
I set the time with the slider and turn the switch (input_boolean) on.
This was written quite a while ago and could probably do with a bit of rework to combine the first two automations. But it works and I have a lot of energy monitoring configuration to do…
Thank you for sharing that implementation: I’m learning a lot from it.
Although the Home Assistant docs are expansive, for me, nothing beats seeing a real world implementation where the context of desired outcome is fully understood before diving into the code.