Skip to main content

How to get access to Google Nest devices using the new API (Google Developers)

 I started a Home Automation project where I divided to replace the custom gateway with Home Assistance. Developing my current IoT platform involves much time and custom development for each device requires too much effort. Because of this, I plan to use Home Assistance as the main hub, combined with Samsung Smartthings Hub for Zigbee and Z-wave integration and Azure Functions. But, this topic is for another article. 

Let's talk now about the Google Developers platform and how to get access to your Nest devices. Google decided to retire the old Nest platform and integrate Nest devices inside Google Home, where Google Nest is now supported.

In the long term, the decision is a smart one because under the same API we can get access to all current and future devices. In the meantime we need to move to the new API and getting access to it is not so easy as we think, even it is well documented. 

To get access to the Google Developer platform you need to pay a small fee (~5$) and be ready to play with Postman if you want to put your hand on the OAuth tokens that are required to access the API. Each step required can be found here - https://developers.google.com/nest/device-access/get-started



Below you can find some tips and tricks for each step:

1. Get Started

1.1. Register for Device Access

You don't need to be an organization, you can use the API for non-commercial use without any reviews from Google. 

1.2. Activate a supported device

-

1.3. Set up Google Cloud Platform

You need to create a project in the Device Access platform before it. At this moment in time, you are able to create only one - https://console.nest.google.com/device-access/project-list 

1.4 Create a Device Access project

Later on, you will need the project ID (UUID). If you forget it or lose you you can go anytime in the project sandbox and copy/paste it using the following link - https://console.nest.google.com/device-access

2. Authorize an Account

2.1. Link your account

At this step, you need to create an OAuth 2.0 Client from API&Services - https://console.developers.google.com/apis/credentials. In most cases, the type of application that you need to create is a Web application. Once you create it, navigate to the OAuth App that you created and ensure that you add 'https://www.google.com/' to the  'Authorised redirect URIs' section. 

The OAuth client ID that you need to specify it is similar with an URL (e.g. 424242dwefdw3f34fwdwd32d23d32.apps.googleusercontent.com/)  and can be copied from the device access projects that you created at step 1.4. 

Once you add the OAuth Client ID and project ID to the URL you can run it inside your browser.

https://nestservices.google.com/partnerconnections/project-id/auth?
redirect_uri=https://www.google.com&
access_type=offline&
prompt=consent&
client_id=oauth2-client-id&
response_type=code&
scope=https://www.googleapis.com/auth/sdm.service

Once you finish the flow, you are redirected to google.com where inside the URL you can find your authorization code. 

https://www.google.com/?code=authorization_code&scope=https://www.googleapis.com/auth/sdm.service

Store the authorization_code because you will need later on.

2.2.Get an access token

During this step, you need to get the access and refresh token. I was not able to run the POST on my local machine using CURL, but I have done this with success using Postman. I recommend using Postman if you have issues at this step.

The POST that I executed from Postman looks as followed

- https://www.googleapis.com/oauth2/v4/token?client_id=[clientID].apps.googleusercontent.com&client_secret=[clientSecret]&code=[code]&grant_type=authorization_code&redirect_uri=https://www.google.com

Save the JSON that was returned because contains the access and refresh token. 

2.3. Make a device list call

You need to run this step to ensure that you activate the access and refresh tokens. From Postman you can run the GET command 

https://smartdevicemanagement.googleapis.com/v1/enterprises/[projectId]/devices

where you set inside the heather:

  • Content-Type as 'application/json'
  • Authorization as 'Bearer [accessToken]', that you got at step 2.3. 
If you get the list of devices in JSON you are done!


Enjoy playing around with the API.


Comments

Popular posts from this blog

How to audit an Azure Cosmos DB

In this post, we will talk about how we can audit an Azure Cosmos DB database. Before jumping into the problem let us define the business requirement: As an Administrator I want to be able to audit all changes that were done to specific collection inside my Azure Cosmos DB. The requirement is simple, but can be a little tricky to implement fully. First of all when you are using Azure Cosmos DB or any other storage solution there are 99% odds that you’ll have more than one system that writes data to it. This means that you have or not have control on the systems that are doing any create/update/delete operations. Solution 1: Diagnostic Logs Cosmos DB allows us activate diagnostics logs and stream the output a storage account for achieving to other systems like Event Hub or Log Analytics. This would allow us to have information related to who, when, what, response code and how the access operation to our Cosmos DB was done. Beside this there is a field that specifies what was th...

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills)

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills) The idea that moving to the cloud reduces the costs is a common misconception. The cloud infrastructure provides flexibility, scalability, and better CAPEX, but it does not guarantee lower costs without proper optimisation and management of the cloud services and infrastructure. Idle and unused resources, overprovisioning, oversize databases, and unnecessary data transfer can increase running costs. The regional pricing mode, multi-cloud complexity, and cost variety add extra complexity to the cost function. Cloud adoption without a cost governance strategy can result in unexpected expenses. Improper usage, combined with a pay-as-you-go model, can result in a nightmare for business stakeholders who cannot track and manage the monthly costs. Cloud-native services such as AI services, managed databases, and analytics platforms are powerful, provide out-of-the-shelve capabilities, and increase business agility and innovation. H...

Cloud Myths: Migrating to the cloud is quick and easy (Pill 2 of 5 / Cloud Pills)

The idea that migration to the cloud is simple, straightforward and rapid is a wrong assumption. It’s a common misconception of business stakeholders that generates delays, budget overruns and technical dept. A migration requires laborious planning, technical expertise and a rigorous process.  Migrations, especially cloud migrations, are not one-size-fits-all journeys. One of the most critical steps is under evaluation, under budget and under consideration. The evaluation phase, where existing infrastructure, applications, database, network and the end-to-end estate are evaluated and mapped to a cloud strategy, is crucial to ensure the success of cloud migration. Additional factors such as security, compliance, and system dependencies increase the complexity of cloud migration.  A misconception regarding lift-and-shits is that they are fast and cheap. Moving applications to the cloud without changes does not provide the capability to optimise costs and performance, leading to ...