To water plants i want to start watering manually. I do this by starting an automation using a button on the dashboard.
The watering should end after 1 hour. So i’m looking how i could make HA to fire a trigger at now()+1hour.
what if have tried does not work: It never fires.
I use choose: The default path starts the pump. Than HA should fire at 8:33 (fix time to test the automation). Later it should be dynamic now()+1hour. When fired the choose path for trigger-id “stop-it” will stop the pump.
That is the idea. Two problems: Trigger not fired and i have not found the right way to generate the “HH:MM:SS” sequence.
Hi Tom.
When starting an automation manually (run automation), the trigger section is skipped. Ergo nothing happens. Wouldn’t in your solution the trigger fire after the state is ‘on’ for one hour?
Tom, now i understand. I’m using now your solution. Before i had one automation that started the pump and after an hour stopped it again. But this means having a wait time of one hour: the automation stays active.
I Learned that automations get cancelled (without a warning) whenever any other automation is edit and saved. Therefore i was looking for an alternative. The risk that the pump runs forever i cannot accept.
Ok, if this time is critical there is still the possibility that the pump will run longer than an hour. Say you start the pump then 30 minutes later you restart home assistant or reload automations. This will reset the for: time on all automations. The off automation will run 1 hour from the restart/reload (1 hour and 30 minutes total).
There is a way around this.
Start a 1 hour timer in your automation that turns the pump on.
Trigger the pump off automation when the timer expires.
Timers won’t be affected by automations being reloaded and can be restored after a restart using this method by 123:
There’s another technique, that I have been employing in my own automations, where you use a Time Trigger based on an input_datetime (I learned it from finity). It requires a bit less overhead than a timer (and doesn’t require the use of a timer restoration system). It’s not as feature-complete as a timer but more than adequate for creating a simple delay (that can survive a restart).
In a nutshell:
When the pump is turned on, the input_datetime is set to one hour in the future. The Time Trigger triggers at that time and turns off the pump.
The Time Trigger is unaffected by a restart (unless the restart occurs exactly at the time the Time Trigger should trigger or Home Assistant is offline right through the scheduled time).
Instead of having the trigger at an exact time, it is more safe to check if the target time is passed. This will work even though the system is down at the target time. and the action will be triggered as soon as the system is up and running again.
FWIW, this can also be done with an additional trigger that detects a restart event along with a condition to check if the current time is past the scheduled time and the pump is on. Easily achieved within the automation without the need of a Template Binary Sensor (just an input_datetime).
Right thanks, but in prefer the format 1*60*60 so it is more clear(easy) if you want to adjust to for example 7 hours then it becomes 7*60*60 or to 30 minutes then it is 30*60 etc.
Hi Tom, can you point me to the documentation for the “Template language”? Syntax, functions and functions.
The second example has a few misplaced and nested apostrophes.
To the third example: In the future (when the time trigger has passed) the comparison results always in TRUE. Will it therefore be executed constantly? Resulting in a loop switching the power off?
For the moment i changed my automations so that the time helper “one-hr-later” is set to now+1hr. This helper is used to trigger the stop automation. I tested and found that the set time survives a server restart.