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 for only a few bucks.
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.
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.
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.
The UI and Intelligence
Home-Assistant does all the User Interface and Intelligence. You just have to configure it.
Relevant bits of my configuration are as follows:
broker: !secret remote_server
port: !secret mqtt_port
username: !secret mqtt_user
password: !secret mqtt_pass
- platform: mqtt
name: Living room heat
- [more switches...]
- platform: mqtt
- platform: generic_thermostat
name: Living Room
I don’t have all the automations with the generic_thermostat hashed out yet but am working on them.
I will need a few more temperature sensors to really be able to control things to a finer degree, but to get some basic morning pre-heating intelligence going on, this is totally sufficient. Exciting times!