Hola, I want to check if the automation has run in the past 4 hours and if so, dont actually run it.
With this Im checking battery voltage and if its lower than a given treshold, do XYZ.
My problem is: How can I check if the automation has run in the last 4 hours?
There doesn't seem to be a thing, maybe I need some helper entity?
#Check if the automation has run in the past 4 hours
1 messages ยท Page 1 of 1 (latest)
you could at the end of the automation have it turn itself off with automation.turn_off then have a 2nd automation that triggers when the main automation's entity has been off for 4 hours and switch it back on with automation.turn_on
or if the automation itself is set to "single" mode (default)
which means another instance cant be triggered whilst 1 is running. then you could just add a 4 hour delay at the end of it. so it doesn't actually finish for 4 hours
the disable/enable solution would be better as its easier to manually overide if/when needed
that sounds good, I will look into that later.
Hope I can get it to work then
thanks for the advice! ๐๐ฝ
no worries, good luck with it
it makes sense in the end, I have another automation that checks for battery high treshold with that I could turn the first one on again
yeah, automations turning themselves and other automations on/off can be a powerful trick
Untested but I thought something like this was going to work?
- condition: template
value_template: >
{{ state_attr('automation.some_automation', 'last_triggered') == none or
(now() - state_attr('automation.some_automation', 'last_triggered')).total_seconds() > 4 * 3600 }}```
will check it later, thanks!
Implemented, are you interested in updates? Ie. if it worked?
Definitely
i don't mind either way. but I hope it works as intended whichever method you go for ๐
we'll see ... in 4 hours or so when the battery is charged and passes the treshold
so far my hacky solution for the shellly uni plus (see other thread under energy) seems to work
this is a more generic approach which works for every automation, regardless of enitity_id
condition:
- condition: template
value_template: >
{{ now() - this.attributes.last_triggered | default(as_datetime(0), true) > timedelta(hours=4) }}
definitely "stealing" this, thank you