Automation rate limiting

I suggest native support for rate limiting automations.

There is a forum thread suggesting different solutions how to rate limit automations:

However, these are either quite verbose, like adding a separate script that disables, delays and enables the automation, or rely on script sematics that prevent running a script twice in parallel.
It would be easiest to be able to specify the rate limit directly in the automation definition, for example

automation:
  - alias: 'Some notification'
    trigger:
      ...
    condition:
      ...
    # No more than once per 5 minutes
    rate_limit: 
      minutes: 5
    action:
      service: notify.notify
      data:
        message: 'Some notification'

Iā€™m not sure where it would be best to put the rate_limit expression ā€“ in the trigger, condition or at the top level?

Why not just put a

delay:
  minutes: 5

in the automation (after executing the action). That should effectively give you the same experience.

CARLO

3 Likes

Thanks! I havenā€™t noticed before that there can be multiple actions in the automation.

Turns out that adding a delay at the end of an automation action only works if the automation runs a script and the delay is at the end of the script. Putting a delay directly inside the automation action doesnā€™t rate limit the automation. Apparently, HA runs the automation action even when the previous delay hasnā€™t ended.

To put it in code,
this works:

automation:
  ...
  action:
    service: script.do_stuff

script:
  do_stuff:
    sequence:
      - do_something
      - delay:
          minutes: 10

This doesnā€™t:

automation:
  ...
  action:
    - do_something
    - delay:
        minutes: 10

Personally, I would prefer an explicit rate_limit attribute of the automation.

1 Like

I agree a ā€˜rate_limitā€™ would be better. Iā€™m starting to see the need for that with my speech automations. I only want to hear about the thermostat every so often. :confused:

1 Like

I wrote a tip about this topic here: Limit automation triggering

Basically, you can turn off the automation as the first action, do all the normal stuff then add a delay and enable it again as the last actions.

5 Likes

+1
This would definitely be usefull a so we donā€™t need the workarounds