Science and technology

Build a house thermostat with a Raspberry Pi

My spouse and I moved into a brand new residence in October 2020. As quickly because it began getting chilly, we realized some shortcomings of the house’s older heating system (together with one heating zone that was at all times on). We had Nest thermostats in our earlier residence, and the present setup was not almost as handy. There are a number of thermostats in our home, and a few had programmed heating schedules, others had completely different schedules, some had none in any respect.

It was time for a change, however the home has some constraints:

  • It was constructed within the late 1960s with a renovation throughout the ’90s.
  • The warmth is hydronic (scorching water baseboard).
  • It has six thermostats for the six heating zones.
  • There are solely two wires that go to every thermostat for warmth (purple and white).

To purchase or to construct?

I wished “smart” thermostat management for the entire warmth zones (schedules, automations, residence/away, and so on.). I had a number of choices if I wished to purchase one thing off the shelf, however all of them have drawbacks:

Option 1: A Nest or Ecobee

  • It’s costly: No sensible thermostat can deal with a number of zones, so I would want one for every zone (~$200*6 = $1,200).
  • It’s troublesome: I must rerun the thermostat wire to get the notorious C wire, which allows steady energy to the thermostat. The wires are 20 to 100 ft every, in-wall, and would possibly be stapled to the studs.

Option 2: A battery-powered thermostat such because the Sensi WiFi thermostat

  • The batteries final solely a month or two.
  • It’s not HomeEquipment-compatible in battery-only mode.

Option Three: A commercial-off-the-shelf thermostat, however just one exists (type of): Honeywell’s TrueZONE 

  • It’s previous and poorly supported (it was launched in 2008).
  • It’s costly—greater than $300 for simply the controller, and also you want a RedLINK gateway for a shoddy app to work.

And the winner is… 

Option four: Build my very own!
I made a decision to construct my very own multizone sensible thermostat, which I named ThermOS.

  • It’s centralized on the furnace (you want one system, not six).
  • It makes use of the present in-wall thermostat wires.
  • It’s HomeEquipment suitable, full with automation, scheduling, residence/away, and so on.
  • Anddddd it is… enjoyable? Yeah, enjoyable… I feel.

The ThermOS hardware

I knew that I wished to make use of a Raspberry Pi. Since they’ve gotten so cheap, I made a decision to make use of a Raspberry Pi four Model B 2GB. I am positive I might get by with a Raspberry Pi Zero W, however that will probably be for a future revision.

Here’s a full listing of the components I used:

Name Quantity Price
Raspberry Pi four Model B 2GB 1 $29.99
Raspberry Pi four official 15W energy provide 1 $6.99
Inland 400 tie-point breadboard 1 $2.99
Inland eight channel 5V relay module for Arduino 1 $eight.99
Inland DuPont jumper wire 20cm (Three pack) 1 $four.99
DS18B20 temperature sensor (real) from Mouser.com 6 $6.00
Three-pin screw terminal blocks (40 pack) 1 $7.99
RPi GPIO terminal block breakout board module for Raspberry Pi 1 $17.99
Alligator clip check leads (10 pack) 1 $5.89
Southwire 18/2 thermostat wire (50ft) 1 $10.89
Shrinkwrap 1 $four.99
Solderable breadboard (5 pack) 1 $11.99
PCB mounting brackets (50 pack) 1 $7.99
Plastic housing/enclosure 1 $27.92

I started drawing out the hardware diagram on draw.io and realized I lacked some essential data in regards to the furnace. I opened the facet panel and located the step-down transformer that takes the 120V electrical line and makes it 24V for the heating system. If your heating system is something like mine, you will see a number of jumper wires between the Taco zone valves. Terminal Three on the Taco is jumped throughout all of my zone valves. This is as a result of it does not matter what number of valves are on/open—it simply controls the circulator pump. If any mixture of 1 to 5 valves is open, it must be on; if no valves are open, it must be off… easy!

At its core, a thermostat is only a kind of swap. Once the thermistor (temp sensor) contained in the thermostat detects a decrease temperature, the swap closes and completes the 24V circuit. Instead of getting a thermostat in each room, this challenge retains all of them proper subsequent to the furnace so that each one six-zone valves could be managed by a relay module utilizing six of the eight relays. The Raspberry Pi acts because the brains of the thermostat and controls every relay independently.

The subsequent downside was methods to get temperature readings from every room. I might have a wi-fi temperature sensor in every room operating on an Arduino or Raspberry Pi, however that may get costly and complex. Instead, I wished to reuse the present thermostat wire within the partitions however purely for temperature sensors.

The “1-wire” DS18B20 temperature sensor appeared to suit the invoice:

  • It has an accuracy of +/- zero.5°C or zero.9°F.
  • It makes use of the “1-wire” protocol for information.
  • Most importantly, the DS18B20 can use “parasitic power” mode the place it wants simply two wires for energy and information. Just a heads up… nearly the entire DS18B20s on the market are counterfeit. I bought just a few (hoping they had been real), however they would not work after I tried to make use of parasitic energy. I then purchased actual ones from Mouser.com, they usually labored like a attraction!

Starting with a breadboard and all of the elements domestically, I began writing code to work together with all of it. Once I proved out the idea, I added the present in-wall thermostat wire into the combo. I bought constant readings with that setup, so I got down to make them a bit extra polished. With assist from my dad, the self-proclaimed “just good enough” solderer, we soldered results in the three-pin screw terminals (to keep away from overheating the sensor) after which connected the sensor into the terminals. Now the sensors could be connected with wire nuts to the present in-wall wiring.

I am nonetheless within the strategy of “prettifying” my temperature sensor wall mounts, however I’ve gone via just a few 3D printing revisions, and I feel I am nearly there.

The ThermOS software program

As standard, writing the logic wasn’t the laborious half. However, deciding on the applying structure and framework was a complicated, multi-day course of. I began out evaluating open supply initiatives like PiHome, however it relied on particular hardware and was written in PHP. I am a Python fan and determined to begin from scratch and write my very own REST API.

Since HomeEquipment integration was so necessary, I figured I’d finally write a HomeBridge plugin to combine it. I did not understand that there was a whole Python HomeEquipment framework known as HAP-Python that implements the accent protocol. It helped me get a proof of idea operating and managed via my iPhone’s Home app inside 30 minutes.

The remainder of the “temp” logic is comparatively easy, however I do need to spotlight a chunk that I initially missed. My code was operating for just a few days, and I used to be engaged on the hardware, after I observed that my relays had been turning on and off each few seconds. This “short-cycling” is not essentially dangerous, however it definitely is not environment friendly. To keep away from that, I added some thresholding to ensure the warmth toggles solely when it is +/- zero.5C°.

Here is the brink logic (you possibly can see the rubber-duck debugging within the feedback):

# test that we wish warmth
if self.target_state.worth == 1:
    # if warmth relay is already on, test if above threshold
    # if above, flip off .. if nonetheless beneath carry on
    if GPIO.enter(self.relay_pin):
        if self.current_temp.worth - self.target_temp.worth >= zero.5:
            standing = 'HEAT ON - TEMP IS ABOVE TOP THRESHOLD, TURNING OFF'
            GPIO.output(self.relay_pin, GPIO.LOW)
        else:
            standing = 'HEAT ON - TEMP IS BELOW TOP THRESHOLD, KEEPING ON'
            GPIO.output(self.relay_pin, GPIO.HIGH)
    # if warmth relay just isn't already on, test if beneath threshold
    elif not GPIO.enter(self.relay_pin):
        if self.current_temp.worth - self.target_temp.worth <= -zero.5:
            standing = 'HEAT OFF - TEMP IS BELOW BOTTOM THRESHOLD, TURNING ON'
            GPIO.output(self.relay_pin, GPIO.HIGH)
        else:
          standing = 'HEAT OFF - KEEPING OFF'

And I achieved my final purpose—to have the ability to management all of it from my telephone.

Putting my ThermOS in a lunchbox

My proof of idea was fairly messy.

With the software program and normal hardware design in place, I began determining methods to package deal the entire elements in a extra everlasting and polished type. One of my major considerations for a everlasting set up was to make use of a breadboard with DuPont jumper wires. I ordered some solderable breadboards and a screw terminal breakout board (thanks @arduima for the Raspberry Pi GPIO pins).

Here’s what the solderable breadboard with mounts and enclosure seemed like in progress.

And right here it’s, mounted within the boiler room.

Now I simply want to arrange and label the wires, after which I can begin swapping the rest of the thermostats over to ThermOS. And I will be on to my subsequent challenge: ThermOS for my central air con.


This initially appeared on Medium and is republished with permission.

Most Popular

To Top