#How to ensure that an automation runs no more than once per hour?

1 messages · Page 1 of 1 (latest)

vagrant sparrow
#

I have an automation that runs a pump for 20 seconds depending on some conditions. This works ok, except that I want this to happen at most once per hour. How can I accomplish the 'once per <timeperiod>' aspect? Thanks

lapis cave
#

The easiest way to achieve this is to add a delay of 1h to the end of your actions block. Make sure to keep the mode as "single". However it depends on how critical it is to only trigger once per hour, because this approach wouldn't ensure that it only runs once per hour when home assistant restarts

peak hornet
vagrant sparrow
#

ok will try it. thanks

lapis cave
peak hornet
#

you can also have an automation disable itself as the last thing it does, then have a 2nd automation turn it back on when its been disabled for an hour.
I have some stuff with automations turning each other on and off for some stuff.

vagrant sparrow
peak hornet
#

automation mode is in the overflow menu in the top right but its set to single by default anyway

vagrant sparrow
#

ok thanks

last cloak
#

@peak hornet do you know if the last_triggered automation attribute is preserved after home assistant reset?

#

because if it is, then we could have the a condition now() - this.attributes.last_triggered >= 3600 seconds...

#

if not, then I think the best way is to introduce the datetime helper that is updated in the automation on each run and compared in the conditions part

#

ok, found it, last_triggered is a ram-based state, not preserved during reset. so datetime helper should be the best solution

peak hornet
true shoal
last cloak
#

Makes sense to me that the argument is preserved, but I didn't find how and where. Do we agree that then the correct solution is to add the condition, like so:

{{ now() - this.attributes.last_triggered >= timedelta(hours=1) }}

to avoid using delays that are not preserved between resets?