Sunday, January 14, 2024

Thermostat Monitor System

 Summary

I was having trouble keeping track of which of my house's three heating zones was activating the boiler and pump at any given time. So I built a device to monitor which zone was calling for heat. 

Zone activation sensor system, with indicator lights

I used Prometheus to keep track of zone activation over time. 


Two days of zone activation lots via Prometheus. The temperature dropped over the last 8 hours, so you can see the upper floor is constantly active.

Build Process

My house has a hot-water heating system with three zones, each controlled by a valve like this one


Zone controller, photo via Amazon.com

There are three zones, each managed with one of these zone valves. Each zone valve is controlled by a thermostat.

Boiler and control valves 

These control values take a 24 Volt Alternating Current (VAC) input. When a thermostat calls for heat, it does so by sending 24 VAC to its control valve. The control valve opens the physical valve and sends 24 VAC to the boiler.


Diagram of power flow through the boiler system. The thermostat is effectively a switch that, when activated, closes the connection between the 24VAC transformer and the zone control valve.

The boiler system uses a transformer to convert the standard 120 VAC wall power to the 24 VAC used for the heating system. 

Each thermostat has its own settings for when to call for heat. The basic function of a thermostat is to track a set point (e.g., 68 degrees) and a current temperature (e..g, 70 degrees). If the current temperature is below the set point (in the case of a heating thermostat, e.g., 65 degrees) the thermostat will close the circuit from the transformer to the control valve. The control valve will open the pipe for hot water to the associated region of the house and will also close a circuit to provide 24 VAC to the boiler. This, in turn, causes the boiler to heat up and the water pump to turn on. 

Side note: newer thermostats like a Google Nest Thermostat require a "C-Wire." The C-Wire or "Common-Wire" is a neutral wire that allows the thermostat to use the 24 VAC supplied by the transformer. Without a C-Wire, the thermostat is just like a switch. 

Approach

I wanted to monitor which thermostat was calling for heat at what time and for how long. I also did not want to modify the heating system (I definitely don't want to break out boiler in the dead of winter!) To do this, I took advantage of a handy property of alternating current: you can indirectly measure it. Alternating current creates a magnetic field, which you can measure without directly touching the wires carrying that current. 

I purchased some of these clamp sensors (you can find them on eBay), which can measure alternating current on a wire when clamped around it. 

Clamp current sensor photo via eBay

I connected these to an Adafruit Metro ESP-32 S2, and used its analog ports to measure the voltage reported by each clamp sensor. 


Adafruit Metro ESP32-S2 via Adafruit


I found a prometheus exporter for CircuitPython on github. I had to make one modification to make it work with my board (my fork on GitHub).

I wrote a CircuitPython program to read the analog signals from the clamp sensors, then make that reading available to my prometheus server via a simple HTTP endpoint. Setting up CircuitPython took a bit of work, let me know in a comment if you would like a blog post about that process. 

The endpoint looks like this when viewed with a web browser:

Statistics reported by the thermostat monitor system

I configured my Prometheus server to scrape the thermostat statistics every 15 seconds. To generate a graph of when thermostats are active, I can use a query like:

environment_thermostat_upper_heat{job="thermostat"}

A query and associated results viewed in the Prometheus graph viewer

In this case we can see that the upper floor heat was active almost continuously over the past ten hours. This is not surprising, since an arctic vortex just arrived. 

Conclusion

CircuitPython is really handy for making Internet of Things (IoT) devices that work with an aggregator like Prometheus. 




No comments:

Post a Comment