Automation repeats despite being in single mode

I have an automation that plays a radio station everytime a motion detector detects motion between certain hours and I made sure the mode is SINGLE but despite this the automation restarts every single time it detects motion :confused:

Can anyone explain why? Here is the automation YAML:

alias: Morning music Bixu
description: ""
trigger:
  - type: motion
    platform: device
    device_id: bd7d9da9b2bbb123f3fa5ab4238ee8b0
    entity_id: e953d1591796387750eb6acac4af511c
    domain: binary_sensor
condition:
  - condition: time
    weekday:
      - fri
      - thu
      - wed
      - tue
      - mon
    after: "06:50:00"
    before: "07:50:00"
action:
  - service: media_player.volume_set
    target:
      device_id: 2978cc4ab0059c242bef3159ca6592ca
    data:
      volume_level: 0.3
  - service: media_player.play_media
    target:
      entity_id: media_player.kitchen
    data:
      media_content_id: media-source://radio_browser/dfe3ebed-08cd-447a-9a58-efb8eebab9f8
      media_content_type: audio/aac
    metadata:
      title: RFM
      thumbnail: https://static2.mytuner.mobi/media/tvos_radios/8mByXHnRWv.png
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://radio_browser
        - media_content_type: music
          media_content_id: media-source://radio_browser/country/PT
mode: single

Thank you!

That’s the normal way for automation to work… The trigger is a motion detection so the automation will be triggered at every detection. Single means, the new automation cannot be launched if the same automation is already running…

So to avoid to have it running at each movement, you need to add like for instance an input boolean that you force to “on” when the automation runs and test in the automation that the input_boolean is not “on” as an additional condition. You reset than this input_boolean to “off” at 8 am for example… so the automation can run again the day after…

1 Like

Welcome!

The automation is no longer “on” once service: media_player.play_media has run. You can see this in Traces (top right) > Trace timeline. Which means if the motion triggers again (within the timeframe), it will run the automation’s actions again.

You could limit the triggering by adding a simple condition that checks if it’s already playing.

condition: not
conditions:
  - condition: state
    entity_id: media_player.kitchen
    state: playing

However, you might want a condition more appropriate for your scenario, as that will prevent triggering if anything is playing on that media player, not just that specific radio.

3 Likes

Thank you so much, this explanation was the one I needed in order to understand the way this works since it’s not really that intuitive :sweat_smile:

For me, the automation was “on” since the speaker was playing so it wouldn’t make sense for it to restart but now I understand it’s only “on” in the exact moment the motion sensor detects motion.

Thanks again!

It’s “on” until it finishes executing all of its actions.

Your automation performed two actions that required less than a second’s worth of processing time and then it was finished. In other words, it was “busy” for about a second or two (its trace will tell you the exact duration).

Mode determines what the automation (or script) should do when it is triggered (or called) while it’s busy executing its actions. This automation is “busy” for such a short duration that the choice of mode (single, queued, parallel, etc) is irrelevant.

Reference

Script modes

1 Like