Build your own Nest — part 1.

I live in a cold, poorly-insulated apartment in San Francisco that I share with my wife and our 2 week old baby girl. We love our apartment but we don’t love our heating situation. The building was built with forced-air ducts that became too complicated for our landlord to maintain so he replaced these with in-wall electric heaters. Space heaters alone are illegal under SF rent board rules but if you install them into the wall, they pass for whatever reason. We’ve had to have our wall heaters on 24/7 for the past 2 weeks. There’s one in our living room that runs at 4.1KW and one in each of our bedrooms that run at 2KW. I used PG&E’s pricing bands to calculate this will cost $1700/month and our apartment is less than 1000 sqft.

The new child (and heating arrangements) only came home Xmas day — I need a solution fast!

If I lived in a modern apartment, I long ago would have bought a Nest and constantly fought my wife over the appropriate evening temperature setting (as I see those who have a Nest do). The Nest is only compatible with modern thermostat wiring and so I needed to find an alternative.

Measure the problem

My first goal was convincing my wife that it really wasn’t that cold in our apartment. Not just that but the temperature wasn’t dropping dangerously low during the night. A quick search popped-up the DHT22 temperature and humidity sensor. My original plan was to plug this into the GPIO pins on a Raspberry Pi but my wife (as an interior designer by trade) doesn’t allow such ‘monstrosities’ to litter the apartment. Whatever I built had to

  • Be as small and as elegant as possible
  • Be serverless (I’m not a huge serverless advocate yet but once this thing is built, I don’t want to tinker with it again should I switch out a box)
  • Be accessible anywhere, so we too can play that remote Nest game with my spouse

Earlier in 2015, I came across ESP8266. A small (not much larger than a quarter) Wi-Fi module with an integrated microcontroller. These can be purchased from $2 and runoff 3.3volts (you’ll likely spend more on the power transformer than the device itself). I opted for the ESP8266–12E dev board as it has a built-in 5v-3.3v regulator (easy to power from any micro-USB) and many more GPIOs which I can use for more input and outputs than just the DHT22 sensor.

Look how small and cute the ESP8266–12E is — version 1 is about 1/3 this size

As an ex-AWSer, I would love to use the new IoT services. However, AWS’ IoT service requires HTTPS and client certificates. These things are just too complex for the little ESP to handle by itself without frequent kernel panics. I tried numerous workarounds to this

  • Using AWS’ new API Gateway to bridge over to the IoT API. Alas, the API Gateway only exposes HTTPS
  • Using the AWS’ HMAC-SHA signing mechanism to publish to SNS and then Lambda over to IoT. However, I need to have an accurate iso8601 time (within 15 minutes) for a valid signing request. The challenge is to get my ESP to know an up to date time with every request. I wrote a Lambda function to give me an S3 resource for this (perhaps you can find more use for this).
  • Using AWS SDK for C but this won’t fit on the small ESP8266.

In the end I opted for a pre-signed URL over HTTP into AWS S3. This is one of the last bastions of non-HTTPS APIs into AWS and I truly hope they keep it.

In exploring for an alternative to the AWS HTTPS issue, I came across Thingspeak that allows me to use HTTP methods to update ‘channels’ and ‘fields’. Thingspeak doesn’t have built-in logic and I was being rate-limited but I kept a backup feed there as it offers some nice graphs.

Building the web front-end is an area I did get to better utilize AWS, especially with my goal to be serverless. S3 hosts the static content, IAM allows me to authenticate against the Facebook SDK (so only the wife and I can actually change the temperature) and Lambda helps me automatically determine the heater state. I hold the desired temperature and state of the heater in S3. I did consider porting this across to AWS’ IoT service, but I had already built the state logic in S3 and Lambda.

I’m also putting the temp change data into DynamoDB so I can develop a ‘learning’ service at a later date

Hardware run-through

Making this pretty will have to come in part 2

You can find the source-code for web front-end, back-end Lambda function and Arduino sketch at:-

I decided to go with the native Arduino SDK upload after playing around with NodeMCU for a while and it panicking on me a lot. This will also give me more flexibility with interrupts for extending the project later.

If I had modern thermostat wiring and a real heating system at home, I would just need to attach a 24volt relay to the existing wiring to trigger the heating system. I have simulated this with an LED that lights-up whenever the heater-state is ‘on’. Unfortunately for me, I do not have a regular 24volt thermostat so I must explore another method.

In part 2 I will be configuring the remote heater control and adding a local override pad to the sensor module.

Prettification can wait