Building a Smart Heater from scratch

Pedro Freitas
3 min readDec 5, 2020

--

The winter is starting to get tougher here in Portugal, bringing up challenges regarding climatization of our homes. If you don’t live in here, you probably thought that it is a warm country due to our sunny summers. Traditionally older houses are inferior in terms of climatization, lacking things seen in other western and central Europe countries.

Designing a solution

With that said, I’ve put my DIY hat, and the first thing I’ve done was to seal air leaks by install weather stripping where it was necessary, improving the amount of heat lost from heating appliances.

I’m using a simple space heater to do climatization of my living room, which includes an analogue thermostat. Toggling it too high or too low results in an inefficient outcome, so I’ve decided to turn this appliance into a Smart Heater.

Picture 1 — Overview of the setup

By using an ESP8266, running Arduino, plugged with a DHT11 sensor, I’m able to measure in real-time the temperature and humidity of my living room. This device collects the data and sends it to an MQTT server running in a Raspberry Pi. I’ve developed a small microservice that analyzes this data, toggling a smart plug when necessary, according to a preset target temperature. This setup allows me to save money since the heater is only turned on when needed, without any manual interaction.

Implementation

To be able to interact with the smart plugs I own (Tuya based), I’ve used tuyapi library and followed this documentation on how to setup.

You can find the source code for the following components here:

Monitoring the solution

To monitor the Node.js Microservice, we can use the New Relic monitoring platform to collect temperature information in the form of custom events. With the data present in New Relic, we can create powerful dashboards that allow us to visualize on the real-time. New Relic includes a free tier, with no credit card required. Currently the microservice aggregates 60 samples before doing any action.

Picture 2 — Monitor the device through New Relic.

All the data is queryable through NRQL, here is an example of a query for the temperature readings widget (Picture 3):

SELECT latest(minimum) as 'ºC Min', latest(maximum) as 'ºC Max', latest(average) as 'ºC Avg', latest(target) as 'ºC Target' From HeaterEvent WHERE appName = 'Smart Heater' TIMESERIES
Picture 3 — We can expand graphs in the dashboard for better view.

Scale-up possibility

We could scale this solution to include multiple temperature sensors and smart plugs. The MQTT messages would have to carry a device identifier so that the Node.js Microservice could do a correlation between temperature source and a given smart plug.

Another improvement to consider is swapping the DHT11 sensor to a DHT22, which provides a lower margin of error, in terms of readings.

Disclaimer

This solution is just a prototype, not recommended for general use. You’re better off purchasing a smart climatization solution from a well-established vendor. Use the information provided here as-is, no warranties and/or liability provided.

--

--

Pedro Freitas

Full-time DevOps Engineer | CKA | CKAD — Helping organizations to grow a DevOps culture.