Automation with multiple triggers but don't want actions to always happen

I have an automation setup, and there are two triggers that effectively do the same thing. Thing is, sometimes one sensor triggers, other times the other sensor triggers first, it all depends on how quick the cloud service is responding. I want either one to trigger the automation, but I do not want the automation to trigger more than once in a period of 5 minutes, give or take. How can I accomplish this so that the below automation will still in essence work, but that it won’t trigger more than once?

alias: Garage Door Opened
description: ''
trigger:
  - platform: state
    entity_id: cover.garage_door
    to: opening
  - platform: state
    entity_id:
      - binary_sensor.garage_door
    to: 'on'
condition: []
action:
  - service: notify.alexa_media
    data:
      target: >-
        media_player.echo_show_kitchen, media_player.bedroom_echo,
        media_player.basement_echo
      message: Garage Door Open
      data:
        type: announce
mode: single

The easiest way is to put a wait period after the “real” action. Because the automation is set to single mode, it won’t run more than once at the same time. So as long as the wait period is busy, a seconds trigger will be ignored.

Delay will not survive a reboot. It this is acceptabe then your solution will work.

That is why I said easiest. :smile: other that will survive reboot is to create a timer helper with the flag to on to restore it on a reboot. Start the timer as part of the action, and put in a condition that the timer should not be running.

What about a template condition? Would it survive a restart? E.g.


{{ ( now() - state_attr('automation.xxx', 'last_triggered') ) > timedelta(minutes=5) }}

1 Like

Unless something has changed…no.

Last triggered gets reset in restart.

But if the delay is 5 minutes or less (unless you REALLY need the automation to not trigger for exactly 5 minutes) then I wouldn’t worry about it.

Just put in the condition that the last triggered attribute was more than 5 minutes ago.

The chances of you restarting in that 5 minutes is at most 1 in 12 and that’s only if you do a lot of development.

1 Like