Wait for end of TTS command on Google Home

Hi all!

I am still fairly new to HA, so hope this is not too basic of a question. I am playing around with TTS on a Google Home and try to send multiple messages as a sequence to a Google Home. I am creating a script to manage this and take the messages as input variable. The challenge I am facing is that I am calling the first TTS command, then I need a delay, and then the second TTS command. The delay needs to be as long as Google Home needs for the first message, without knowing the length of it beforehand. A minimal setup of the fixed length delay would be:

  alias: 'Broadcast a message on a single device'
    - service: tts.google_say
        entity_id: "{{ device_name }}"
        message: "{{ msg }}"
        language: "{{ lang }}"
    - delay:
        seconds: 2
    - service: tts.google_say
        entity_id: "{{ device_name }}"
        message: "{{ msg2 }}"
        language: "{{ lang }}"

I am looking for a step that kind of checks if Google Home is still speaking and waits for it to end, only then continues with the script. Is anybody having any ideas/suggestions for this? Thank you!

Presuming that the state changes to idle at the end of the speech

wait_template: "{{ is_state(device_name, 'idle') }}"

Thanks, Marc. It seems that the state does not switch to idle after playing. In the HA dashboard, it also shows the “media player” as still active. Guess this has something to do with Google Home setup. I also tried

wait_template: "{{ not(is_state(device_name, 'playing')) }}"

but also doesn’t react to that. Any other ideas?

EDIT: just noticed that the Google Home turns back to idle after a few minutes only, not at the end of the message.

Mine always goes to idle after the message.
But the order should be

TTS the message
Delay 2 seconds
wait_template to idle

Because the TTS doesn’t have time to start before the wait_template says it’s idle.

Amazing - that did the trick! Thanks!
I also tried it with 1 second delay and that one wasn’t enough … interesting that it takes that long!

But it actually doesn’t delay anything it just “waits” for media player to update its status