This page presents my implementation of a smart thermostat using the Raspberry Pi board as the controller, with an added Pi Plate expansion board. This thermostat is controlled using a web page interface, so it can be controlled via any personal computer, smart phone or tablet with a regular browser. There is even a possibility to control it using another application via TCP/IP socket messages.
DISCLAIMER: I have created this web page to share my experience on using the Raspberry Pi in a thermostat application. You should not consider the solution detailed below as a final product to copy. You should rather see this as providing ideas on how to design your own smart thermostat. If you do not feel capable of understanding this project in its entirety, do not use it. Besides, I am not claiming to be a good software writer… So use it at your own risk! Consider the potential hazards that playing with heating and air conditioning systems represent. I shall not be held responsible for any mishaps that may occur as a result of implementing this thermostat solution.
The advent of the Raspberry Pi board opened a new world and allowed for elaborate thermostat feature development via simplified programming. Using any microcomputer platform like PIC or Arduino is possible, but the Ethernet stack, a web server and plotting functions are not something you can easily develop on such hardware. The Raspberry Pi, being a full computer running Linux, makes the above task development relatively easy, as support for these features is built-in.
The idea behind this smart thermostat project is to provide the same basic features as a regular programmable thermostat to begin with, namely:
- Current temperature and humidity measurement and display,
- Seven-day programming for both heating and cooling modes,
- 4-wire interface (Common, Heat, Cool, Blower),
- Manual program override (and self-return to program),
- Built-in clock.
This implementation adds the following nice features, which really differentiate this from a regular thermostat:
- Web interface, touch-friendly, for control and programming instead of LCD display and buttons,
- Seven-day programming of blower cycles to recirculate air at predetermined periods of the day,
- Outdoor temperature display via weather service RSS feed query,
- Ability to control the thermostat using text commands sent through TCP/IP socket messages. I use this to control from my home phone Asterisk PBX.
- Solid state relays (PhotoMOS) instead of dry mechanical relays,
- Web authentication by means of user ID and password,
- Temperature and On-Off cycle plotting on a per-day basis, in .PDF or .PNG output format, with a seven-day back log.
- An optional Watchdog function using a separate autonomous PIC micro-controller. Safety First!
The Software Platform
The Linux distribution I used on the Pi is Raspbian, a free operating system based on Debian optimized for the Raspberry Pi hardware. I elected to use Python 2.7 scripts to program this thermostat. Much of the required python libraries are already installed as part of the Raspbian Linux disto. The following are the Python libraries I use to augment the Python experience on Raspbian:
- Flask as the web server. It is lighter than Apache and it integrates seamlessly into Python. Follow these instructions to install Flask on the Pi.
- RPIO to control the Raspberry Pi General Purpose Input Output (GPIO) pins. It is an improved version of RPi.GPIO. It also allows to manage interrupts from I/O pins and TCP/IP Socket within Python with just a few commands. Follow these instructions to install RPIO on the Pi.
- Pychart to generate the temperature and activity plots. To me, this seems like the simplest yet a quite flexible package for generating charts out of raw data. Type “sudo apt-get install python-pychart” to install Pychart.
- Feedparser as the RSS client engine. This is optional, but it allows to retrieve and display weather data, such as outdoor temperature, sourced from a reliable weather services. Follow these instructions to install Feedparser on the Pi.
Here is the Python and HTML source code of my RasTherm project. I hope it will give you some good ideas!
The Hardware Platform
Of course, you need to obtain a Raspberry Pi board. I suggest the B version (either 256MB or 512 MB RAM) and an SD card (8GB, class-10 recommended). An enclosure, even the cheapest ($5), is highly desirable. A suitable 5V DC supply with a micro-USB cable is also required.
There are many ways to support and interface the required electronics to the Pi. I use the Pi Plate. It is an add-on board of the same dimensions, which sits right above the Pi. Since the amount of external electronics is small, there is more than enough room on the Pi Plate. Look on eBay; you may find cheaper pre-assembled copies of the Pi Plate…
For the temperature sensor, I have chosen the Sensirion SHT10 Temperature/Humidity sensor. It is relatively inexpensive, it uses a two-wire data interface and can be operated at any clock rate, something important if the cable between the Pi and the sensor is long. Mine is 9 meters long and reliable readings are achieved. Please see the note below on how to extend the length of the cable to more than the specified 30 cm. This is a small sensor with 0.050″ pin pitch!, So I mounted the sensor on a generic SOIC-to-DIP adapter PCB, which makes the connection to the cat-5 cable much easier.
I have elected to use the AQV21x PhotoMOS solid state relay family on the HVAC wiring instead of mechanical latched relays, which are more expensive, require more current to operate and make noise. These solid state relays (essentially fancy opto-couplers) on the other hand only require 2 or 3 milliamperes to operate, are reliable and sell for only a couple of dollars each.
I have used surface-mounted (SMT) 0805-size resistors and capacitors in the circuit. This size fits very well between the holes of the prototyping area. The wire type used is AWG 30 wire-wrap solid wire (the red wires). I have also used AWG 24 stranded wire (the yellow and black wires) between the PhotoMOS relays and the terminals.
For mroe detail: RasTherm – A Smart Thermostat built on the Raspberry Pi
Current Project / Post can also be found using:
- raspberry pi smart thermostat
- raspberry pi smart thermostat kit