Delay between services in action - TTS and Play media

Hi guys,

I have the following action in my “Good morning automation” - once motion is detected it sends TTS message to my google home and then says the weather - this worked fine for a long time. Now I want to play a random MP3 in the end. The problem is that it starts playing an MP3 file immediately without finishing TTS.

  action:
  - service: tts.google_say
    entity_id: media_player.living_room_speaker
    data_template:
      message:  "HERE COMES MY WEATHER FORECAST"
  - service: media_player.play_media 
    data_template:                 
      entity_id: media_player.living_room_speaker            
      media_content_id: "https://MYDOMAIN.duckdns.org/local/mp3/intros/{{range(1, 20)|random}}.mp3"
      media_content_type: 'audio/mp3'

I undertand why it is doing that but is there a solution for this?
I know that I can add a delay between services (delay: 00:00:20), but my weather text could be just 15 seconds or could be 30 seconds, the same delay interval is not a nice solution.

Is there a way to call the second service after google home stopped saying the text?

Maybe a wait template? Does the media player state or attribute change when playing the weather forecast?

1 Like

Once TTS is played - media player state changes to idle, good point actually, will look in that direction

Didn’t know that wait_templait exists, this is a solution for my problem and will make many of my automations much simpler, thanks!

  - wait_template: "{{ is_state('media_player.living_room_speaker', 'idle') }}"
    timeout: '00:00:25'
1 Like

Hi,

In which part of the yaml file I have to place this line? I made the automation in UI but I can edit it with yaml ofcourse.

Can someone explain mealso what this line will do?

Another solution is to use the custom integration Chime TTS which combines the mp3 and TTS audio into a single local file to avoid any lag between the two.