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.
Comments
Post a Comment