The Nest binding integrates devices by [Nest](https://store.google.com/us/category/connected_home?) using the [Smart Device Management](https://developers.google.com/nest/device-access/api) (SDM) API.
To be able to use the SDM API it is required to first [register](https://developers.google.com/nest/device-access/registration) and pay a US$5 non-refundable registration fee.
To be able to use the SDM API it is required that you use a Google Account with your Nest devices.
To migrate to a Google account, follow the migration steps in the [Nest accounts FAQ](https://support.google.com/googlenest/answer/9297676?co=GENIE.Platform%3DiOS&hl=en&oco=0#accountmigration&accountmigration1&#accountmigration2&#accountmigration3&zippy=%2Chow-do-i-migrate-my-account)
These parameters configure which SDM project is accessed using the SDM API and configure the OAuth 2.0 client details used for accessing the project.
First a SDM project needs to be created and configured:
1. Register for device access by clicking the "Go to Device Access Console" button and follow the instructions on the [Device Access Registration](https://developers.google.com/nest/device-access/registration) page.
1. Create a new SDM project on the [Projects](https://console.nest.google.com/device-access/project-list) page
1. Give your project a name so it is easily recognizable
1. "Skip" entering the OAuth client ID for now
1. If you want to download camera images using the binding, it is required to "Enable" events.
Enabling events also allows for faster thermostat state updates.
The binding only uses events when the Pub/Sub configuration parameters of the Nest SDM Account Thing are also configured.
1. After clicking the "Create project" button, the SDM project details of the created project show
1. Copy and save the **Project ID** at the top of the page (e.g. `585de72e-968c-435c-b16a-31d1d3f76833`) somewhere
Now an OAuth 2.0 client is created and configured for using the SDM API by the binding:
1. Configure the "Publishing status" of your Google Cloud Platform to "Production" ([APIs & Services > OAuth consent screen](https://console.cloud.google.com/apis/credentials/consent)) so the OAuth 2.0 tokens do not expire after 2 weeks
1. Create a new client on the "Credentials" page ([APIs & Services > Credentials](https://console.cloud.google.com/apis/credentials)):
1. Click the "Create Credentials" button at the top of the page
1. Copy and save the generated **Client ID** (e.g. `1046297811237-3f5sj4ccfubit0fum027ral82jgffsd1.apps.googleusercontent.com`) and **Client Secret** (e.g. `726kcU-d1W4RXxEJA79oZ0oG`) somewhere
1. Configure the SDM project to use the created client:
1. Go the the SDM [Projects](https://console.nest.google.com/device-access/project-list) page
1. Click on your SDM Project to show its details
1. Scroll to "Project Info > OAuth client ID" and open the options menu (3 stacked dots) at the end of the line
1. Select the "Edit" option
1. Copy/paste the saved OAuth 2.0 Client ID here (e.g. `1046297811237-3f5sj4ccfubit0fum027ral82jgffsd1.apps.googleusercontent.com`)
1. Click the "Save" button at the end of the line to update the project
Finally, an SDM Account Thing can be created to access the SDM project using the SDM API with the created client:
1. Create a new "Nest SDM Account" Thing in openHAB
1. Copy/paste the saved SDM **Project ID** to SDM group parameter in the SDM Account Thing configuration parameters (e.g. `585de72e-968c-435c-b16a-31d1d3f76833`)
1. Copy/paste the saved OAuth 2.0 **Client ID** to SDM group parameter (e.g. `1046297811237-3f5sj4ccfubit0fum027ral82jgffsd1.apps.googleusercontent.com`)
1. Copy/paste the saved OAuth 2.0 **Client Secret** to SDM group parameter (e.g. `726kcU-d1W4RXxEJA79oZ0oG`)
1. Create an authorization code for the binding:
1. Replace the **Project ID** and **Client ID** in the URL below with your SDM Project ID and SDM OAuth 2.0 Client ID and open the URL in a new browser tab:
1. After your browser has been redirected to <https://www.google.com>, the **Authorization Code** will be set in the browser URL as value of the "code" URL query parameter
Next click the "Enable" button on the [Smart Device Management API](https://console.cloud.google.com/apis/library/smartdevicemanagement.googleapis.com) page for your GCP project to enable the SDM API.
Now it should also be possible to use the configured account to discover your Nest devices via the Inbox.
You can monitor the SDM API using the Google Cloud Platform Console via [API & Services > Smart Device Management API](https://console.cloud.google.com/apis/api/smartdevicemanagement.googleapis.com/overview).
If you've made it this far, it should be easy to edit the SDM Account Thing again and update it so it can also use SDM Pub/Sub events. :-)
### Pub/Sub Configuration Parameters
After configuring the SDM configuration parameters, a SDM Account Thing can be updated so it can listen to SDM events using Pub/Sub.
This is required if you want to download camera images using the binding or to get faster thermostat state updates.
Enable Pub/Sub events in your SDM project:
1. Open your SDM project details using the [Projects](https://console.nest.google.com/device-access/project-list) page
1. Scroll to "Project Info > Pub/Sub topic" and check if it is set to "Enabled"
1. If it is set to "Disabled", enable events:
1. Open the options menu (3 stacked dots) at the end of the line
1. Select the "Edit" option
1. Check the "Enable events" option
1. Click the "Save" button at the end of the line to update the project
Lookup your Google Cloud Platform (GCP) Project ID:
1. Open the [IAM & Admin > Settings](https://console.cloud.google.com/iam-admin/settings)
1. Copy and save the GCP **Project ID** (e.g. `openhab-12345`)
Next an OAuth 2.0 client is created which is used to create a Pub/Sub subscription for listening to SDM events by the binding:
1. Open the "Credentials" page ([APIs & Services > Credentials](https://console.cloud.google.com/apis/credentials)):
1. Click the "Create Credentials" button at the top of the page
1. Copy and save the generated **Client ID** (e.g. `1046297811237-lg27h26kln6r1nbg54jpg6nfjg6h4b3n.apps.googleusercontent.com`) and **Client Secret** (e.g. `1-k78-XcHhp_gdZF-I6JaIHp`) somewhere
Finally, the existing SDM Account Thing can be updated so it can subscribe to SDM events:
1. Open the configuration details of your existing "Nest SDM Account" Thing in openHAB
1. Copy/paste the saved GCP **Project ID** to Pub/Sub group parameter (e.g. `openhab-123`)
1. Enter a name in **Subscription ID** that uniquely identifies the Pub/Sub subscription used by the binding
> Must be 3-255 characters, start with a letter, and contain only the following characters: letters, numbers, dashes (-), periods (.), underscores (_), tildes (~), percents (%) or plus signs (+). Cannot start with goog.
1. Copy/paste the saved OAuth 2.0 **Client ID** to Pub/Sub group parameter (e.g. `1046297811237-lg27h26kln6r1nbg54jpg6nfjg6h4b3n.apps.googleusercontent.com`)
1. Copy/paste the saved OAuth 2.0 **Client Secret** to Pub/Sub group parameter (e.g. `1-k78-XcHhp_gdZF-I6JaIHp`)
1. Create an authorization code for the binding:
1. Replace the **Client ID** in the URL below with your Pub/Sub OAuth 2.0 Client ID and open the URL in a new browser tab:
1. After your browser has been redirected to <https://www.google.com>, the **Authorization Code** will be set in the browser URL as value of the "code" URL query parameter
The SDM Account Thing should now be ONLINE and have as status description "Using periodic refresh and Pub/Sub".
The created subscription can also be monitored using the Google Cloud Platform Console via [Pub/Sub > Subscriptions](https://console.cloud.google.com/cloudpubsub/subscription/list).
| ambient_humidity | Number:Dimensionless | Lists the current ambient humidity percentage from the thermostat | R |
| ambient_temperature | Number:Temperature | Lists the current ambient temperature from the thermostat | R |
| current_eco_mode | String | Lists the current eco mode from the thermostat (OFF, MANUAL_ECO) | R/W |
| current_mode | String | Lists the current mode from the thermostat (OFF, HEAT, COOL, HEATCOOL) | R/W |
| fan_timer_mode | Switch | Lists the current fan timer mode | R/W |
| fan_timer_timeout | DateTime | Timestamp at which timer mode turns OFF | R/W |
| hvac_status | String | Provides the thermostat HVAC Status (OFF, HEATING, COOLING) | R |
| maximum_temperature | Number:Temperature | Lists the maximum temperature setting from the thermostat | R/W |
| minimum_temperature | Number:Temperature | Lists the target temperature setting from the thermostat | R/W |
| target_temperature | Number:Temperature | Lists the target temperature setting from the thermostat | R/W |
| temperature_cool | Number:Temperature | Lists the heat temperature Setting from the thermostat | R |
| temperature_heat | Number:Temperature | Lists the heat temperature setting from the thermostat | R |
The `fan_timer_mode` channel has a `fanTimerDuration` configuration parameter that can be used for configuring how long the fan is ON before it is switched OFF (1s to 43200s).
Similarly, when a DateTime command is sent to the `fan_timer_timeout` channel, the fan timer is switched ON and runs until the timestamp in the command (min now+1s, max now+43200s).