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.

30 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?

Of course, since Google constantly make modifications to everything, the guide and instructions in this post is partly obsolete. Still, there’s enough in here to actually make things work.
I have a setup with Home Assistant OS running on the HA Yellow and connected to Nabu Casa with a proper subscription. Then I have a Google Nest Audio Speaker (the bigger brother of the Google Mini).
Connecting Home Assistant and the Google speaker is easy enough. You need to add the Google Cast Integration (unless you already have it). HA should autodetect compatible devices.
Then make sure your Google Speaker (whatever model you may have), is present as a Device.
Then set up the Google Assist configuration and enable Google Voice Assistant as explained here: Google Assistant configuration
Be aware that even those instructions are already outdated. It tells you to add a “Assistant Smart Home Skill” but the term skill isn’t used in Google Home anymore. Instead click on the settings coggle and choose Add a Service. Then under Works with Google choose the Home Assistant Cloud by Nabu Casa and complete the setup.
Then return to Home Assistant under Settings --> Voice Assistants you should now see your Google Assistant section:


Make sure the Expose new entities switch is turned off. If not everything you have in Home Assistant is automatically exposed to Google Assistant. You may not want that! It can cause total chaos unless you know exactly what you’re doing. Switches are often exposed as Lights and sometimes vice versa. Then if you (or someone else gives the command “Hi Google, Turn of all lights” then suddenly a lot more is turned off that you might have expected.
A much better approach is to add devices, entities and/or domains manually as you move forward, learning how to do these things. If you (like me) have a smartplug that controls power to Home Assistant itself, consider adding a Security Device PIN to it to prevent Home Assistant from unexpectingly shut it self down!

In this guide, we’re teaching Google Assistant how to run a Home Assistant Script. So, first make the script in Settings --> Automations & Scenes --> Scripts Perhaps just a simple script like this which will play back the Oslo Metro Radio Station on a Google Audio Nest speaker:

action: media_player.play_media
target:
  entity_id: media_player.my_speaker
data:
  media_content_id: media-source://radio_browser/7b1266f2-da4f-47a9-9f50-d689a8d64d3f
  media_content_type: audio/mpeg

The name for your speaker is obviously different from mine.
Remember to make the script something unique but at the same time logical and easy to remember. Don’t call it “Play Radio” or something similar as Google will almost certainly misunderstand it and instead playing some random Internet radio station.
Go back to Settings --> Voice Assistants and click on the Expose tab on the top of the screen and then click on :
image
You’ll be presented with a long list containing all entities available in Home Assistant, and you just have to start looking for your script entity. You can search for it using the name you gave your script. Click in the box followed by EXPOSE 1 ENTITY and your script automatically becomes exposed and available to Google. It is perhaps somewhat unlogical that a script is consider to be an entity, but for us, this is good. Notice that Automations are also available a selectable entities, but Google Assistant are so far not compatible with Home Assistant Automations.
Your script should now be visible in the list of exposed entities. Now you could add aliases to it, which in my opinion is a very good idea.
Finally you can test your new feature by ordring Google to run the script. You do that by saying “Hi Google, activate <script>” where <script> is replaced by the name you gave your script or by any of its aliases.
You can also manipulate how the script is accessed and used by opening Google Home App on your smartphone. Here’s how:
In Google Home, click on Automations and the big blue + button (sometimes also named +Add). Then choose whether to add a new automation for everyone in your household, or just yourself. New automations are by default named “Untitled”. click on the pencil and give it a unique new name (not previously used). Then click on Starters followed by the microphone icon which means “When I say to Google Assistant …” Then add a word, phrase or a whole sentence in the input box. Next, in the Actions part, add the custom command “Activate <script>” (replace <script> with the name of your script from Home Assistant).
You’ve now just created a second way to run the script through Google Assistant.
In my opinion, this way is sometimes better than the first one, and faster, since it doesn’t have to go through Home Assistant twice in order to fulfill the command.
Have fun.