2/21/15

Nest ControlBot


A couple of months ago I bought my first Nest thermostats. The idea of them learning about and adapting to my family's temperature preferences sounded very appealing.

The Nest thermostat we setup downstairs works perfectly because the ambient temperature it senses and learns about is the temperature we care about.

But the upstairs Nest thermostat is located in the hallway where there are no vents. Due to this the temperature Nest aims to get to is not necessarily the appropriate desired temperature. This results in Nest trying to get to 73 but the temperature in my daughter's room reaching 80. We of course had the same problem with our old thermostat, but I was hoping for a more intelligent solution with Nest, like remote sensors that reported its temperature back.

The Wally integration with Nest attempts to solve this problem, but it unfortunately did not work
for my use case. The details of my issues are here: https://community.nest.com/message/45215#45215. My daughter's room still ended up reaching high temperatures because of Wally's reporting structure and also due to the tendency of her room to heat up very quickly. I am sure Wally+Nest works fine for the majority of users, but I required more customizability and transparency.

I needed a solution that would do the following:
  • A way to control the frequency that temperature is reported from the sensor.
  • A way to specify a range to prevent too frequent furnace activity. 
          Eg: Specify target temperature of 71 and a range of 1. This means that the heat turns on only when the temperature is 70 and stays on till temperature is more than 71. If the range is 2 then the heat should turn on at 69 and stay on till temperature is more than 71.
  • A way to specify different schedules. Each schedule should contain the start time, end time, target temperature and the temperature range.

The following is my solution. It addressed all my issues mentioned above.

Hardware Prerequisites

Assemble both using these instructions.

Code


I wrote a bot that runs continuously and checks a specified schedules file. If the current time falls in the range specified in the schedules file then it starts communicating with Nest to achieve the desired room temperature. The code also accounts for intermittent lapses in internet connections by retrying requests.
It is written in Python, I would have preferred to write it in Golang, but Python seemed easier to quickly setup on the Raspberry Pi.

It uses the following high-level algorithm (if you need to heat, cooling would be the opposite of the below):


If room_temperature is less than the (target_temperature - specified_range):
    set Nest to one degree more than Nest's ambient temperature so that it turns on.
else:
    set Nest to one degree less than Nest's ambient temperature so that it does not turn on.


Limitations:
* Does not handle overlapping schedules. The first schedule it sees in the range is the one it uses.
* Does not work with multiple temperature sensors. This would be simple to fix if needed.

I put the bot code on GitHub. Documentation is here.

I also created a mobile-friendly Google App Engine webapp that displays the target temperature and the current room temperature. It also contains a button to start/stop the bot. I restricted access to it to only mine and my wife's email addresses.
The webapp code is also on GitHub. Here is a screenshot of the page from my phone:

Finished Unit

DS18B20 hooked up to the breadboard


The complete setup


Placed in a cardboard case


Temperature sensor in the middle of the shelf



I have had this running for a few weeks now and it has definitely solved my family's problems. My daughter's room has been consistently in the 69-72 range. With her room being less stuffy it has resulted in better sleep for her, her brother and their parents.



2 comments:

Unknown said...

This is a fantastic idea. I was just searching for remote sensors for the Nest to solve the same problem. Separately, I had been trying to figure out what to do with the nifty Raspberry Pi I recently ordered. I look forward to trying this. Thanks.

Ravi said...

Thanks Russ. Let me know if you run into any trouble.