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.
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:
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: