CLI for setting and enforcing nest thermostats.
The model of Nest we have doesn't support locking and this was cheaper than buying new ones.
NOTE: Get or use an existing gmail.com address for everything here. Do not use a Google Workspace domain for your Google Cloud, Nest Developer account or anything else associated with this coe. Google is a hassle and refuses to support Google Workspace domains for most consumer products.
Believe me, you will lose hours to this, and $5 to a Nest Developer account you'll never be able to use. Save the time.
Using a gmail address.
- Visit Google Nest Device Access Console
- Accept the terms and pay the one-time $5 fee
- Create a project (note your Project ID)
- Link your Google Account with Nest devices to this project
Logging in with a @gmail.com address:
- Visit Google Cloud Console
- Create a new project
- Enable the Smart Device Management API
- Go to APIs & Services > Credentials
- Click Create credentials > OAuth client ID
- Choose Desktop app
- Add
http://localhostas an authorized redirect URI - Save the generated Client ID and Client Secret
Logging in with a @gmail.com address thats part of your Google Home.
Construct a URL like this (replace values):
https://nestservices.google.com/partnerconnections/YOUR_PROJECT_ID/auth?client_id=YOUR_CLIENT_ID&redirect_uri=http://localhost&response_type=code&scope=https://www.googleapis.com/auth/sdm.service&access_type=offline&prompt=consent
Paste it in a browser, approve access, and capture the code=... from the URL you're redirected to.
curl -L -X POST 'https://oauth2.googleapis.com/token' \
-d client_id=YOUR_CLIENT_ID \
-d client_secret=YOUR_CLIENT_SECRET \
-d code=THE_CODE_YOU_COPIED \
-d grant_type=authorization_code \
-d redirect_uri=http://localhostSave the response into config.json:
{
"project_id": "enterprises/YOUR_PROJECT_ID",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"refresh_token": "YOUR_REFRESH_TOKEN"
}If you add a datadog_api_key to config.json, enforcement actions will be logged to your datadog account
Run this to see your devices and their names:
python nest_thermostat_control.py --config config.jsonYou’ll get output like:
[Bedroom Thermostat] Mode: COOL, Setpoint: 75.0°F
[Living Room Thermostat] Mode: OFF
...
Take note of the thermostat names you want to manage.
Now you can enforce minimum and/or maximum temperatures (in Fahrenheit) for selected devices:
python nest_thermostat_control.py \
--config config.json \
--enforce-min 70 \
--thermostats "Thermostat Name 1,Thermostat Name 2"- Only thermostats that are ON and in COOL mode are affected
- Others are left unchanged