Example code:
alias: Sound alarm
description: ''
trigger:
- platform: state
entity_id: E1
to: notifying
- platform: state
entity_id: E2
to: notifying
condition: []
action:
- repeat:
while:
- condition: state
entity_id: E1
state: notifying
- condition: or
conditions:
- condition: state
entity_id: E2
state: notifying
sequence:
- service: media_player.play_media
data:
media_content_id: >-
https://xxx.com/yyy/alarm.wav
media_content_type: music
target:
entity_id: media_player.xxxxxx-yyyyyyy
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
Some initial data:
- E1 and E2 can never be at “notifying” state at the same time
- sequence is playing about 10 seconds long media file, when triggered. The structure is OK and works, let’s not concentrate on it
What I was aiming for, and what I thought this structure would do, is the following:
- Triggered by either E1 or E2 in “notifying” state.
- if either E1 or E2 is “notifying”, while loop plays 10 sec media file and 10 sec delay in the end gives it time to finish.
- If E1 or E2 is still notifying, it runs the sequency again, that is, plays the audio file during 10 sec delay and so on.
Instead of that, what the structure does is:
- If E1 is notifying, behavior is like described before. File is played in a continuous loop as long E1 is “notifying”
- If E2 is notifying, the file is played only once.
Why is this?