Copy the script from the GitHub page, and add it to your scripts.yaml or wherever you place your scripts.
Make sure your Google Nest Hub is playing an ambient sound, White Noise for example by giving it a voice command. Make sure that it is playing
Go to Developer Tools > States and find your Google Nest Hub media player entity, copy the media_title attribute contents, it should be something like White Noise or another title representing the ambient sound which is playing
Edit the Google Home Voice script variables:
variables:
check_for_title: "White Noise" #or whatever title you got from the media_player entity
use_resume: false #unless you also set up the Google Home Resume script to resume what was playing afterwards
Create a new script which sends the right commands to the Google Home Voice script, something like this:
person_x_locator_voice:
alias: Locate person X by voice command
sequence:
- alias: "TTS for speaker voice command"
service: script.google_home_voice
data:
target_variable: true
action:
- alias: "Trigger Person X locator cast script"
service: script.person_x_location # this should be the script you posted above
Change the script you posted, to use the variable created by the Google Home Voice script
alias: PersonX Location Script to Google Home v1
sequence:
- if:
- condition: state
entity_id: person.personx
state: not_home
then:
- service: tts.cloud_say
data:
entity_id: "{{ voice_target }}"
message: The Person X is out of known zones, but I will cast you a map withing few seconds
- delay:
hours: 0
minutes: 0
seconds: 6
milliseconds: 0
- service: cast.show_lovelace_view
data:
entity_id: "{{ voice_target }}"
dashboard_path: lovelace
view_path: psxmap
- delay:
hours: 0
minutes: 1
seconds: 10
milliseconds: 0
- service: media_player.turn_off
data: {}
target:
entity_id: "{{ voice_target }}"
else:
- service: tts.cloud_say
data:
entity_id: "{{ voice_target }}"
message: The Person X is nearby {{ states('person.personx')}}
- delay:
hours: 0
minutes: 0
seconds: 6
milliseconds: 0
- service: cast.show_lovelace_view
data:
entity_id: "{{ voice_target }}"
dashboard_path: lovelace
view_path: psxmap
- delay:
hours: 0
minutes: 1
seconds: 10
milliseconds: 0
- service: media_player.turn_off
data: {}
target:
entity_id: "{{ voice_target }}"
mode: single
Create a routine in the Google Home app which triggers the script created in step 5, and ends with playing the ambient sound.
Absolutely brilliant idea. I just wrote a briefing/home status script and realized the need to solve the problem of playing to the evoked speaker. Looking forward to implementation when I can get Resume up and running again.
I tried to use it with Sonos and Google Assistant but unfortunately Sonos doesn’t report playing ambient noises (e.g. white noise). It’s not visible in the Sonos app as well. What I tried is to play a song from Spotify instead, but the problem is that Google Assistant announces the song with “All right, playing Dancing Queen on Spotify”. Then the played song is visible in the Home Assistant media player state, but it takes sometimes over 10 seconds to trigger.
Wondering if you have any other ideas when ambient sounds are not detected by Home Assistant media player?
Waiting for Dancing Queen to start
google_home_voice:
alias: 00 - Google Home Voice
variables:
check_for_title: Dancing Queen
There’s one thing that I found could be used for the speaker identification which is the speaker volume. The Google Home routine can change the assistant volume by 1%. This is almost immediately visible in the Home Assistant state debugger - in this case from 0.4 to 0.39.
I tested this with a voice command like Decrease the volume by 1% and it also is immediately visible. Wondering if the script could be modified to detect this kind of change? E.g. when the script starts it would record all the volumes and detect which one dropped by 1 percentage point?
You will need to update the Google Home Resume script to 2022.11.3 as well if you update to this version
Improvements
The script makes use of the settings of the Google Home Resume script so it can immediately store all data, and no further processing in the Google Home Resume script is needed.
Hi, just found out this script, gonna read about it later, but just quick question, does it only work on google home devices? Or does it also work on Google Assistant devices, like a watch ?
No, it only works on Google Home devices.
It uses Google Home routines which start a ambient sound on the device. That will work on phones and watches as well, but those are not exposed as media_player in HA, so HA can’t see that the ambient sound is playing.