This Instructable explains how I built WiFi enabled thermostats for my home. The thermostats are programmable with 6 different time periods during the day, although increasing that to any arbitrary number would be fairly trivial. They can be programmed (in the sense of setting times and temperatures) as well as controlled over the internet, and they have a touchscreen LCD display for local control as well. And, I spent (and continue to spend) a fair amount of time trying to get them to look decent; after all, this is something that hangs on my wall, and I and my family will be seeing it every day.

One obvious question is “why would anyone want to do this when there are plenty of WiFi-enabled thermostats for sale commercially?” One possible answer would be to save money. But, while it is true that these might cost less to build than some commercial models, once you factor in your time, this becomes a bad answer! Better answers would be to have fun doing it (I did), or to build a thermostat that you can program to run and interact with other devices in any way desired. I built these as part of a larger home energy management system, and perhaps I'll post another Instructable on that later. And as a bonus: the hub for the thermostats is ready to go as a hub for a complete home automation system!

A second obvious question is what sort of formal qualifications or relevant experience do I have in this area, and the answer is absolutely none – no background with HVAC systems, no background in programming, no background in electronics. So, if you decide to build your own thermostats, you should NOT just blindly copy exactly what I have here and hook it up to your wall. This project requires precise, analytic thinking, and you must understand the type of HVAC system you have, review and modify all code and circuits as appropriate, and make sure you understand what you're doing and the consequences of getting it wrong. Failure to do so could destroy your HVAC system, electrocute your loved ones, or burn down your house. Seriously! I certainly welcome feedback from anyone who does have knowledge in these areas as to how I could make these thermostats better.

And of course, I could not have done this without all of the hard work from the folks who created the various libraries used, the people who took the time to put information out on the web in Instructables, forums, and blogs, and the many people who helped me out with advice and answers to my questions. Special thanks to Mark Pendrith who was especially helpful and gave me the code that forms the foundation of the arduino sketch.

Finally, in the process of modifying files to work with just the thermostats (as opposed to the larger home energy management system) as well as remembering everything I did over time to get this to work, there will undoubtedly be some errors in here. Please let me know if you catch any and I'll try to get them corrected as quickly as possible.

With all of that out of the way, here's what I did:

The system uses a Raspberry Pi as a central hub that serves web pages so I can control the thermostats from anywhere. The hub also handles all of the wireless communication over nRF24L01+ radio modules (I know I said “WiFi,” and the nRF24L01+ radio module isn't technically WiFi, but more on that later), and maintains a MySQL database with the thermostat programming as well as any data logging I do. And finally, the hub runs two servers written in Python – one controls the thermostat (as an intermediary between the web-page and the thermostat) and the other handles data logging. I believe this could probably be done with the thermostats each serving its own simple web-page and sending data directly to the MySQL database. This would eliminate the need for the lighttpd web-server and the two python servers. But, I feel like doing this on the hub does provide the simplicity of a single web-site, and the python servers provide a lot of flexibility. Plus I don't have to update the code on the thermostats whenever I want to make changes to these aspects.

If you really dig into this, you'll probably wonder why I bother with a MySQL database instead of just writing a little data to a text file when necessary. The primary answer is that I need the MySQL database for other parts of my system, but if all I had were the thermostats, it might be fairly easy just to eliminate the database and replace it with text files.

So, the communication flow essentially works as follows.

User Updates on Web-site

A user controls or programs a thermostat on a web-site written in PHP (mostly, a little javascript).

That web-site saves any changes to the MySQL database, and sends an instruction to the python control server.

The python control server interprets those instructions, updates an internal representation of the thermostat, and sends the appropriate instructions to the physical thermostat over the RFX network.

User Updates at Thermostat

A user controls a thermostat using the touchscreen controls.

The thermostat sends the changes to the python control server.

The python control server updates an internal representation of the thermostat and saves any changes to the MySQL database.

Thermostat has data to log or messages to save

The thermostat sends data or a message to log to the python data logging server.

The data logging server either saves that data to the MySQL database or to a log file based on the type of message.

Thermostat Temperature Automatically Changed according to a Set Program

The python control server monitors the program set for the thermostat and determines when the set temperature should change.

The python control server updates an internal representation of the thermostat and sends the new set temperature to the thermostat.

So, with that overview behind us, below are details on how I set this up. The first step lists the supplies and tools I used. The next several steps of the Instructable cover how I set up the hardware and software infrastructure for the hub. Most of these will include instructions by reference – there are plenty of places to get great information on how, for example, to set up a MySQL database on a Raspberry Pi, so I don't try to replicate that. Then, when the infrastructure is in place, I give considerably more detail on how I built the actual thermostats as well as the code I use to control them.

Step 1: Materials and Tools



  • Raspberry Pi Model B, B+, or 2 (with an ethernet port) and a power cord
  • Ethernet cable to connect the Raspberry Pi to your network
  • RFX gateway kit (http://embeddedcoolness.com/home/) to allow the nRF24L01+ radio modules to be used in TCP/IP (i.e., “WiFi”) mode


Power supply:

  • Bridge rectifier (converts ~34vac from thermostat wires to ~34vdc)
  • Buck converter (I used LM2596 – steps ~34vdc down to ~5vdc)
  • Voltage regulator (I used LM1117 - takes ~5vdc down to 3v3 for power input)
  • Switch


  • 1284P microcontroller
  • 40 pin DIP socket for the microcontroller
  • 16Mhz crystal oscillator
  • 22pF ceramic capacitors (2)
  • 10k ohm resistor
  • 0.1uF capacitors (2)
  • 3x2 pin male header (for ISP connector)


  • Relays with a 3V coil (4) - I used JRC-21F
  • PN2222A transistors (4)
  • 300 ohm resistors (4)
  • diodes (4) – I used 1N4004

Temperature sensor

  • ds18b20 digital temperature sensor
  • 4.7k ohm resistor

Touchscreen LCD

  • 3v3 Touchscreen LCD (I used this one)
  • 14 pin female header
  • 2N4403 transistor (as a switch for the LED lights in the touchscreen)
  • 12k ohm resistor (to control the current to the 2N4403 transistor)
  • 100 ohm resistors (3)


  • nRF24L01+ radio module (4x2 pin header configuration; it comes in low power and high power versions – low power should work for most applications, but if your thermostat will be 4 or 5 rooms away from the hub, you may need a high power module)
  • 4x2 pin female header


  • Perf board (I used 90cm x 150cm – I also found that paying a little more for a better quality, more rigid board was worth it to me)
  • 2 Pin Plug-in Screw Terminal (5)
  • Breadboard – for testing circuits/components before soldering
  • Plenty of hook up wire in different colors
  • Solder


  • Wood
  • Plexiglass
  • Screws


  • Wire cutters and strippers
  • Soldering station
  • Multimeter
  • avrisp mkii programmer (or equivalent)
  • CNC router (I used this to construct the case)
  • Screwdrivers and other common tools

About This Instructable




More by asheville makers:Web-Enabled Home Thermostat (and Home Automation Hub) How to Make Your Brother Printer Accept a Toner Cartridge 
Add instructable to: