#How to ensure that an automation runs no more than once per hour?
1 messages · Page 1 of 1 (latest)
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
yeah, I was about to say this. its definitely the "lazy" way to do it but it works most of the time.
ok will try it. thanks
https://www.home-assistant.io/docs/automation/modes/#example-throttled-automation this approach is also described in the docs
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.
this shows yaml. is it only possible to create these using the automation builder? or only through the yaml?
you can do it in the editor
automation mode is in the overflow menu in the top right but its set to single by default anyway
ok thanks
@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
i am surprised its not maintained as the data is stored somewhere because its available in the UI. i have automations which has last trigger months ago and some over a year at this point i think (i should clean some stuff up...)
last_triggered is an attribute of an automation entity, and like all other attributes of automation entities they are restored after a restart.
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?