can report that they are close, but most certainly not identical. My final setup with the 2 identical scripts is definitely better, or more secure.
Had already experienced the timing issues when using 1 executable script and and looping, as is yours. That is happening with your script also. It somehow is more sensitive for HA internals than using 2 scripts both executing the play script. They don’t have to wait for one another.
The delay seems more robust than the wait_template.
tested in a complete comparison, only needing the boolean to flip for either loop script:
with the below code:
sound_bite:
alias: Sound bite
sequence:
- service: media_player.play_media
data_template:
entity_id: >
{{states('sensor.sound_bite_player')}}
media_content_id: >
{{states('sensor.sound_bite')}}
media_content_type: 'music'
play_sound_bite:
alias: Play sound bite
sequence:
- service: script.sound_bite
- delay:
seconds: >
{{state_attr(states('sensor.sound_bite_player'),'media_duration')|int}}
- condition: template
value_template: >
{{is_state('input_boolean.loop_sound_bite','on')}}
- service_template: >
script.play_sound_bite_{{ 'loop' if is_state('input_boolean.play_loop_or_alt','off') else 'loop_alt' }}
play_sound_bite_loop:
alias: Play sound bite loop
sequence:
- service: script.sound_bite
- delay:
seconds: >
{{state_attr(states('sensor.sound_bite_player'),'media_duration')|int}}
- condition: template
value_template: >
{{is_state('input_boolean.loop_sound_bite','on')}}
- service: script.play_sound_bite
play_sound_bite_loop_alt:
alias: Play sound bite loop alt
sequence:
- wait_template: >
{{ is_state('script.play_sound_bite', 'off') }}
- service: script.play_sound_bite
too bad we can’t post videos, because its fun to see the scripts flip and take control
btw your suggestion Is better when changing sound bites in between, and the attribute ‘media_duration’ hasn’t been adjusted accordingly yet. That is 1 time only, and of course, only relevant in this testing scenario. But noteworthy. --> Cookbook