Google SDM Api - App and Drivers for Hubitat Elevation

Google Pre-requisite setup:

Follow the Get Started QuickStart from Google

Click on the blue "Enable the API and get an OAuth 2.0 Client ID" and follow the directions immediately above that blue button, with the following modification:

Enter https://cloud.hubitat.com/oauth/stateredirect as the value for Authorized redirect URIs

Go to the Cloud Pub/Sub API page, and enable the Pub/Sub API for your Google Cloud Platform (GCP) project.

Installation

SDM Api App

On the Apps Code page, press the New App button

Paste the code for sdm-api-app.groovy and press the Save button (or type Ctrl-S)

Press the OAuth button, then press Enable OAuth in App, then press the Update button.

Individual Device Drivers

On the Devices Code page, press the New Driver button

Paste the code for sdm-api-thermostat.groovy and save

Repeat this process for each of the device handlers you want to install.

Create the app

On the Apps page press the Add User App button then click on Google SDM API in the list of available apps.

Copy and paste the contents of your Oauth2 credentials.json file downloaded from GCP into the Google credentials.json input field

Copy and paste your Google Device Access project ID into the Google Device Access - Project ID input field for the Google SDM API app.

####NOTE: Don't forget to press the Done button to make sure the app sticks around!

Authorization and Discovery

On the Apps page, click the link to Google SDM API

Now that the previous steps are complete, you should now see a section: Auth Link - Click this link to authorize with your Google Device Access Project.

Click on this link, and walk through the steps to authorize with Google. When complete, you will be redirected back to a basic page provided by this HE app.

Click the specified link to return to the App configuration page. It will now display a Discover button

Press the Discover button on the Google SDM API app page to discover your authorized Nest devices.

Features

Camera images

The latest still image is downloaded when a device event is received (Doorbell, Camera, Display). This can be displayed in a HE dashboard using the attribute tile. Simply select the device, and the attribute to use is image.

Note: this currently only works for Local dashboards -- support for cloud dashboards coming in a future update.

Motion "sensor"

A "Motion" event from Google will trigger a motion Active event in HE. Since the current API does not send another event when motion is no longer detected, a preferences entry is defined for each device, which determines the amount of time before the motion is deemed Inactive. If another motion event is received before this timer expires, the Inactive transition is deferred for the specified interval.

"Presence sensor"

A "Person" event from Google will trigger a presence Present event in HE. A preferences entry determining the length of "presence" is defined as for motion above.

Sound "sensor"

A "Sound" event from Google will trigger a sound detected event in HE. A preferences entry determining the length of sound "detection" is defined as for motion above.

Doorbell Chime

The doorbell chime will generate a pushed event on button 1 for the device.

Any of these HE events can be used for Rule Machine or Notification triggers.

Debug buttons -- not required for normal operation -- but useful to retry actions that might have failed during setup, such as the event subscription

Log Access Token

This button will log your current Google access-token, so that you can use it to manually make calls to google for testing

Force token refresh

This button will trigger the App to refresh your Google access-token.

Subscribe to Events

This button will attempt to create the event subscription with Google pub/sub -- useful if this initially failed for any reason.
If a matching subscription already exists, it will log a 409 warning. If this occurs and you are not receiving events, it's possible that the existing subscription does not match the local state.accessToken which is being used by HE to authorize the incoming POST.

Delete event subscription

This button will delete the current Google pub/sub event subscription. If you need to use this button, immediately follow up with the above Subscribe to Events button to re-create your event stream.

Delete all devices

This button will delete all child devices from HE, which represent your physical Nest devices. Useful if you need/want to clean up and start over, without needing to re-authorize with Google. You can follow this up with the Discover button on the main App page to re-discover your devices.

Troubleshooting

Google Auth link/button not showing up

The App checks that all required prerequisites are present before revealing this button. This includes the following:

App Settings

  • Google Device Access - Project ID
  • Google credentials.json

Application State

  • accessToken -- this should be created automatically when the app is first installed

You can validate these entries by going to the App page in HE, then click on the settings gear icon in the top-right corner.