Automation keeps running again and again

Hi all,

In automation below, I have the issue that my trigger entity jumps from off to on, multiple times (because the person walking to the front-door needs to walk 5s :-))
How can I make sure that my automation runs only once after entity trigger ?

- id: '1742217033737'
  alias: popup.webcamvoordeur
  description: ''
  triggers:
  - trigger: state
    entity_id:
    - binary_sensor.g4_pro_person_detected
  conditions: []
  actions:
  - action: media_player.play_media
    metadata:
      title: dingdong.mp3
      thumbnail:
      media_class: music
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
    data:
      media_content_id: media-source://media_source/local/dingdong.mp3
      media_content_type: audio/mpeg
    target:
      entity_id: media_player.lenovo_tab_m11
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - action: tts.speak
    metadata: {}
    data:
      cache: true
      media_player_entity_id: media_player.lenovo_tab_m11
      message: Er is iemand aan de voordeur
      language: nl_BE
    target:
      entity_id: tts.piper
  - action: browser_mod.popup
    metadata: {}
    data:
      dismissable: true
      autoclose: false
      browser_id:
      - 186985c47d5865c097004f6ea5179a01
      content:
        type: picture-entity
        camera_view: live
        entity: camera.g4_pro_high
#        camera_image: camera.g4_pro_high
        show_state: false
        show_name: true
      timeout: 15000
      size: wide
  mode: single

Thanks a lot !

Kr,

Bart

1 Like

Hi Sir_Goodenough,

Looked into my previous posts, and I’m not seeing the same type of post. Or are you refering to another post that is similar to mine ?

Kind regards,

Bart

1 Like

My bad.
It showed up 2x in my list somehow
You are all good.

There are various ways to throttle an automation. For short throttle durations in automations that use single mode, you can usually just add a delay to the end of the automation’s action sequence. For longer throttle durations, you can use a condition that checks how long it has been since the automation last executed its actions:

  - alias: Prevent automation from running more than once per hour
    condition: template
    value_template: |
      {{ this.attributes.last_triggered | default(as_datetime(0), 1) < now() - timedelta(hours=1) }}

In addition to Didgeridrew’s advice, you may also wish to consider specifying the exact state-change that should trigger the automation. Currently, your State Trigger is configured to trigger for any state-change (and for changes in the binary_sensor’s attributes, if any).

  triggers:
    - trigger: state
      entity_id:
        - binary_sensor.g4_pro_person_detected
      from: 'off'
      to: 'on'
1 Like

Hi Didgeridrew,

Thanks a lot for your answer. Where exactly should I put this ?

Kr,
Bart

Hi 123,

Thanks a lot for your feedback, will adapt immediately

Kr,

Bart

In the conditions block…

Automation Config
- id: '1742217033737'
  alias: popup.webcamvoordeur
  description: ''
  triggers:
  - trigger: state
    entity_id:
    - binary_sensor.g4_pro_person_detected
  conditions: 
    - alias: Prevent automation from running more than once per hour
      condition: template
      value_template: |
        {{ this.attributes.last_triggered | default(as_datetime(0), 1) < now() - timedelta(hours=1) }}
  actions:
  - action: media_player.play_media
    metadata:
      title: dingdong.mp3
      thumbnail:
      media_class: music
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
    data:
      media_content_id: media-source://media_source/local/dingdong.mp3
      media_content_type: audio/mpeg
    target:
      entity_id: media_player.lenovo_tab_m11
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - action: tts.speak
    metadata: {}
    data:
      cache: true
      media_player_entity_id: media_player.lenovo_tab_m11
      message: Er is iemand aan de voordeur
      language: nl_BE
    target:
      entity_id: tts.piper
  - action: browser_mod.popup
    metadata: {}
    data:
      dismissable: true
      autoclose: false
      browser_id:
      - 186985c47d5865c097004f6ea5179a01
      content:
        type: picture-entity
        camera_view: live
        entity: camera.g4_pro_high
#        camera_image: camera.g4_pro_high
        show_state: false
        show_name: true
      timeout: 15000
      size: wide
  mode: single