Automation trigger limit

Would it be possible to implement a limit on how frequently a automation can trigger? I have a looping automation to mirror a esphome light to a virtual switch in smartthings. I have tried putting delay and “for” duration conditions in the automation’s. But, as my wife recently found out, if you switch all the lights off at once it causes a death loop of seizure inducing flashing through out the whole house. She was happy, lol.

Basically if i could limit the trigger rate to 1/second it would break the loop. Something I can do in node red, but not HA. I recently moved off node red due to memory leaking issues on my pi.

But that’s it. just a additional automation tool is my feature request.

Thanks.

You could use last triggered condition like this;

condition:
  - condition: template
    value_template: "{{ ( as_timestamp(now()) - as_timestamp(state_attr('automation.whatever, 'last_triggered')) |int(0) ) > 10 }}"
2 Likes

Sweet. How would that look in this?

- alias: SmartThings virtual switch mirror 1 Basement hall light
  trigger:
    platform: state
    entity_id: light.basement_hall_light
    to: 'on'
    for: 00:00:01
  condition:
  - condition: state
    entity_id: switch.basement_hall_light
    state: 'off'
  - condition: template
    value_template: "{{ ( as_timestamp(now()) - as_timestamp(state_attr('automation.smartthings_virtual_switch_mirror_1_basement_hall_light, 'last_triggered')) |int(0) ) > 10 }}"
  action:
  - delay: 00:00:01
  - service: switch.turn_on
    entity_id: switch.basement_hall_light
#
- alias: SmartThings virtual switch mirror 2 Basement hall light
  trigger:
    platform: state
    entity_id: light.basement_hall_light
    to: 'off'
    for: 00:00:01
  condition:
    condition: state
    entity_id: switch.basement_hall_light
    state: 'on'
  action:
  - delay: 00:00:01
  - service: switch.turn_off
    entity_id: switch.basement_hall_light
#
- alias: SmartThings virtual switch mirror 3 Basement hall light
  trigger:
    platform: state
    entity_id: switch.basement_hall_light
    to: 'on'
    for: 00:00:01
  condition:
    condition: state
    entity_id: light.basement_hall_light
    state: 'off'
  action:
  - delay: 00:00:01
  - service: light.turn_on
    entity_id: light.basement_hall_light
#
- alias: SmartThings virtual switch mirror 4 Basement hall light
  trigger:
    platform: state
    entity_id: switch.basement_hall_light
    to: 'off'
    for: 00:00:01
  condition:
    condition: state
    entity_id: light.basement_hall_light
    state: 'on'
  action:
  - delay: 00:00:01
  - service: light.turn_off
    entity_id: light.basement_hall_light

like that? the first one?

I think i see what you did there. is that 10 seconds it evaluates against?

Okay, i am starting to implement it. I have it in one light so far. 10 to go. thanks, i’ll let you know if it kills the loop.

1 Like

seems to work. thanks!

Did you find a better way limit triggering since?
This workaround merely limits how often the automation action is executed, but not how often it is triggered.
I am using it as I haven’t found better way, but the automation is still triggered multiple times a second for fast changing values and each such trigger has to be evaluated, the condition checked and logged to traces.
So it practically means you have no chance to debug it (as the trace is gone before you check it) and it must be causing quite considerable load on the system.

1 Like

Hi there! did you ever manage to solve this by limiting triggering rather than execution?

I haven’t used this in a long while, but a quick thought that may work. Maybe as part of the action, disable the automation for a set delay, based off your requirements for a trigger limit?