Skip to content

irabinovitch/nest-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nest Thermostat Control

CLI for setting and enforcing nest thermostats.

Why?

The model of Nest we have doesn't support locking and this was cheaper than buying new ones.

Setup Instructions

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.

1. Register for Device Access

Using a gmail address.

  1. Visit Google Nest Device Access Console
  2. Accept the terms and pay the one-time $5 fee
  3. Create a project (note your Project ID)
  4. Link your Google Account with Nest devices to this project

2. Set Up Google Cloud

Logging in with a @gmail.com address:

  1. Visit Google Cloud Console
  2. Create a new project
  3. Enable the Smart Device Management API
  4. Go to APIs & Services > Credentials
  5. Click Create credentials > OAuth client ID
    • Choose Desktop app
  6. Add http://localhost as an authorized redirect URI
  7. Save the generated Client ID and Client Secret

3. Link Your OAuth Client to the Nest Project

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.


4. Exchange the Code for Tokens

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://localhost

Save 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


💻 Usage

1. List All Thermostats

Run this to see your devices and their names:

python nest_thermostat_control.py --config config.json

You’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.


2. Enforce Temperature Limits

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors