Using Home Assistant SDM Nest Integration


As you might know, Google has shut down the Works with Nest program since the 31st of August 2019. Since then there was no official way to integrate Nest products with Home Assistant. Lets not talk about how bad of a decision I find this by Google, but lets look forward! There was integration known as badnest which was based on Google’s own Web API. But this integration was unstable, and required reauthenticating every once in a while. Luckily there is now a new integration available for Home Assistant that uses the Google SDM (Smart device Management) API. This integration is available since version 0.118.0 of Home Assistant so make sure you are running this version before trying any of the steps below.

Setting up the new integration requires quite a few steps, and if not done correctly it can be hard to troubleshoot. In this article I will guide you through all the required steps, and some of the common errors that may be seen. I also had a lot of trouble getting this integration to work in the first days. I want to thank Alan Porter for creating this integration.

Google Device Access Registration

The first major step that we need to take is to register at Google using the Device Access Registration. This will give us access to the Google Smart Device Management API. I have created screenshots of this process which are hopefully helpful.

  1. First go the the Device Access Registration page. Click on the the button Go to the Device Access Console.

  2. Accept the Terms of Service.

  3. Next up, Google will ask you to pay a fee of $5, to get access to the SDM api. Ridiculous? Yes if you ask me, but there is no way around this.

    Important note: do this with the account that has access to your Nest devices.
  4. Once you have paid, you should have the Google Device Access console visible. Click on Create project.

  5. Give your project a name.


  6. Google will ask you for an OAuth client ID, I recommend that you create this first before continuing. To create an OAuth client id follow the next steps. Or skip now and create an OAuth client ID later.
  7. To create an OAuth client ID first visit the Google Developer console (open this in a new tab)
  8. From the Google Developer Console click on Credentials and click on CREATE CREDENTIALS

  9. From the drop down list select OAuth Client ID.


  10. Pick a name for your credential, and make sure you set the Redirect URL. This redirect URL needs to be externally accessible. I recommend that you use Nabu Casa (Home Assistant Cloud) for this. Your URL should be in the following format:

    https://<some id>.ui.nabu.casa/auth/external/callback


    You can also use your own URL, as long as it is reachable from the outside.
  11. You should now be presented with an OAuth client created message. Take note of the OAuth Client ID and OAuth Client Secret. We need both later for our configuration.

  12. Now head back to your Google Device Registration screen, and enter the OAuth Client ID.


    Click Next.
  13. Next make sure you enable Events, by click on Enable.

  14. You are done, take note of the Project ID.

If you followed along you should have the following information:

Project ID
OAtuh Client ID
OAuth Client Secret

These are three of the four configuration parameters that are required for the new Nest Integration. Next up we need to create a Pub/Sub subscriber to follow the SDM API Event. Follow the steps for this in the next paragraph.

Create a Pub/Sub subcriber for SDM

We already enabled Events previously. Now we need to enable the Pub/Sub API and create a Pub/Sub subscription. To do this follow the steps below:

  1. Enable the Cloud Pub/Sub API using this link. This is easy just click on Enable.
  2. From the Google Cloud Platform console we are going to create a Pub/Sub subscription. Here is a direct link.
  3. Now within the Google Cloud Platform console, click on CREATE SUBSCRIPTION.
  4. Enter the following settings:
    – Subscription ID: I used the same name as my project.
    – Subscription topic: select enter manually and enter the topic from the Device Access Registration console. You can get the topic by going into the project and copy the Pub/Sub topic. As shown below.



    – Select Pull as a subscription type.
    – Leave the rest default and click on CREATE.

  5. Once created take note of the Subscription name. We need this for our configuration.

At the end of these steps you should have the subscription name which is the subscriber_id in the configuration of the Nest integration. This name should be in the format: projects/…/subscriptions/SUBSCRIBER_ID Go back if you do not have this ID.

Nest integration configuration

We can now configure the Nest integration using configuration.yaml. Enter the following configuration details using the configuration parameters that we noted earlier:

nest:
  client_id: CLIENT_ID
  client_secret: CLIENT_SECRET
  project_id: PROJECT_ID 
  subscriber_id: projects/.../subscriptions/SUBSCRIBER_ID 

Run a configuration check, and restart Home Assistant.

Now you can add our Google Nest devices by following the steps below:

  1. First, and this is really important. Make sure you do the configuration from your external URL. For example I use the Nabu Casa remote UI URL https://<id>.ui.nabu.casa/. This is very important, otherwise you will get a 400 invalid request error.
  2. From the Home Assistant UI navigate to Configuration then Integrations. Under Add integration (bottom right) locate Nest.
  3. You should now be pointed to a Google login page. Login here.
  4. Next you will be prompted with the following screen:



    It is ok if you see that the integration is not tested and approved by Google. Click on Next.
  5. Next you will see two more screens asking for permission. Allow those permissions.


  6. Next up you will see a confirmation screen. Confirm permanent access to your Google Nest devices.

If all went well, your Nest integration is ready!

Common errors

During the setup of this integration I ran into several errors myself. I have listed the most common errors as I have seen them on the Home Assistant community. If you run into different errors please let me know, I will update the guide accordingly.

Error 400: invalid_request / authorization error

This error is seen during authorization of the integration. This is due to the fact that you are not connecting from the external URL. Make sure you connect on your external URL and not the internal URL. Here is an example of this error message (in dutch):

Optional: configure access to the Smart Device Management API

Some users have reported that access to the Smart Device Management API is not always given automatically. Usually when this happens you will see log items like this in the Home Assistant log:

aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://smartdevicemanageme…[my project_id]/structures')

You need to follow a few steps to fix this:

  1. Go the Google API management page.
  2. Click on Enable API and services

  3. Search for Smart Device Management. And enable the API.

It will take some time for the integration to pick this change up. Alternatively you can restart Home Assistant.

Data not updating

Something else I ran into was the data not updating in Home Assistant. This is due to a bad subscription ID in the configuration. Make sure you copy the entire subscription name in the format projects/..../suubscriptions/subscription-id

You can easily check if the subscription is updating by looking at the unacked message count from the Google Cloud Platform console.

This is what the unacked message count should look like. If you see a high number here, please go through the steps once again.

Conclusion and wrap-up

In this article we took a look at the new Google Nest integration for Home Assistant. It is great to finally have a good working and official integration back into Home Assistant. The setup of the integration is quite difficult and I hope this guide helps you to set this up.

Unfortunately Google does not provide access to Nest protect devices yet, but lets hope that they will offer this through the same API in the future. Right now I am very happy to have full Nest integration of my thermostat back into my Home Assistant setup.

Maarten

Hi, I am Maarten and I am the owner of this weblog. I post on various IT subjects that matter in my life as an IT professional.

Recent Posts