Background
In another post I have share a script to send actions to a Google Home and resume the stream (TuneIn / Spotify) which was playing afterwards. It also restores the volume, and you can work with Google Home speakers groups.
In my home I have several Google Nest/Home speakers, and I had some scripts where a TTS would be sent which was triggered by a Google Home routine. However, I could only set it to a predefined Google Home speaker, and not to the specific speaker on which I gave the voice command.
This made me thinking, and I found a solution for this, using the ambient sounds which you can start in your routines.
So I made a new script, which can be used in cooperation with the other script, to send a TTS or other actions, like e.g. an image, or a cast of your Lovelace dashboard to specific Google Home after you ask a question to it.
The script itself relies on the other script, so make sure that script is running correctly first, including the prerequisites.
Requirements
- Home Assistant version 2022.2 is required because the
iif
filter/function introduced in that version is used in templates - The Google Home Resume script and all its prerequisites in case you want to resume what was playing afterwards.
Most recent change
Version 1.5.0 - 20 May 2022
New feature
- Added the
target_variable
option. When set totrue
it will add the variablevoice_target
to the service call containing the entity_id of the Google Home which was used to trigger the script. This can be used to use the entity in a script. It will only be added on script service calls. In case the Google Home Resume script is used as well, it will also add the entity_id underextra
, so the resume script will recognize it as a target to be resumed.
Older changes can be found here
Prerequisites
- Expose scripts to Google Assistant (either use Nabu Casa, or the manual setup)
- A separate script per TTS messsage, which will be called from the Google Home
- A routine in the Google Home app which starts the script (you can find your scripts under
Adjust Home Devices
āAdjust scenes
)
The last action in your routine should be to start the ambient sound (Play and control media
āSleep sounds
ā Any sound you only use for this script - Define the right variables for your home in the Google Home Voice script as desribed below
How to use start script
To use the script you will need to provide the action
to be performed. Like the Google Home Resume script only service calls are working. In case no service calls are entered the script will stop (it will only stop the ambient sound, but not resume the previous stream).
There is no need to provide the target
, it will be added by the Google Home Voice script, based on the ambient sound playing.
In case you need to change the volume (eg for TTS) you can use the volume
variable.
Example
Letās say you have the Waze and proximity integrations set up, and want to send out a TTS message with the ETA.
The script will then be something like this:
eta_thefes:
alias: "ETA TheFes"
icon: mdi:car
sequence:
- variables:
message: >
{% set eta = (as_timestamp(now()) + 60 * states ('sensor.thefes_home') | float(0) | timestamp_custom('%H:%M') %}
If TheFes leaves now, he will be home at {{ eta }}.
- alias: "TTS for speaker voice command"
service: script.google_home_voice
data:
target_conversion:
media_player.kitchen_hub: media_player.livinghome_group
use_resume: true
action:
- alias: "Send TTS message"
service: tts.google_cloud_say
data:
message: "{{ message }}"
volume: 35
Variables in service call for the script:
Variable | Required | Description |
---|---|---|
action | Yes | The title of the ambient sound as shown in developer tools > states |
target_conversion | No | A list dictonary with target replacements when you send the voice command |
use_resume | No | Set to false in case you donāt want to use the Google Home Resume script, and just want to send the actions |
target_variable | No | If set to true the entity_id of the Google Home will be added as the variable voice_target so it can be used in scripts, and added under extra so the Google Home Resume script will resume it. |
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
Variable | Required | Example | Description |
---|---|---|---|
check_for_title | Yes | Witte Ruis |
The title of the ambient sound as shown in developer tools > states |
use_resume | No | false |
Use use_resume: false if you donāt have the Google Home Resume script. Donāt set this setting when you do want to use it, but set it in the script call instead if you need it. Default is true . |
Other scripts
For other related Google Home scripst, see my Github page
Buy me a coffee
If you like this script, please feel free to buy me a coffee (I might spend it on another beverage though).
In case you decide to do so, thanks a lot!