Script to send actions to the right Google Home (based on voice commands)

  1. Copy the script from the GitHub page, and add it to your scripts.yaml or wherever you place your scripts.
  2. 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
  3. 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
  4. 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
  1. 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
  1. 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
  1. Create a routine in the Google Home app which triggers the script created in step 5, and ends with playing the ambient sound.

Thank you very much I will try this this weekend and comeback to you.

Sorry as I’m a new user in Home Assistant can you just give little more info about step 1 & 2:

1/ Step 1: When you say copy the script, are you talking about this one: Link

2/ Step 2: is not clear. Do you want me to creat a script in HA that will play a sound in Google Home when I call it fromt the Nest Hub for example ?

Thank you for your help

  1. No I’m talking about this one, which is linked to in the first post of this topic: Script to send actions to the right Google Home (based on voice commands)
  2. Just say: “Hey Google, play white noise” to your Google Home Device

Thanks; I was busy this afternoon, I will try to check this tomorrow. I’ll let you know ASAP.

Update

Verstion 1.6.0 - 04 August 2022

:sparkles: New feature

  • Support for Music Assistant resume

I am so many versions behiind, really need to update at this point! Thanks again for this.

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?

Before

group_members:
  - media_player.salon_speakers
volume_level: 0.4

After

group_members:
  - media_player.salon_speakers
volume_level: 0.39

Update

Version 2022.11.0 - 21 November 2022

:red_circle: BREAKING

  • You will need to update the Google Home Resume script as well if you update to this version

:star2: Improvements

  • Changed version number to YYYY.MM.version
  • Templates to store data are improved, variables to store Spotify and YouTube Music data are now integrated in the general player data variable

Changes for Google Home Voice script

Version 2022.11.1 - 23 November 2022

:red_circle: BREAKING

  • You will need to update the Google Home Resume script to 2022.11.3 as well if you update to this version

:star2: 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.

Update

Version 2022.11.2 - 24 November 2022

:bug: Bug fixes

  • Better handling of empty settings

Update

Version 2022.11.3 - 26 November 2022

:bug: Bug fixes

  • Fix template copy/paste error causing variable store to fail

Update

2022.12 Happy Holidays; let’s bring the family together

:red_circle: BREAKING

  • Integrated into the Google Home Resume package, update according to the instructions

:star2: Improvements

  • Template improvements

  • More use of YAML anchors

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.

ok, thnx for feedback!

Got hopeful when I saw this. But then got a whole lot of 404 errors. Guess it was removed.

It’s moved, not removed.
It’s part of my Google Home Resume package now, which you can find here

Awesome. That’s the one time I love being wrong! :slight_smile: