Enlighten your old furnace with a Raspberry Pi, Home Assistant, an ESP8266, and some relays.

My mom has one of those on/off furnaces (EDIT: actually it’s a boiler) that heats up water and circulates it through pipes around the house that have little radiator fins. She wants it to turn on before she wakes up so it’s not so cold in the morning. In this post, I explain how to turn a normal furnace into a smart furnace controlled by Home Assistant for only a few bucks.

Furnace controls in Home Assistant

Starting point

I already had a Raspberry Pi 3 running Home Assistant for some basic home automation stuff around the house (a few lights, cameras, door sensors, temperature, ham radio, motion sensors.. see my earlier posts in this category). This can be set up pretty easily. I also have an OpenVPN server installed on the home router (using DD-WRT), allowing easy remote access to the LAN.

The furnace is as simple as it gets. There are like 8 zones each controlled by a two-wire (red and white) Honeywell mercury thermostat.

Honeywell Mercury Thermostat

Physically Controlling the Furnace

When one of these thermostats gets cold, mercury flows downhill and connects the two wires, which are hooked up to a 24V transformer that actuates a water valve (for example, the silver box in upper left of above photo). The water flows and the heat turns on. Again, this system is heat only so it’s as simple as it gets. To take control of it, all I need to do is be able to control a relay that connects the two wires. I could put a relay and temperature sensor in the wall near each thermostat and run some wires to control them, but it’s easier for me to put all the relays together by the furnace and rely on wireless temperature sensors.

But how to control the relays? I don’t want to have a dedicated Pi down there for run a bunch of wires. Enter… the ESP8266.

The ESP8266 is an incredible little System-on-a-Chip (SoC) that has a WiFi radio and can be programmed just like an Arduino. It has libraries ready to go for message passing (MQTT) to tell it when to flip switches, Over-The-Air updating so I can upgrade the system without plugging it into a computer, and tons of other stuff. It also has 16 GPIO pins, many of which are available for the user in most packages. And it’s just a few bucks! (Note that the ESP32 just came out that has Bluetooth too). I got one packaged as a Wemos Mini D1 because it came with a USB interface, making it easier to deal with for a few extra dollars.

Wemos ESP8266 and Relays. USB cable is only for power because data comes over WiFi.

On the other end of these relays, we simply patch into the contacts of the red and white thermostat wires from each zone we want to control. The original thermostats stay where they are, and the system reverts to normal old behavior when the relays are off.

MQTT for communication

MQTT is perfect for this kind of application. It’s an IBM-developed simple messaging protocol originally intended to control pipelines and stuff via satellite. It offers publish and subscribe services, which is exactly what we need. The ESP8266 will subscribe to a few topics and turn relays on and off according to what it gets and Home Assistant will publish commands based on user input or automations. MQTT also has a “last will” feature where the ESP8266 can tell the broker to send an “unexpectedly offline” message if it ever gets disconnected, which I use to send myself an email if the power at home goes out or if something else breaks. The PubSub library (among others) adds MQTT capabilities to the ESP8266.

I have an external MQTT broker on a server but you can alternatively just use the built-in MQTT server on Home Assistant or install one locally on your LAN. I like the external one because it will tell me if the house goes offline.

The ESP8266 Code

My code is posted here. It has “secure” MQTT (encrypted but not verified), and allows OTA updates from the LAN. Note that there are a lot of things that can go wrong (i.e. the furnace can stay on if this loses connection after it turns on) so use at your own risk! I assume no liability if this damages your property. It should be monitored and adjusted carefully while you work out any kinks.

Home Assistant configuration for smart furnace

Home-Assistant does all the User Interface and Intelligence. You just have to configure it. The generic_thermostat component is perfect for this.

Relevant bits of my configuration are as follows:

With those components in place you just make a few simple automations to turn the heat on in the morning and off at night.

To get some basic morning pre-heating intelligence going on, this is totally sufficient. Exciting times!

Here it is in action over a day:

Temperature turning on in morning and holding steady all day



13 thoughts on “Enlighten your old furnace with a Raspberry Pi, Home Assistant, an ESP8266, and some relays.”

  1. As a general tip for people like me that might be searching for this, what you are controlling is a boiler, not a furnace.

    I plan to do a very similar setup. Where are you getting the power for the board? Did you plug and just plug in an adapter, or are you converting down the 24v AC from the transformer near the boiler?

    You didn’t include what you’re doing with the original thermostats. It seems like it would be pretty easy to pick up that side of the wiring as well. Did you do, or do you plan to do this?

    1. Thanks for the feedback! I mentioned “boiler” at the top now. Yeah, the ESP8266 and relay board are just powered through the nearby wall AC outlet through a standard phone-charging microUSB wall-wart. The original thermostats stayed where they were so the system reverts to “regular old” mode when all relays are turned off (I edited the description above to clarify this).

  2. Do you have the part number of the relay module you used, and could you give additional info on how you wired the ESP8266 to it?


    1. It just says “4 Relay Module” on it. It’s one of those optoisolated ones. Here’s the exact model.

      For wiring it, I applied +5V to the VCC pin, GND to the GND, GPIOs D4, D5, D6, D7 to the relay inputs (those are Wemos numbers; actual ESP8266 GPIO numbers are 2, 14, 12, 13). Importantly, I jumpered the VCC and VCC-JD pins (this powers the coils with the same +5V coming in over the USB cable from the wall outlet).

  3. hello is it possible to add 4 manual buttons to this project. I want to use this project to control my room lights.

    1. Sure. You just need buttons that can trigger the MQTT messages that will in turn flip the relays. I use an old IR remote control from a TV with a $2 IR receiver for things like this because that’s the cheapest, but you can also wire buttons right into the Pi or use other wireless buttons of some kind.

  4. Hi there, my 12 year old son is looking to do a raspberry pi project that controls our heating (help!). Being a relative neophyte to coding, does your setup work without him wiring into our thermostat? We have a wireless Drayton Digistat RF701 Thermostat. Any help gratefully received!

    1. Hi Sarah, I checked out your thermostat and I can’t tell exactly how one would control it from a raspberry pi. So I’m afraid I’m not sure how to help your son out. One good place to start would be to just hook the pi up to a temperature sensor of some kind and read what the current temperature is. He could have it ding or blink a light when he thinks its time for the heater to turn on and off and maybe that could be later expanded to actually flip it on and off. That extension may require wiring changes though.

  5. does the esp8266 that we see plugged into the relay board need a separate board to program it? or can we plug it directly into a pc?

    1. Many ESP8266s, including the one in this post, come packaged on boards that have a micro-USB port and some memory and other stuff. The ESP8266 itself is just a chip so you can get it alone without any of these things.

  6. Using a Raspberry Pi to automate an old furnace is a clever and cost-effective solution. What are the main benefits of integrating a Raspberry Pi with your home heating system?

Leave a Reply

Your email address will not be published. Required fields are marked *