This script supports
- Resuming of TuneIn, Spotify and generic streams after TTS message to a Google cast device
- Resuming an entire speaker group after a TTS has been sent to a single group member
- Resuming of individual group members after a TTS has been sent to a speaker group
Recent changes
1 February 2022
- BREAKING: This script is longer maintained by me. I have replaced it in my own configuration by the new Google Home Resume script. You can still report bugs or other issues, and I will do my best to fix them, but I will no longer add functionality to this script.
- Changed links to new location in my configuration (folder
not_maintained
so the script will still be available, and there will be no dead links)
25 January 2022
- Small fix to avoid error caused by undefined
fixed_picture
variable.
24 January 2022
- Created a fork which allows other actions than only TTS
- Simplified some templates
- Moved the last choose block (to turn on the players with screen) so it will actually be executed when needed.
13 January 2022
- Bugfix to resolve the error in case
players_screen
was not defined as variable.
9 January 2022
- Fixed a bug in the template to determine which entities should be resumed
7 January 2022
- Fixed a bug which would cause an error if
speaker_groups
was not defined. - Changed post 3 to an updated version of the dashboard card
6 January 2022
- Found out that sending the silent mp3 is not needed to retrieve the old volume, just turning them on works fine. Advantage is that only a very short delay is required for HA to be able to retrieve the current volumes (0.25 seconds is enough) so Iâve removed the settings to set if volume restore is required, it is now always enabled (but only performed when there were non playing entities).
The fieldssilent_mp3
,restore_volume_all
andvolume_non_playing
are removed. The script variablesdefault_volume_restore
anddelay_volume_restore
are removed as well. Iâve leftdefault_volume_level
for cases where the script was not able to retrieve the old volume.
This will not break your existing automations or scripts, but it might be that you now send some script variables in your actions which are no longer used.
3 January 2022
- Fixed an error in the template to determine volume restore is required
- Changed the order of sending the TTS and the volume change, and added a wait_template. This will make sure the volume is changed after the stream stopped, so the volume of the stream will not increase/decrease just before the TTS starts. This is based on the first
tts_target
from the list, so it works best if there is only onetts_target
.
2 January 2022
- Small change in condition to check if volume should be changed
- Small changes to some other conditions making the checks more robust
December 2021
- Fixed some bugs in template to determine spotcast account
- Added variable
fixed_picture
to link to pictures used as thumbnail after resuming. This prevents that the picture of the song which was playing will be used as a thumbnail. You can make sure a more generic picture is used (e.g. the logo of the TuneIn stream). - Placed script on Github instead of in this post so I can maintain it in one place
- Removed need to add
frequent_radio
streams. The script will resume any stream starting withhttp
- added variable
service_data
to provide additional service data for the tts_script call. - Fixed a bug in the template to determine the
tts_target_list
when thetts_target
was part of a group which was not playing. - Fixed a bug where both groups and single entities belonging to that group would be resumed
- Fixed a bug in determining the tts_targets_not_playing (was still using the old approach for speaker groups there)
- Made some changes to make it work with the updated script to send a TTS to the right Google Home (on which you asked the question)
November 2021
- BREAKING: removed the need for HA group entities for the speaker groups, the entites have to be defined in the script variables now.
- Added a variable
default_volume_level
for a default volume, in case the retreived volume is not a valid value (e.g. entity was not turned on by the script in time) - In case a single entity was playing, and this entity was belonging to a group, it would not resume if the TTS was sent to the group, and
speaker_group_split
was set tofalse
. This is fixed now. - added variable to provide
tts_service
Prerequisites
- Iâm using Google Cloud TTS, check the TTS variable to make sure this matches your setup. It could be that your TTS service also requires service data like language, in such cases you can add them using the
service_data
variable - For Spotify you need to have the Spotify integration installed, and Spotcast (available on HACS)
- The entity_idâs for media_player entities from the Spotify integration should be formatted like
media_player.spotify_{{ spotcast user }}
. For the primary Spotcast user you can use whatever you want as{{ spotcast user }}
. - The primary Spotcast user needs to be specified under
primary_spotcast
(see comment above). - To determine the Spotify account, the source in the Spotify media_players is used. This is compared to the friendly name of the Goolge Home media_player. Therefor the Google Home media players in HA need to have the exact same name as they have in the Google Home app (this is also already a requirement for Spotcast to work with entity_idâs)
- Google Nest Hub speakers can be entered under the variable
players_screen
. This will make sure the photo display is turned on again after the TTS in case nothing was already playing. - If you use speaker groups in the Google Home app, you can enter them under the variable
speaker_groups
. If you use them, youâll need to complete this variable, and add the group members in there as well (see the script for an example).
Known limitations
- It is possible to create speaker groups on the fly from the Google Home app, e.g. if you are playing something from Spotify on your Kitchen speaker, you can add your Living Room speaker in the Google Home app, without them belonging to a speaker group. The script wonât recognize these groups created on the fly. The cast integration wonât recognize these devices as playing anymore, so they wonât be resumed.
- When Spotify switches to a new song or starts playing, the Spotify Media Player will shortly not show as playing. When at that moment the script is started, the stream will not be resumed afterwards.
How to start the script
In case you want your script/automation to resume with the next action immediately
- alias: "TTS voor Nest Hub Kitchen"
service: script.turn_on
target:
entity_id: script.google_home_say
data:
variables:
tts_message: "Hello, hello! This is a test!"
tts_target: media_player.google_kitchen
tts_volume: 35
In case you want to have your script/automation wait for the TTS script to be completed
- alias: "TTS voor Nest Hub Kitchen"
service: script.google_home_say
data:
tts_message: "Hello, hello! This is a test!"
tts_target:
- media_player.google_kitchen
- media_player.google_living
- media_player.upstairs_group
tts_volume: 35
speaker_group_split: False
The script can also be started from the GUI, both in YAML mode and full GUI mode. The variables tts_message and tts_target are required. tts_volume is optional, in case it is not set the current volume will be used. In full GUI mode you can only select one enttiy_id as limitation of the the entity
selector. In YAML mode, or if called in a service call in an automation or script, you can enter multiple entity_ids.
Explanation of the fields
Field | Required | Example | Description |
---|---|---|---|
tts_message | Yes | "Hello, this is a test" |
The TTS message to be sent |
tts_target | Yes | media_player.kitchen_hub |
The media_players entities to which the TTS message should be sent. Multiple entities can be provided as a comma separated string, or as a list (see 2nd example above) |
tts_volume | No | 35 |
The volume for the TTS message, can be entered as a value between 1 and 100 , or as a value between 0 and 1 . Both 0.35 and 35 will result in 35% volume. |
speaker_group_split | No | True |
If set to True it will not send the TTS message to the Google Home speaker group entity, but it will send it to the separate member entities. Requires the speaker_groups to be provided in the script. |
And finally the script itself
Link to the script on my Github config, so I don have to maintain it in two places
Explanation of variables in the script
Only tts_service
is required, all other are optional, but will affect the workings of the script.
Variable | Default | Example | Description |
---|---|---|---|
tts_service | tts.google_cloud_say |
the service used for the tts service call | |
service_data | language: nl |
Add additional service data for your tts_service call | |
players_screen | See script on Github | Enter a list of cast devices with a screen. Do not use a comma seperated string here. | |
primary_spotcast | pepijn |
The Spotify account which is used as primary account for spotcast, should match the last part of the Spotify media player. | |
fixed_picture | See script on Github | A dictionary with the pictures. As key value the artist should be used (check media_artist in developer tools > states) |
|
speaker_groups | See script on Github | A combination of a dictionary and a list, with speaker groups of which all entities are included in another speaker group. | |
default_volume_level | 0.25 |
0.5 |
The default volume level to use to set the entity to if the old volume can not be retreived |
default_group_split | False |
True |
True/False default setting for splitting speaker groups to individual entities when sending TTS |