How do I add a timer to prevent constant re-triggering?

I have a TTS announcement on doorbell motion. It’s working but the issue is, if people are hanging out in front of the door, it’s constantly triggering the announcement. How do I configure so this trigger can only happen once every 5 minutes, for example.

trigger:
  - type: motion
    platform: device
    entity_id: binary_sensor.motion_g4_doorbell
    domain: binary_sensor
condition:
  - condition: time
    after: '09:00:00'
    before: '23:00:00'
action:
  - service: media_player.volume_set
    target:
      entity_id: media_player.google_hubs
    data:
      volume_level: 0.65
  - service: tts.google_say
    data:
      entity_id: media_player.google_hubs
      message: Motion at Front Door
mode: single

The simplest is to put a delay after the action

  - service: tts.google_say
    data:
      entity_id: media_player.google_hubs
      message: Motion at Front Door
  - delay:
      minutes: 5

If you want the delay to be customizable from Lovelace you can use an input number like this.

  - delay:
      minutes: '{{ states(''input_number.doorbell_delay'')| int }}'
1 Like

By adding the following to the condition section the automation will only trigger if it hasn’t been triggered for 5 minutes or longer.

condition:
  - condition: time
    after: '09:00:00'
    before: '23:00:00'
  - condition: template
    value_template: "{{(as_timestamp(now()) - as_timestamp(state_attr('automation.NAME_OF_YOUR_AUTOMATION', 'last_triggered'))) >= 300}}"

Let me know if it works because I’m not sure. Do you use NR ? If so, just add a throttle node between the motion detected and the action.

1 Like

Thank you very much! I tried both and both seem to work. I don’t use NR (still a HA novice).