I have 2 Nest thermostats in my house. They’re great! No doubt they have saved me money since the first day. The one thing that’s bothered me though is the lack of push notifications. Perhaps it’s overkill but I like to know what my thermostat is doing such as changing setpoint and operation mode.
One of my thermostats is in my hallway and it’ll go into Eco mode if I don’t walk by it frequently enough. Having a push notice tell me that it’s in Eco mode now will enable me to open the app and get it back to heating or cooling.
I couldn’t find a way to get these types of status notifications in the Nest app. The only notice they’ll send you is filter reminders. I could disable Eco mode, but it’s cool that it’s trying to save me money. Maybe I should walk by the thermostat more often? I’m too lazy, so let’s setup push notifications instead!
I’ve created this status notification method using Python, SQLite, IFTTT and a Nest Developers account. You’ll need somewhere to run this script. Linux is preferred and what this guide will be based on. A Raspberry Pi is perfect, but a virtual machine running Ubuntu or CentOS will work too.
Table of Contents:
Download the script here. You can view raw and paste it to a file. It’s also available on GitHub along with an empty database. The database is optional since the script will create a new database for you.
You’ll need a Nest developers account to get the status off your thermostats. Since we cannot access the thermostats directly on our LAN, we need to get information through the cloud and Nest’s API system.
- Sign up for Nest Developers at https://developers.nest.com/
- Once you’re signed up and in the developers console, click
Create New Product
- Enter a Product Name. Mine is simple:
- Enter a description. I chose: “Get information on home thermostats for push notifications.”
- Enter a support URL. I chose this domain. You can also use http://localhost if you don’t have a domain. This is mainly for public users who will use this application. In this case there are none -- it’s only you.
- Choose a category. I chose
- Under Users select
read v2. Enter description of “To know when house is set to away mode”
read v6. Enter description of “To be able to see what mode the thermostat is in”
Using your web browser open the
Authorization URL link. Read through the permissions we just defined to make sure they match and click Accept.
You’ll receive a PIN code on the next screen. Save that code so we can exchange it for a permanent code.
Log into your Linux server or Raspberry Pi and run this command on the terminal:
curl -X POST -d "code=AUTH_CODE&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=authorization_code" "https://api.home.nest.com/oauth2/access_token"
AUTH_CODE with the pin you received
CLIENT_ID with the Product ID from the Nest Developers App you just created
CLIENT_SECRET with the Product Secret from the Nest App
You should get a reply back that says something like:
If you see that line above, then you’re good! Save the portion that says
c.ULQf......... because that’s your permanent code.
If you don’t see a token that begins with
c., verify the curl command above has the right values and try again.
More Nest API information is here if you want to read up on it.
IFTTT is how I handle all of my notifications. It’s free, reliable, works great and has support for many platforms (mobile, desktop). There are other services out there, but I haven’t had much success with them and I don’t want to pay for premium services.
- Log in, or create your IFTTT account.
- At the top click Search and type
Webhooksand click it to open it
Connectto enable the service and then click on
Settingsto view settings.
- Write down the URL. We need the portion after /use/
Warning: clicking on Edit connection will cause the key to be changed and making the old key unusable.
Next we need to setup the applet:
- Click My Applets and click New Applet.
+This, and select Webhooks
- Click “Receive a Web Request”
- Give it a name like “notify” or “nest” or whatever you want. You can re-use this same Webhooks applet for other projects. So you can keep it generic if you’d like.
- Type Notification and select “Send a notification from the IFTTT app”
- In the Notification field, delete everything and type
Install the IFTTT app to your phones and tablets you’d like to receive notifications on.
Now that we have our services setup, time to setup the Python script.
If you haven’t yet, download the notification Python script
First make sure you have the Python requests module loaded. You can install via apt or via pip. Here’s apt:
sudo apt-get update sudo apt-get install python-requests
Then open the Python script in your favorite text editor and at the top of the file:
- Change the location of
databaseFileto a place where you’d like to store your sqlite database. (e.g. /home/pi/nestapi/nestapi.sqlite)
- Change the
iftttEventNameto the name you gave the ifttt applet in step 4
- Change the
iftttSecretKeyto the line of text after the /use/ URL from earlier
- Lastly in the
nestAPIURLchange the c.12345 text to the text you received from running the curl command earlier.
Feel free to check out the rest of the script, but you shouldn’t have to alter anything else.
Run the script by typing
python nestapi.py in terminal and see if you get any errors. The script should create the database on first run and populate the database with the information. You may also get some initial push notifications, too.
If you don’t have any errors then the final step is to add the script to the crontab so that it runs on a schedule to check your thermostats.
crontab -e and add:
# Nest API Minutely Thermostat Check * * * * * /usr/bin/python2 /home/pi/nestapi/nestapi.py >/dev/null 2>&1
Change the path of nestapi.py if necessary.
This will run the Python script every 60 seconds and get the thermostat details from the Nest Developers API. It compares it against the saved info in the database and if there’s a change to setpoint, or running state, you’ll get a push notice from the IFTTT App
There is an option to have streaming updates from Nest’s API so you get real-time thermostat updates. I did not attempt to figure that out because the state of my thermostat doesn’t change all that often and a check every 60 seconds is perfect.
- To remove the IFTTT:
- Go to your Applets
- Click on the applet you created
- Click the settings or gear icon
- Select Delete.
- To remove the Webhooks service:
- Click Search at the top
- Type Webhooks
- Click on Webhooks and go to Settings
- Click Disconnect Webhooks
- To remove the Nest App:
- Log into your normal Nest account
- Click on your location at the top right and select Settings.
- Click on Works with Nest
- Click on the Nest application you created
- Choose Remove Connection.
- To remove the Nest Developer App:
- Log into your Nest Developers account
- Click on the Nest application you created.
- Click Edit and click Delete Product.
That’s it to remove everything.