Today, I’m going to show you how to integrate Google Assistant with Home Assistant. So you can control all your Home Assistant entities using your voice from any Google Assistant enabled-speaker. And I’m going to show you how to do it for free.
Table of Contents
Ways to integrate Google Assistant
There are 2 ways that you can integrate Google Assistant with Home Assistant. The easiest way is to use the Home Assistant Cloud service. The Cloud service doesn’t only give you access to link Google Assistant but also Amazon Alexa. It also makes it easier to set up remote access for your Home Assistant instance. The cloud service is a subscription plan which costs $5 a month. It’s not a lot for all the benefits that you get. Also, to support the developers that made the Home Assistant project possible, I would recommend, if you can, to support them by subscribing to the Cloud service.
The other way to integrate Google Assistant, which is the method that we will set up today, is free, but it does require a lot more steps to configure. But like always, I’m going to make it simple for you guys, and I’m going to go over everything step-by-step.
Set up new project via Actions on Google
Before setting up everything, you need to have remote access configured in Home Assistant. If you haven’t done that yet, check out my Beginner's Guide to Home Assistant, where I show how to set up remote access using DuckDNS.
-
To create a new project via the Actions on Google website, go to console.actions.google.com.
-
Click on New Project, set up a name for it, and click on Create project.
-
Then, select Smart Home and click on Start Building.
-
Now that the project is created, under Quick setup, click on Name your Smart Home action and set up a name for it. This would be the name that you would look for when we get to the process of linking the Home Assistant instance to Google Assistant.
-
Click on Save, and then click on Actions.
-
Under Fulfillment URL, enter your full DuckDNS URL, including port
443
at the end and also/api/google_assistant
. -
Click on Save and then click on Account linking.
-
Under Client ID, you need to enter the following link,
[https://oauth-redirect.googleusercontent.com/r](https://oauth-redirect.googleusercontent.com/r/g-asst-integ-for-home-asst)
, including the project ID at the end. To locate your project ID, click on the Menu icon on the top right, and then click on Project settings. Depending on what you set up as the Project name, sometimes the Project ID could be different or have some extra characters at the end. So, you want to double-check this before you continue with the setup. -
To go back to the Account linking, click on Develop, and then enter the following under Client ID, including the Project ID at the end:
https://oauth-redirect.googleusercontent.com/r/your-project-id-here
-
For the Client secret, you can enter anything you would like. This is not a password that Home Assistant would need to link to Google Assistant.
-
For the Authorization URL, enter your DuckDNS URL and include at the end port
443
and also/auth/authorize
. -
And for the Token URL, enter the same link but replace
authorize
withtoken
at the end. -
Click on Next and under Use your app for account linking, click on Next as well without changing anything.
-
Now, under Configure your client, enter email under Scopes and then add another scope and set it to name.
-
Make sure that the option Google to transmit clientID and secret via HTTP basic auth header is unchecked.
-
Click on Next and then Save.
-
The configuration here is now done, so click on Test to activate the new action.
Create a service account in the Google Cloud API
Next, you need to go into the Google Cloud API website and create a service account. This would provide a file with some details that you would need to set up in Home Assistant. So you can sync any changes in the Home Assistant platform with the Google Assistant service.
- On another tab, go to https://console.cloud.google.com/apis.
- Click on Select a project and click on the project created via the Actions on Google website.
- Then, go into Credentials, click on Create Credentials, and select Service account.
- Set up a Name for this service, which would then be added as a service account ID. You can also add a description for this service if you would like. However, it’s not needed.
- Click on Create.
- Then, under Grant this service account access to project, click on the drop-down and select Service Accounts > Service Account Token Creator.
- Click on Continue and then click on Done.
Download the JSON file for the Service account
All right, so the Service account is now created. To download the file that we would need, go into:
- Manage service accounts.
- Then, click on the More options icon on the right side of the created service and click on Create key.
- On the pop up that comes up, click on
JSON
for the Key type. - Then click on Create.
Enable the HomeGraph API
Before setting the Google Assistant integration in Home Assistant, you need to enable the HomeGraph API in the Google Cloud Platform.
- Go to the sidebar, and under API & Services, click on Library.
- Then search for HomeGraph API, open it.
- Click on Enable.
Configure the Google Assistant integration in Home Assistant
We’re done with the configuration on the Google side. Which pretty much was the hard part. Next, you need to configure the Google Assistant integration in Home Assistant. You could add all the settings inside the Configuration.yaml file. However, to make everything nice and neat, create a separate file, and add the Google Assistant configuration in there.
- Using a code editor like VS Code, open the Home Assistant Config folder and create a file named, for example, google_assistant_integ.yaml.
- Then, open the configuration.yaml file and enter the following:
google_assistant: !include google_assistant_integ.yaml
- Save the changes to the configurarion.yaml file.
- Then, open the Google Assistant integration file and enter the following:
project_id:
service_account:
private_key:
client_email:
- Then open the JSON file, downloaded from the Google Cloud Platform.
- Copy the
project_id
, theprivate_key
, and theclient_email
and paste it into the Google Assistant integration file. - Next, enter
report_state:
and set it totrue
. Like that, Google Assistant is updated with any state changes in your Home Assistant entities. - Lastly, enter
exposed_domains:
and add the domains from Home Assistant that you would like to expose to Google Assistant.
report_state: true
exposed_domains:
- switch
- light
- sensor
- script
- At this point, we pretty much have the basic setup required, so save the file and then restart Home Assistant to apply the changes.
Link Home Assistant in the Google Home App
After the Google Assistant integration is configured, you need to Link Home Assistant in the Google Home app.
- Open the Google Home app on a mobile device and tap on the plus “+” icon on the top left.
- Then, tap on Set up device > Have something already set up?
- And then search for the name of the project you created via Actions on Google. Your project will show up with a cloud icon and the word [test] at the beginning.
- Tap on your project, and you should get the Home Assistant login screen.
- Sign in to your Home Assistant.
- When the linking is completed, another page comes up to assign your Home Assistant entities to rooms.
- When you finish, tap on Done and then Finish setup.
And that’s about it. Your Home Assistant entities are available now via Google Assistant, and you can easily control them with your voice.
Disable entities from being exposed to Google Assistant
If you have entities that you don’t want to control with Google Assistant, you can easily disable them, so they are not exposed. To do that, go back into the Google Assistant integration file.
- Add
entity_config:
- Enter the name of the entity that you would like to configure.
- Below it, type
expose:
and set it tofalse
. - When you are done, save the file, restart Home Assistant.
- Then from Google Assistant, run the command, “Hey Google! Sync my devices”. Google Assistant will then resync and apply the changes made in Home Assistant. You would then noticed that the device blocked from being exposed would be removed.
Other options that you can add to the entity_config is aliases, which you can use to add different aliases that will refer to a specific entity, and also room, which is used to specify the room that the entity belongs to. And then again, when you are finished editing the file, save it, restart Home Assistant and run the command via Google Assistant to sync the devices.
Reenable the Actions on Google Test environment
There is one important thing that I want to mention. The Actions on Google project that we created to make this possible is in a testing environment. So after 30 days, the test expires. However, you can still control your devices via Google Assistant with no problem. The part that you’re going to run into an issue is if you make changes to your home assistant, and you try to sync your devices in Google Assistant. You would get an error message that it was unable to sync with your Home Assistant project. The good news is that you can quickly fix that by reenabling the test simulation. To do that, go back to the Actions on Google website
- Open your project
- Then click on Develop
- Account linking
- And click on Test.
And that’s about it. When you run the command via Google Assistant to sync your devices, you won’t get an error message anymore, and any changes in your Home Assistant will sync with Google Assistant.