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