Delay service until last action is complete

I am trying to figure out a way to string media streams to play back to back. Problem is right now, i set a delay after each item but since the item’s lengths arent consistent it leads to dead space or playback getting cut.

Current actions:

    - service: tts.google_say
  entity_id: media_player.audiogroup
  data_template:
    message: >
      Good Morning! The weather is {{states.sensor.pws_weather.state}} with a current temperature of {{states.sensor.pws_temp_f.state  | round(0)}} degrees with a high of {{ states.sensor.dark_sky_daily_high_apparent_temperature.state | float | round(0) }} degrees and a low of {{states.sensor.dark_sky_daily_low_apparent_temperature.state  | round(0)}} degrees.
- delay: 00:00:30
- service: media_player.play_media
  data:
    entity_id: media_player.audiogroup
    media_content_type: "audio/mp3"
  data_template:
    media_content_id: >
        {{ "http://myurl/audio/1.mp3"}}
- delay: 00:05:00
- service: media_player.play_media
  data:
    entity_id: media_player.audiogroup
    media_content_type: "audio/mp3"
  data_template:
    media_content_id: >
        {{ "http://myurl/audio/2.mp3"}}
- delay: 00:01:10
- service: media_player.play_media
  data:
    entity_id: media_player.audiogroup
    media_content_type: "audio/mp3"
  data_template:
    media_content_id: >
        {{ "http://17473.live.streamtheworld.com:3690/WQHTAAC_SC"}}
1 Like

WAIT
Wait until some things are complete. We support at the moment wait_template for waiting until a condition is true, see also on Template-Trigger. It is possible to set a timeout after which the script will abort its execution if the condition is not satisfied. Timeout has the same syntax as delay.

wait until media player have stop the playing

wait_template: “{{ states.media_player.floor.state == ‘stop’ }}”

wait until a valve is < 10 or abort after 1 minutes.

wait_template: “{{ states.climate.kitchen.attributes.valve < 10 }}”
timeout: 00:01:00
When using wait_template within an automation trigger.entity_id is supported for state, numeric_state and template triggers, see also Available-Trigger-Data.

wait_template: “{{ is_state(trigger.entity_id, ‘on’) }}”
It is also possible to use dummy variables, e.g., in scripts, when using wait_template.

Service call, e.g. from an automation.

service: script.do_something
data_template:
dummy: “{{ input_boolean.switch }}”

Inside the script

wait_template: “{{ is_state(dummy, ‘off’) }}”

2 Likes

Thank you! This worked perfectly!