Nest Thermostat Push Notifications

September 7, 2017 by Pat - Comments - 8 min read

Nest Push NotificationsI 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
Setting up a Nest Developers Account
Setting up IFTTT Webhooks
Installing the Notification Python script
Removing Everything


Download the script

Download the script on GitHub along with an empty database. The database is optional since the script will create a new database for you.


Nest Developers Account

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.

  1. Sign up for Nest Developers at https://developers.nest.com/
  2. Once you’re signed up and in the developers console, click Create New Product
  3. Enter a Product Name. Mine is simple: Home Thermostats
  4. Enter a description. I chose: “Get information on home thermostats for push notifications.”
  5. 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.
  6. Choose a category. I chose Home Automation and Sensors
  7. Under Users select Individual

Permissions

  1. Select Away and read v2. Enter description of “To know when house is set to away mode”
  2. Select Thermostat and read v6. Enter description of “To be able to see what mode the thermostat is in”

Click Create Product

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"

Replace AUTH_CODE with the pin you received
Replace CLIENT_ID with the Product ID from the Nest Developers App you just created
Replace CLIENT_SECRET with the Product Secret from the Nest App

You should get a reply back that says something like:

{"access_token":"c.ULQLf..................","expires_in":315360000}

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.


Setup IFTTT Webhooks

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.

  1. Log in, or create your IFTTT account.
  2. At the top click Search and type Webhooks and click it to open it
  3. Click Connect to enable the service and then click on Settings to view settings.
  4. Write down the URL. We need the portion after /use/

IFTTT Webhooks for Nest Push Notifications
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:

  1. Click My Applets and click New Applet.
  2. Click +This, and select Webhooks
  3. Click “Receive a Web Request”
  4. 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.
  5. Click Create Trigger
  6. Click +That
  7. Type Notification and select “Send a notification from the IFTTT app”
  8. In the Notification field, delete everything and type ``
  9. Click Create action
  10. Click Finish

Install the IFTTT app to your phones and tablets you’d like to receive notifications on.


Setup the Python script

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:

  1. Change the location of databaseFile to a place where you’d like to store your sqlite database. (e.g. /home/pi/nestapi/nestapi.sqlite)
  2. Change the iftttEventName to the name you gave the ifttt applet in step 4
  3. Change the iftttSecretKey to the line of text after the /use/ URL from earlier
  4. Lastly in the nestAPIURL change 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.

Run 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.


How do I remove all of this?

  1. To remove the IFTTT:
    1. Go to your Applets
    2. Click on the applet you created
    3. Click the settings or gear icon
    4. Select Delete.
  2. To remove the Webhooks service:
    1. Click Search at the top
    2. Type Webhooks
    3. Click on Webhooks and go to Settings
    4. Click Disconnect Webhooks
  3. To remove the Nest App:
    1. Log into your normal Nest account
    2. Click on your location at the top right and select Settings.
    3. Click on Works with Nest
    4. Click on the Nest application you created
    5. Choose Remove Connection.
  4. To remove the Nest Developer App:
    1. Log into your Nest Developers account
    2. Click on the Nest application you created.
    3. Click Edit and click Delete Product.

That’s it to remove everything.

Share this post:

About Pat

I'm a I.T. systems engineer by day and in my spare time I code. I've made WordPress websites and plugins, weewx extensions and static html sites using Jekyll. I'm a technologist at heart and I enjoy tinkering on many different technology projects. Here on my site you will find some of the projects I've worked on, and other random bits of knowledge that I hope help someone along the way.

mentions