Smart thermostat with ESP32

This build log is incomplete. Check back later for updates. This notice will be removed once the build is done.

My house is fairly sizable and as a result, sometimes the temperature across rooms and especially between floors is not uniform. Recently I have also noticed periodic changes in temperature which depend a lot on outside temperature. This is likely due to the horrendous position of the thermostat in a corridor as opposed to the living room which makes the living room prone to temperature fluctuations while the thermostat is blissfully unaware. Ultimately though, I'm not sure whether it's me or the house. I also recently got a piano which means I now need to worry about humidity. Unfortunately, the whole house humidifier attached to the furnace isn't powerful enough for Saskatchewan winters, which means the smart thermostat has to do a bit more than just thermostat-y things.

So I set out to build a smart thermostat with probes on each floor to monitor and control both temperature and humidity as I no longer have trust in my old fashioned wall thermostat.

Why build and not buy one of the hundreds of ready-made smart thermostats? No convincing reason.


To control a thermostat, we must first figure out how a thermostat works. Wall thermostats work either through 110/120/220/240V AC line voltage or 24V AC1. There are a number of resources online about wall thermostat voltage and wire color codes. Please read the documentation for your own furnace to make sure as these are just guidelines.

To ensure my thermostat works as I expect, I pulled out the wall thermostat device and looked at the wiring. Mine has 4 wires: red, green, yellow, and white. This makes it quite simple as I already have an idea of what to expect. I assumed the red line was voltage and used a multimeter set on AC voltage to test the rest of the wires.

I set the thermostat to 'heat' and increased the target temperature well above current temperature and noted the voltage between the red wire and white wire dropped to 0.2V AC. When the thermostat is off, the voltage between red and white wires went up to 24V AC. I then repeated the same, setting the thermostat to 'cool', changed the temperature, and noticed persistent voltage drop of 24V AC between red and white wire, but diminished voltage between red and yellow from 24V AC to about 0.2-0.4V AC, signifying a connection between red and yellow. The voltage drop between the red and green wire remained at about 0.9V AC, and I noticed the fan was on for both heat and cool settings.

That yields the following configuration, which is consistent with the standards.

Wire Function
Red Voltage line
White Heat
Yellow Cool
Green Fan

Note that what I actually found behind my thermostat were wires that had all sorts of colors not matching the above. However, the previous technician had labeled the wires as R, W, Y, and G. Make sure to test your wires.


The thermostat I'll be building is a power control board with the ESP322 at its heart. It connects through 3 24V AC mechanical relays to the furnace wiring as described above and will read temperature readings from multiple DHT20 sensors scattered through the house. The control board will connect to wifi and each sensor is connected to another ESP32 which broadcasts its readings over wifi as well. I thought about using bluetooth for communication, but the distances would make it unreliable. I was also not able to measure the current draw between thermostat wires, so I'll be taking a better-safe-than-sorry approach to relay selection.

Bill of Material


Part name Part number Description
ESP32-DevKitC-VE 1965-ESP32-DEVKITC-VE-ND ESP32 brains


Part name Part number Description
ESP32-DevKitC-VE 1965-ESP32-DEVKITC-VE-ND ESP32 brains
DHT20 1528-5183-ND Temp and humidity sensor




  1. I was surprised it was AC and had to double check, but multimeters don't lie.↩︎

  2. I'm using an ESP32-DevKitC-VE. Why Xtensa ESP32 as opposed to their Risc-V boards? It was in stock. Use whatever ESP32 module or any other microcontroller you have around. Even an ATMega328p with HC-05 bluetooth would work. I'm just taking the easy route.↩︎