How to allow an automation to run itself a max of once every XX seconds after being triggered?

How can I set an automation to not be able to run itself again within X seconds of itself last being run?

For further clarity, I have a webhook set to trigger when a camera detects motion. When this happens it tends to send several webhooks at once, so it triggers the automation several times in HA. I would like the automation to trigger a max of once every 10 seconds.

Thanks!

Add this condition:

  conditions:
  - condition: template
    value_template: "{{ now() - this.attributes.last_triggered|default(as_datetime(0),1) > timedelta(seconds=6) }}"

Change the number of seconds at the end of the template to what you want or change it to minutes or hours

1 Like

Another hack is setting the automation to single mode and then add a 10 sec delay as the last command in the automation.

4 Likes

Though don’t use that for longer than a few 10s of second or the automation has a higher probability of being interrupted, leading to unpredictable results. Also setting max_exceeded: silent will prevent warnings in the logs form attempting more than one automation run at once.

1 Like

Good idea with that disclaimer.
Waits should not be used for longer periods!

1 Like

Testing now! Thanks so much, Tom

Thanks! Will play around with this as well.

I would say my solution is a hack.
The best solution is the one tom_l presents.

With short delays the chance of interruptions by reload and the like is small, but they are present!

1 Like