Pause automation so it doesn’t trigger every second

I have a couple of automations that have a tendency to quick fire 10 times in 10 seconds (exaggeration but to make a point). Specifically snapshots from cameras based on motion sometimes go haywire.

So far the only way I found to prevent it is to create another automation that turns the first one off after firing and then switches it back on after a delay.

Surely there must be a better/easier way - any thoughts?

If throttling the repeat rate of the automation is your only concern, you could simply add a condition that checks the current time compared to when the automation was last triggered and enforce some suitable minimum time between each run.

conditions:
- "{{ now() - state_attr(this.entity_id, 'last_triggered') > timedelta(seconds=5) }}"

Assuming it’s in single mode you can also add a delay as the last step, and that’ll stop further runs from happening during that delay.

love this one, thanks a lot. Added already, will see how it goes

the one from Mayhem is a more elegant one but also a good and simple shout

1 Like

Do note that while this should work fine for existing automations, it will break for new automations (and thus is not immediately suitable for blueprints) as the last_triggered attribute will initially be null / none. Also not sure whether it is preserved between server restarts? So just to be safe, you may want to add an additional default safeguard:

conditions:
- "{{ now() - (state_attr(this.entity_id, 'last_triggered') or as_datetime(0)) > timedelta(seconds=5) }}"

@WaldB I’m in the same situation but the solution here doesn’t seem to work with blueprints. Will you share your delay automation?

It does/should work, as long as you add the default safeguard I explained just above.

@Mayhem_SWE
Thanks. I can’t get it to work. Adding this to the blueprint breaks it; adding to the automation doesn’t work for me.

Okay I’ve had another look at this. I really thought the default filter would kick in on none (which is what state_attr() returns for a non-existent entity_id and/or attribute), but I guess it only does on undefined? My bad… Try this instead:

conditions:
- "{{ now() - (state_attr(this.entity_id, 'last_triggered') or as_datetime(0)) > timedelta(seconds=5) }}"