The Home Assistant Beginner’s Guide Part 3: Integrating Home Assistant with the Google Assistant/Google Home

In this third part of the Home Assistant Beginner’s Guide we will be going through the steps on how to integrate your Home Assistant with the Google Assistant (and thus your Google Home, Google Nest Audio or Google Nest Mini). By the end of this guide you will be able to ask your Google Assistant to turn the lights on with a specific colour and manage most of your devices that have been added to your Home Assistant.

A Google Nest Audio integrated with Home Assistant
The Google Nest Audio
A Google Nest Mini integrated with Home Assistant
The Google Nest Mini

This guide will cover the Home Assistant integration with the Google Assistant without using Nabu Casa. Paying and using the service will make your integration much easier but as I already own the domain and run multiple services next to Home Assistant on my server, I went down the manual route. Paying the monthly subscription fee for Nabu Casa will support the further development of Home Assistant, so I am by no means discouraging you from doing so.

Be warned before you start this Home Assistant Beginner’s Guide: This is by far the most complex thing we’ve done so far. There’s a fair bit of ‘coding’ involved, and we’ll be working with more than one different tool. With that said, I’ll try to explain things in the simplest way possible. After all, this is a Beginner’s Guide!

Google Home and Google Assistant are two different things

Before starting off with the actual Home Assistant Beginner’s Guide we need to clear up a few misconceptions: When talking about Google Home (GH), Nest Audio or Nest Mini, I mean the hardware, the physical speaker that sits in your home. Google Assistant (GA) is the software that runs on that hardware. Many, including sometimes Google, use the two synonymously.

Google Home is now Nest Audio

Since writing this article, the Google Home line of devices have been replaced by Google Nest devices. Currently, these include the Nest Audio and Nest Mini. However, both still run the same Google Assistant as found on Google Home devices. I have updated this beginner’s guide to reflect these changes.

However, this integration will not just connect your smart speaker with Home Assistant. The Google Assistant runs on just about anything and its reach is increasing with almost daily. Anything from your phone to watches to security cameras and car dashboards run the Google Assistant. It’s just that Google Home was the first device that brought Google Assistant into our homes.

Requirements

There are two main requirements for the Google Assistant and Home Assistant integration:

  • The obvious one: You need a smartphone that can run the Google Home app. This can be an iOS or Android device. You do not need a Google Home, Google Nest or Nest Mini device for this integration to work, it just makes things more convenient.
  • The less obvious, but soon will become apparent, one: Your Home Assistant has to open to the internet. You can find out how to do that in the Home Assistant Beginner’s Guide Part 2.
  • This has already been pointed out in the first Beginner’s Guide but I’ll mention it again: Using an advanced text editor, such as Visual Studio Code will make editing files so much easier.
  • This guide was written for Windows users. I don’t have any Apple devices and as such couldn’t test any of the steps.

gactions CLI

First up, you’re going to want to download the gactions CLI. This is the command line interface used to test and update your integration.

Download the correct version for your OS (in most cases this will be x86_64) and copy the file into a new and empty folder. In the same folder create a text file and rename it project.json (make sure you have file name extensions in Windows Explorer enabled, otherwise you will end up with a file called project.json.txt).

Open the file with Visual Studio Code. Update and copy the following code into it (use the URL you previously created with Duck DNS):

Downloading the gactions CLI for the Home Assistant integration
{
  "actions": [{
    "name": "actions.devices",
    "deviceControl": {
    },
    "fulfillment": {
      "conversationName": "automation"
    }
  }],
  "conversations": {
    "automation":
    {
      "name": "automation",
      "url": "https://[YOUR HOME ASSISTANT URL]/api/google_assistant"
    }
  }
}

Creating a new project in Actions on Google

Go to the Actions on Google developer console and create a new project. Enter a suitable project name (I went for Home Assistant, how imaginative) and your country. Click on create project. You’ll be greeted with a new window containing many complicated sounding words. Don’t worry, I don’t understand any of it either. We’re only interested in the Actions SDK. Click on Build. Copy the code ($ gactions update…) and paste it into an empty notepad, we’re going to need that.

Setting up Actions on Google for Home Assistant
Setting up Actions on Google for Home Assistant
Setting up Actions on Google for Home Assistant
Setting up Actions on Google for Home Assistant

In the notepad, replace PACKAGE_NAME with project.json and replace the $ with ./ if you’re running Windows. This is what your code should look like on a Windows machine:

./gactions update --action_package project.json --PROJECT_NAME

Open the folder we created for the gactions CLI in the Windows Explorer, hold down shift and right-click anywhere inside the folder. You should see the option titled Open PowerShell window here in that right-click menu somewhere. Click on that.

