Hacking the Nest Thermostat with a Beaglebone Black
My Nest thermostat is great, but it’s in a room of my house where the ambient temperature is all over the place. First off, the room tends to warm up quite a bit when the sun comes in. It’s also in the dining room on a wall that is within maybe three feet of the oven in my kitchen, and the light over my dining room table has 5 halogen bulbs that will also heat up the room considerably when turned on. All told, it tends to be a room that routinely gets warmer than the rest of the house, which results in the furnace not running, making the rest of the house colder than I want it.
This project takes a BeagleBone Black with a TMP36 Temperature Sensor to track the temperature in another room of my house, and turn up the thermostat when the temperature difference between rooms gets to be greater than 1° C (1.8° F). It will then turn it back down again when the temperature difference equalizes or the temperature in the second room gets warm enough. The BeagleBone Black is a small Linux computer, and for this project I left it running the default Ångström Linux. On the surface, the BeagleBone is a competitor to the more popular Raspberry Pi, but it also has many of the analog in/out capabilities of the Arduino, making it a nice combination of the two if you want to work with a full Linux operating system and analog sensors. As you can see in the picture, I’ve also added a 2.5A power supply, a lightweight case and a solderable proto cape. If you zoom in, you can see that I suck at soldering.
The source is all available here: https://github.com/tomgersic/beaglenest
The meat of this project is contained in beaglenest-client. The beaglenest-server script isn’t neaded at all, except to provide a web-accessible log of operations. If you don’t want that, you can just comment those bits out. It also uses Twilio to send me a text whenever it’s overriding the existing Nest target temperature, and when it resets back to the default so that I know when it’s being turned up. That can also be disabled if you just want the temperature sensing and Nest control.
This is all possible, in large part, due to the Unofficial Nest API on Node. The makers of Nest are working on a public developer API, but it’s not widely available right now. This “unofficial” library makes good use of the existing APIs being used behind the scenes by the thermostat and existing Nest apps that are already out there.
After logging in with nest.login, calling nest.fetchstatus returns a JSON document with all sorts of interesting things about your Nest thermostat. Among other things, you’ll find the current ambient temperature at the Nest (current_temperature) and the temperature the thermostat is set to (target_temperature). Using these, it’s possible to compare the Nest’s ambient temperature with the ambient temperature of another room, and update the target_temperature if the temperature difference between the two rooms has gotten to be greater than a threshold value (in my case, I’ve set this to be 1 degree Celsius). It will then eventually set the temperature back to the old target temperature when the temperature increases enough in the other room of the house.
My BeagleBone Black isn’t publicly accessible behind my home router’s firewall (and I don’t really want it to be), so I wanted to be able to monitor it’s activity while away. The beaglenest-server adds a simple logging API in Heroku using Express with a viewer that looks like this:
Since runaway temperature increases could get expensive, I decided to have the BeagleBone send me an SMS whenever it’s overriding the default temperature. Twilio provides an NPM that makes it really easy to do this.