Add cooldown to Automation

Hi,

add a cooldown for automations,

eg. cooldown: 15 minutes
Means if the automation was trigger within the last 15 minutes, do not trigger it again.

and
a once per day cooldown would be awesome too!

You can accomplish this already. Add a service call to turn the automation itself off, then create another automation that turns the first automation back on if it’s been off for a certain period of time.

Add to first automation (we’ll assume it’s called automation1):

- service: automation.turn_off
  entity_id: automation.automation1

Create a second automation with the following:

trigger:
  platform: state
  entity_id: automation.automation1
  to: 'off'
  for: '00:15:00'
action:
  service: automation.turn_on
  entity_id: automation.automation1

That will turn the first automation back on if it’s been off for 15 minutes.

Once per day would look like this:

trigger:
  platform: time
  at: '00:00:00'
action:
  service: automation.turn_on
  entity_id: automation.automation1

Thanks for the info, i already know that there are multible ways to do this.
All are, for the fact that this is a basic and needed task for automations way to complicated.

For your way:

  • too much code
  • another entity added (automation)
  • automation cant be disabled manually
4 Likes

What do you mean by this? You could add a condition to only call the automation.turn_off service if the cooldown automation is on. But I suppose that adds to the first issue you listed.

Could you please tell me some usecases for this?

1 Like

Hello from 4 years in the future. My specific use case is to prevent the occasional issue where an automation will run about 15 seconds later after running for the first time. I have an automation set to run when myself or my wife leave the house, and then an automation to run when we get home. If we both leave at the same time, every once in a while there is some odd race condition where the “leaving home” automation will run, then the “arriving home” automation will run 15 seconds later or so, even though we both are now gone. I imagine this is because of how I track home occupation, etc. So having a “cooldown” on this automation prevents that from happening. Just dropping this here for posterity since I came across it in my search for a solution.

Given how easy is to add a template condition with the following code:

{{ (as_timestamp(now()) - as_timestamp(this.attributes.last_triggered))|int(0) > 600 }}

(600 seconds = 10 minutes) I still do not understand why they don’t add a “cooldown” feature to the dropdown menu in the automation conditions that does the same thing.

1 Like

If you’re interested, you can simplify the template condition to this:

{{ now() - this.attributes.last_triggered > timedelta(minutes=10) }}

However, both of our examples will fail for a new automation (an automation that has never been triggered yet) because the value of its last_triggered property is none.

This version mitigates that initial situation:

{{ now() - this.attributes.last_triggered | default(as_datetime(0), true) > timedelta(minutes=10) }}

The majority of Home Assistant’s new features are added by volunteers. So the answer to your question is that, for the past 4 years, nobody has been sufficiently interested in this feature to put in all the work needed to create it.

FWIW, the majority of Feature Requests remain unfulfilled; there are more users submitting ideas than volunteers available/interested to implement them.

2 Likes

I’m interested, thank you very much!

Of course, that’s normal. But maybe these “basic” features also help newcomers to face with Home Assistant (who probably doesn’t search through the community posts at all :smiley:).

1 Like

The Automation Editor is designed for novices. In other words, it doesn’t expose all of Home Assistant’s scripting functionality and limits itself to basic, commonly-used features (to avoid overwhelming novices).

Advanced features and concepts are implemented in YAML and/or Jinja. That’s yet another reason why this FR is unimplemented for 4+ years.

For anyone else landing here after searching for “HomeAssistant automation cooldown” …
I found that last_triggered doesn’t work, because when it evaluates that condition, the attribute has already been updated to now(). So it never evaluates to true and the automation won’t run.

Instead, I ended up adding a timer as described in another post – add a Delay as the last action, and make sure the mode of the automation is set to “single”

Thanks. I was just recently trying to do something similar and I couldn’t figure out why this solution didn’t work. But… Are you sure? It really doesn’t make sense to me that the attribute would be updated before conditions are evaluated. It means it is updated even if the automation wasn’t run, because the conditions were not met. As far as I can see, this is not true.

Yeah just double checked, I have an automation showing the last trace at later time than what is the last triggered attribute. But in that later time the automation didn’t run, because condition was not met.

Ah, you’re right! It does work, using last_triggered.

Turns out I had another bug preventing my actions from running. But when I looked at the traces, I was looking at the most recent which said “Stopped because a condition failed” … and that was really just the condition doing it’s job, because it had also just fired (and failed differently) a few seconds before.

So thanks for making me double check, @Fanful :smiley:

1 Like

So perhaps some of you can coach me a little? I am one of those novice users who’s getting pretty good at the GUI, but still a little lost figuring out how to do things with YAML without some explicit instructions. I can do the cool off timer, that’s easy, and I can see where I can list a condition where only if this same automation was last triggered, but no idea how to specify the condition within. I don’t necessarily want to cool off the automation every time either. So asking for some help on a condition like, “If this automation has been triggered more than 3 times in 5 minutes” or something similar?