It’s my understanding that a call to tts.speak or tts.<whatever> gets converted to a call to media_player.play_media and its announce option is automatically set to true. Users have reported that when announce is true, the player doesn’t report playing while it’s playing the announcement.
In other words, while playing the announcement, it doesn’t change state to playing and then, when it’s done, to either idle or paused but just remains either idle/paused. That makes it challenging to determine when the announcement has finished playing.
If you take that into account, plus the fact that this script isn’t necessarily monitoring the state of the media_player that’s handling the announcement, it’s clear that it will experience problems.
For starters, you have to fix the part that is hard-coded to wait for the living room speaker and, unless you really must have the announce feature, you may wish to use media_player.play_media directly with announce set to false.
The following example is untested and may require adjustments to work in your environment.
service: media_player.play_media
data:
media_content_id: 'media-source://tts/google_cloud?message=Your message goes here'
media_content_type: 'provider'
announce: false
target:
entity_id: media_player.your_chosen_player