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

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(...

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see...

Navigating Cloud Strategy after Azure Central US Region Outage

 Looking back, July 19, 2024, was challenging for customers using Microsoft Azure or Windows machines. Two major outages affected customers using CrowdStrike Falcon or Microsoft Azure computation resources in the Central US. These two outages affected many people and put many businesses on pause for a few hours or even days. The overlap of these two issues was a nightmare for travellers. In addition to blue screens in the airport terminals, they could not get additional information from the airport website, airline personnel, or the support line because they were affected by the outage in the Central US region or the CrowdStrike outage.   But what happened in reality? A faulty CrowdStrike update affected Windows computers globally, from airports and healthcare to small businesses, affecting over 8.5m computers. Even if the Falson Sensor software defect was identified and a fix deployed shortly after, the recovery took longer. In parallel with CrowdStrike, Microsoft provi...