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

This is my Script, which is calling an automation

alias: Where is Person X
sequence:
  - service: automation.trigger
    data: {}
    target:
      entity_id: automation.personX_location_to_google_home_v6
mode: single

That’s a comprehensive write up, however I will need the YAML code of the automation as well, and changes in your script will be required.
I also don’t understand why you trigger an automation in your script, it makes more sense to turn on a script to me.

UPDATE:
Please ignore this post and jump to my next post to get the final version of my script.

Well the only way I found is by creating the automation that was called by the script. The YMAL code of my script is given just above in my previous post and the YMAL code of my automation is at the end of my PDF. But I give it just below:

You can change my script ofcourse.

Initialy I have done this document keeping in mind that some user don’t want to go and check the YAML code so I gave the easiest way to do it and just at the end when it was not possible to do it without using the code I gave the instructions to go and edit the code :slight_smile:

After reading you message I have changed my code. Now instead of using a Script + Automation, I have intégrated all in the One Script. Please consider the below given Script as my new program and ignore my previous post.

Many thanks.

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: media_player.nest_hub
          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: media_player.nest_hub
          dashboard_path: lovelace
          view_path: psxmap
      - delay:
          hours: 0
          minutes: 1
          seconds: 10
          milliseconds: 0
      - service: media_player.turn_off
        data: {}
        target:
          device_id: 82c4023ee17f86bf5177ab8ce2f6aXXX
    else:
      - service: tts.cloud_say
        data:
          entity_id: media_player.nest_hub
          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: media_player.nest_hub
          dashboard_path: lovelace
          view_path: psxmap
      - delay:
          hours: 0
          minutes: 1
          seconds: 10
          milliseconds: 0
      - service: media_player.turn_off
        data: {}
        target:
          device_id: 82c4023ee17f86bf5177ab8ce2f6aXXX
mode: single

This could work, but I don’t have time to look into it today or tomorrow. I will come back to you on Thursday with some suggestions.

I assume you already have the Google Home Voice script set up?

No problem take your time

If you mean the communication between Google Assistant and HA by connecting to the script, the answer is “YES”. Everything is working perfectly. When I say: “Hey Goggle where is Person X”, It is replying to me with what I have written in the script. Ths only thing now is to have this program sent to the Nesthub I’m talking with.

No, I mean the script which is mentioned in the first post of this community post. Did you already add that script to your configuration?

No I didn’t, to be honnest, I was as I said before lost with all the modifications, updates and other posts. So that’s why I wanted you to help me. When reading in the middle of these posts, I red somewhere that we don’t need to add that script etc… So If you can just guide me with the latest update it will really help me.

Again thanks a lot and I really appreciate your help

  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