After TTS I add a delay enough for google to be finished sayng the nmesage 3-5 sec.
then I set the source again to what it was before and it will start playing right away.
Ok, In my case I have a Sonos and the source have a value when you pick a source, like a radio station from the favorites. I did not check how it is on a Nest or other google devices yet.
but you can always use the content_Id.
I have actually just made an extended version of the code that handles various situations also if the device was not playing before the TTS.
I have it all in a script that I call from the automation:
Here you go, and please let me know if you have any questions or challenges:
but I have a problem, all my TTS alerts starts from a automation trigger , how i can run the script inside of automation and send “the text to play by tts” as parameter ?
# Example configuration.yaml entry
automation:
trigger:
platform: state
entity_id: light.bedroom
from: "off"
to: "on"
action:
service: script.turn_on
target:
entity_id: script.notify_pushover
data:
variables:
title: "State change"
message: "The light is on!"
You will need to modify the script to accept the parameter as per this on the linked page:
Here is a modified version of the script that takes two parameters:
the tts message
the media player entity_Id so you ca use it with different media players in different cases.
and finally I added taking a back up of the volume prior the TTS, securing the TTS message is played at a given level example 75% and then restoring the original volume.
and here is an action example from an automation showing how to call the script and pass the parameters:
- service: script.turn_on
target:
entity_id: script.tts_and_continue
data:
variables:
msg: this is a test message, replace it by yours
tts_entity: media_player.spisestue
Let me know if you have other challenges
good luck
I tried with my setup (using spotify) and it doesn’t work. I think it’s pretty normal because spotify needs a custom component to allow HA to start playing music…
I confirm that it works fine with Spotify when running on Sonos devices but, unfortunately not on Chrome cast or other google devices like the google mini or nest.
other streaming apps like TuneIn work fine on both Sonos and Google devices.
The reason basically is that calling the service media_player.play_media that is used in the script works on Sonos devices but not on google. Maybe we need the custom component you mentioned.
I’ll give it a try and look further for a solution
Then the updated version of the script will work with SpotifyConnect on Chrome cast devices like yours.
On Sonos it still works with Sonos if you start Spotify from the Sonos App but not if you choose the Sonos SpotifyConnect device from the the Spotify app.
On the other hand, other streaming services like TuneIn still works with both Chrome cast and Sonos devices.
As you ca see i introduced delays several places to make sure previous commands are finished executing before new ones are called. Maybe some of these delays can be made shorter. You can experiment finetuning these.
What I’ve found is a simply copy paste of the script. What I’v e noticed and that my google mini make the blink after tts message but the music does not start. Moreover looking ath te spotcast docs maybe the second command of the script is not required?
Yes I also noticed some inconsistency too.
I don’t have a google mini but other Chinese products a Mi AI speaker and Mi TV Box box. with built in Chrome cast and these behave differently. So maybe the real Chrome cast behave in yet another way.
If it still don’t work, please send me the state and attributes values for your media player from the developer tools “states tab”, before and after you call the script?
I was looking for something like this! Thanks for this great script!
I have edited the script to fit my use case a little better:
In the Google Home app, I have bundled my two Google Home mini speakers together to a “Home Group” (the group has the name home_group. This home group is the default playback device.
This shows up as an extra media player in Home Assistant.
Whenever I say: “Hey Google, play my favourites” it will start playing my liked songs in Spotify on both speakers.
I want to play my tts on only a single device. This automatically stops playback on the entire group for some reason.
Whenever a tts comes along, I want playback to continue on both speakers.
So it detects the state of the group and will continue playing on either the tts_entity or on the group depending on the state.
It is not the most elegant solution, but this is working fine for now.
If you have multiple groups however, you’ll have to come up with an even more clever way of knowing which group is playing.
Glad to hear my script was useful and inspired you for your solution:
Maybe you can optimize the code by conditional value of the resume_entity instead of a choose construction and two different calls with the only difference by the entity. if this works, you can reconsider containing the resume scipt, in the main script saving further calls.
Try something like this (Not sure the indention is correct)