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(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

What to do when you hit the throughput limits of Azure Storage (Blobs)

In this post we will talk about how we can detect when we hit a throughput limit of Azure Storage and what we can do in that moment. Context If we take a look on Scalability Targets of Azure Storage ( https://azure.microsoft.com/en-us/documentation/articles/storage-scalability-targets/ ) we will observe that the limits are prety high. But, based on our business logic we can end up at this limits. If you create a system that is hitted by a high number of device, you can hit easily the total number of requests rate that can be done on a Storage Account. This limits on Azure is 20.000 IOPS (entities or messages per second) where (and this is very important) the size of the request is 1KB. Normally, if you make a load tests where 20.000 clients will hit different blobs storages from the same Azure Storage Account, this limits can be reached. How we can detect this problem? From client, we can detect that this limits was reached based on the HTTP error code that is returned by HTTP