#Check if the automation has run in the past 4 hours

1 messages ยท Page 1 of 1 (latest)

modern bronze
#

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?

uncut plaza
#

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

modern bronze
#

that sounds good, I will look into that later.
Hope I can get it to work then
thanks for the advice! ๐Ÿ‘๐Ÿฝ

uncut plaza
#

no worries, good luck with it

modern bronze
#

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

uncut plaza
#

yeah, automations turning themselves and other automations on/off can be a powerful trick

ionic junco
#

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 }}```
modern bronze
#

will check it later, thanks!

#

Implemented, are you interested in updates? Ie. if it worked?

ionic junco
#

Definitely

uncut plaza
#

i don't mind either way. but I hope it works as intended whichever method you go for ๐Ÿ™‚

modern bronze
#

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

remote lichen
#
condition:
  - condition: template
    value_template: >
      {{ now() - this.attributes.last_triggered | default(as_datetime(0), true) > timedelta(hours=4) }}
ionic junco
#

definitely "stealing" this, thank you