Running HA scripts from Google Assistant

I’ve been struggeling quite a bit with running HA scripts from Google Assistant and feel that many posts here describe a Google Home app that has changed its interface. At least, I was confused. Since I got it working now, I’d like to share my learnings.

Pre-requisite: I’ve used the Nabu Casa cloud connection for Google Assistant. This might also work without Nabu Casa.

Test Script: I’ve put together a little test script that uses TTS to say something on a certain media_player:

alias: Hallo
sequence:
  - service: tts.azure_say
    data:
      entity_id: media_player.laptop_work_edge
      message: Auch ich grüße dich!
mode: single

You can obviously use any TTS service and any media_player.

Goal: I wanted to say something like

Hey Google, lass uns loslegen

or

Hey Google, aktiviere Hallo

The second example uses the name of the script. The first one a new unique command.

Confusion: After creating the script, I noticed a new entity showing up in the settings of

Configuration → Home Assistant Cloud → Google Assistant → Manage entities

Make sure this is marked in green to be synched to Google Assistant. Also note, that HA presents the script as a scene:

image

This confused me quite a bit. The Google Home app and Google Assistant don’t show scenes anymore. In the past, it seems that they were presented like other entities and that you could assign them to a home and rooms. This doesn’t seem to be the case anymore. Also, some posts here talk of shortcuts. This doesn’t exist in my Google apps either.

Solution: I assume, you have completed the basic setup of Nabu Case (or alternative) with Google Home already and your lights show up and work well.

To find the scene / script, I first had to sync HA with Google by clicking on “sync entities to Google” in the Home Assistant Cloud settings. Then go over to the Google Home app. In the top right corner there should be your profile pic. Select it and then choose “Assistant Settings”. You find a very long list of settings. Here you select Routines (in German: Abläufe). This presents you with some pre-configured generic routines.

On the top right there is a plus button to create a new routine. First, you have to “add a starter”. Select “voice command” and now you can come up with your new unique command, like in my example “lass uns loslegen”. Note: Google Assistant doesn’t like an exclamation mark or a question mark at the end. I first got stuck here just because of the extra punctuation and Google Assistant kept refusing to execute the command.

Next, you have to add an action. Clicking the button brings up all sorts of generic actions. Select “Control home devices” or (in German: Home-Geräte einstellen). Another list of options comes up and you would like to select “Control scenes” (in German: Ambiente steuern). Make sure to press the tiny arrow on the right to the a list of scenes. And finally, there you are. Here is the list of your HA scripts!

I’ve selected the script “Hallo” and then clicked the confirmation buttons all the way back to complete the setup.

Now you can call the script by saying:

Hey Google, lass uns loslegen

or whatever you typed in as a command. Google Assistant will silently do it. If that’s all too complicated, well the “Hallo” script also works by invoking it directly, saying:

Hey Google, activate Hallo

However, in that case, Google Assistant will respond and tell you that it understood and is now going to activate “Hallo”. I find this rather annoying.

Hope this helps you save some time.

27 Likes

Thank you for saving my time, and I can confirm that the process is pretty much the same and is still working in 2022.

4 Likes

Awesome instructions! I was having random success with integrating voice commands to Google for HA scripts.

Im new to this and basically just throwing a combo of Automations/Scenes/Scripts just to get one command to work. I got some to work and others seemed to conflict with googles pre defined “timers” and what not. This worked liked a charm, thanks!!

I added some Google TTS call services to some of my timer scripts just so i could get some feed back that its actually calling the right script.

Side note, i didnt go the Nabu casa but instead the manual way and it still worked.

TL’DR: Scripts are converted to Google “Scenes”, you can find them there

5 Likes

Thank you so much. :slight_smile:
I was trying to get my scripts running with Google Home App for days, but the tutorials I was following were not correct or at least not for the version I downloaded. This works pretty well!!

Ist there any possibility to find Out which speaker was used to process the voice command so we can use this in the Script for the tts Output?

Thank you for the details and as a side note I would mention that you can also create your Google routines from your computer using https://assistant.google.com/settings/routines.

1 Like

Thanks very much. I have a Swan Alexa kettle and had created a script in HA for it to boil, via Alexa media player by pressing kettle image and was trying to work how it get google to use it, now thanks to you can ask google to boil the kettle :slight_smile:

I have setup my own cloud integration using these instructions.

I could not find a list of scenes in Google Home app. When I press “Add action”, I don’t see “Control home devices”. The closest that I could find is “Adjust Home Devices”, but this option only lists devices registered with Google Home and nothing from Home Assistant. Definitely, no option like “Control scenes”.

Update: Found a workaround. I created a virtual switch and attached it to the script. One can turn it on to trigger the script and it will automatically turn off afterwards. Here is my config for the switch inside configuration.yaml:

switch:
  - platform: template
    switches:
      knock_my_socks_off:
        unique_id: knock_my_socks_off
        friendly_name: Knock my socks off
        value_template: "{{ false }}"
        turn_on:
          - service: script.knock_my_socks_off
        turn_off: []

script:
  knock_my_socks_off:
    alias: Knock my socks off
    sequence:
      - service: notify.mobile_app_pixel_8_pro
        data:
          message: Socks are off
    mode: restart

After restarting Home Assistant and asking Google Home to “sync my devices”, it shows up a switch in the “Linked to you” section in the device list in the Google Home app. To tie it to a custom phrase, one has to add the new switch to your home: long-press on the switch name in the device list, press gear icon in top-right, select “Home: Add to a home” and follow the prompts. After this, you should be able to create a routine/automation inside Google Home as described in the original post and choose turning on the switch as an action.

This is how routine in my Google Home app looks like:

I have successfully tested it: when I say “Ok Google, knock my socks off”, I receive “Socks are off” on my Pixel 8 Pro.

3 Likes

Did you ever found a way to solve this?