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
Can anyone explain why? Here is the automation YAML:
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âŚ
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.
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
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.
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.