Copy and paste the code from your notepad and paste it into the PowerShell window using CRTL+V. Hit the Enter/Return key on your keyboard to run the code.

Opening PowerShell from a folder

After running the code you will be prompted to visit a URL. Copy and paste that URL into a browser and allow Assistant CLI to view and manage your Actions on Google. You will receive a long string of code in return for the permission. Copy that code and paste it into the PowerShell window. After a short time a message containing a URL will be returned. Copy the URL in the message.

Updating the Google Assistant JSON in Windows Power Shell
Granting permissions to the Assistant CLI
The code needed for the Assistant CLI
The code in the Assistant CLI

Open the copied URL in a browser and fill in the required App information. Once again, it isn’t critical what you add but I always like to keep it relevant. Once Google is happy with the information you’ve given, click save. Don’t worry about entering private information, this Action will never be publicly released.

Actions on Google for Home Assistant
Account linking in Actions on Google

Click on the back arrow and select Account linking. Click on the Edit button. Fill in information (has to be added but isn’t essential). Click on Add in the following prompt. Select the following:

Grant type: Implicit
Integrating Home Assistant with the Google Assistant in the Actions Console

For the Client ID we’re going to create a long, randomly generated and secure string. Use something like the Random Password Generator for this and make sure to select the maximum length.

Save this string in a notepad, we’re going to need it later (I recommend you add the description Client ID too)! The Authorization URL is your Home Assistant URL with /api/google_assistant/auth added to it:

https://YOUR_HOME_ASSISTANT_URL.duckdns.org/api/google_assistant/auth
Adding the Home Assistant URL to Actions on Google

Add two scopes: One being name, the other one email. Following that, enter some random gibberish in the testing instructions and click save.

Adding scopes to Actions on Google

Finally, with all the information entered, click on TEST DRAFT.

Testing the draft Integration with Home Assistant on Google

With everything sorted out, click on the settings cog in the top-left corner and open the Project settings. Here you’ll find your Project ID. Copy it into your notepad (again, give it a description).

The Project ID for Home Assistant

Enabling HomeGraph API for Home Assistant

This is an optional step but is highly recommended. The HomeGraph API will allow you to ask your Google Assistant to “sync my devices”. That command will sync your Home Assistant devices with the Google Assistant each time you add a new one or change an existing one. To enable the HomeGraph API, follow these steps:

  1. Go to the Google Cloud Platform.
  2. Select your project and click on ENABLE.
  3. Once enabled click on MANAGE and select Credentials in the left-hand menu. Click on Create credentials and select API key.
  4. A new API key will appear in the list. Copy this key into your notepad.
Enabling the Google HomeGraph API
Credentials for the Google HomeGraph API

Home Assistant configuration

Keep your notepad handy and open up the configuration.yaml. You’re going to have to create yet another random string for your access_token. Add and edit the following code with your data:

google_assistant:
  project_id: ACTIONS_ON_GOOGLE_PROJECT_NAME
  client_id: CLIENT_ID_CREATED_DURING_SETUP
  access_token: RANDOM_STRING
  agent_user_id: EMAIL_ENTERED_DURING_SETUP
  api_key: HOMEGRAPH_API_KEY_CREATED_DURING_SETUP
  exposed_domains:
    - switch
    - light
    - group

Restart your Home Assistant from the Web UI and wait for it to restart.

Adding Home Assistant in the Google Home app

Open the Google Home app on your smartphone and navigate to Home control (you’ll find it in the menu). Click on the big + button to add new devices (in this case the home assistant). The project we have just created will located at the very top of the list and will have the prefix [test]. Add the device and all of your devices set up in Home Assistant will show up!

The Google Home App
Adding Home Assistant devices to the Google Assistant
Home Assistant devices in the Google Home app

About Liam Alexander Colman

Liam Alexander Colman has been using Home Assistant for various projects for quite some time. What started of with a Raspberry Pi quickly became three Raspberry Pis and eventually a full-blown server. I now use Unraid as my operating system and Home Assistant happily runs in a Docker container. My personal setup includes many Zigbee devices as well as integrations with existing products such as my Android TV box. Read on to find out more on how I got started with Home Assistant.

1 thought on “The Home Assistant Beginner’s Guide Part 3: Integrating Home Assistant with the Google Assistant/Google Home”

  1. On the Google Cloud Platform- Homegraph API- Create Credentiials I only get these options:
    OAuth Client ID
    Service Account
    Help Me Choose

    I do not see API Key.
    Am I doing something wrong?

    Reply

Leave a comment