Heater Smart Switch

To automate my home heating system, I installed a Shelly 1PM Mini Gen3 switch to control the gas boiler based on sensor data, reducing standby energy consumption.

Heater Smart Switch

Heater Smart Switch

Motivation 

My family and I have been living in a single-family home in Saarland, Germany, for about twenty years. In addition to a gas condensing boiler, we heat our hot water with a solar thermal system. To save the 12 watts of standby consumption, I turn off the heating completely in the summer, as the output of the solar thermal system is usually sufficient to keep the water hot. There were years when I turned it off at the end of April and did not turn it back on until early November. This year was different. There have been many periods of bad weather that have forced me to turn the heater on from time to time. The problem is that I sometimes forget to turn it on - I only notice when someone wants to take a shower and the water isn't hot enough. It can also happen that I forget to turn it off when the sun has been shining again for a long time. I thought it was time to automate the whole thing. 

Preconditions 

  • I already use some Shelly smart switches to control shutters and lights, so it's natural for me to use Shelly devices for this project too. 
  • My house already has a self-made building monitoring system with about 25 sensors, mainly temperatures but also some other environmental sensors. 
  • The monitoring system is based on MQTT and a free serverless cloud broker from HiveMQ, which I also want to use to communicate with the Shelly device. 
  • I have already played around with Node-Red and thought this might be a good use case for a first serious project. 

Installing the Shelly smart switch 

Since the maximum current of the gas condensing boiler is well below 8A, I chose the Shelly 1PM Mini Gen3, which has the added benefit of allowing me to measure the power consumption when the heater is on. Installation was quite simple, as there is enough space in the housing of the heater. The heater is connected directly to the mains, just behind an emergency switch in the next room. The photo below shows the installation of the switch. 

Once the MQTT connection has been configured in the Shelly Smart Control app, everything should be ready for the next steps. I configured it as shown in the dialog below (sorry for the German UI), and a first test with web client provided by HiveMQ worked immediately. 

  

Sensors involved 

At least for the initial setup, I started with three sensors for the switching logic: 

  • The outdoor temperature on the north side of the house. I want the heater to turn on when the temperature drops below a certain level. 
  • The temperature of the hot water tank. I have three sensors attached to the tank, but for this use case, I have only selected the middle one. As before, I want the heater to turn on when the hot water temperature drops below a certain level. The heater will then immediately start charging the tank. 
  • The third is the temperature of the return flow of the charging circuit. If this temperature drops below 50°C again, the charging is finished. 

The first sensor mentioned is a wireless temperature and humidity sensor that I read via Tinkerforge hardware. The last two sensors are DS18B20 One-Wire sensors connected to a Raspberry Pi Pico W. The detailed logic will be shown later in the corresponding function of the Node-Red flow. 

 

Node-Red 

All of the sensor data from the aforementioned building monitoring is collected by a Raspbery Pi Zero-based edge device that outputs a compressed JSON bundle. The Shelly devices cast and consume their specific payloads on specific MQTT topics. Now we need something in the middle to glue it all together. My first impression of Node-Red was that it could do just that. Node-Red currently runs on Kubernetes (see NodeRed-On-Rancher) but for production use I will most likely move it to a Raspberry Pi. This is the flow I created to consume the sensor data, apply the switching logic, and send the commands to the Shelly PM1 Mini Gen3: 

 

Explanation 

  • The purple nodes are the MQTT connectors. All are connected to the same broker, but the one on the left subscribes to home monitoring, and the two on the right publish to the Shelly-specific command topic. 
  • The red node is a sub-flow that processes the incoming message. The raw data is a JSON structure that is compressed and Base64 encoded. The output of the node is the original JSON. 
  • The yellowish nodes simply convert the output of the switching logic (0/1) into regular MQTT messages that can be consumed by the Shelly switch. This could actually be simplified to a single branch, but for ease of understanding and debugging, I kept the two branches for switching on and off. 
  • The only purpose of the green nodes is to produce the debug output on the right. 
  • The orange node named "Heater Switching Logic" is the actual worker node that decides whether to turn the heater on or off. Please see its JavaScript function below! 

Worker function 

 

Shelly command messages 

For the sake of completeness, I want to shed more light on the Shelly MQTT commands that control the heater's power switch. You can also see them in the debug window next to the Node-Red flow. 

  Topic: shelly1pmmini3-<device_id>/command/switch:0 

Payload: on|off 

More information about the MQTT commands in the Shelly Technical Documentation. 

Conclusion 

  • This combination of components, by which I mean MQTT, Node-Red and Shelly devices, is quite powerful. 
  • I have been using HiveMQ's free serverless cloud broker for years and find it very secure, reliable and convenient. 
  • As for Node-Red, I'm a newbie, but I think it has great potential for this kind of connectivity, and it's fun to work with. 
  • Meanwhile, I have become a big fan of Shelly devices. The Shelly 1PM MINI Gen3 I used for this project is really tiny but still packed with power. Look at all the options you have in terms of switching logic, scheduler, power metering, external control via MQTT, just to name the most important ones for me. 

Outlook 

As I mentioned before, the toolset I used for this project is pretty powerful and gave me a lot of new ideas on how to automate our home. Just to name a few: 

  • Some sort of geofencing that opens the garage door for me when I drive up. The door is already equipped with a Shelly 1 MINI Gen3. 
  • I could control the awning on our patio with a Shelly Plus 2PM and an attached Shelly Plus AddOn and a few sensors (wind speed, solar radiation, rainfall). 
  • It would also be interesting to add the sensors on the Shelly AddOn to my existing building monitoring system. This should be possible using MQTT. 

As far as the current project is concerned, I will certainly have to tweak my switching logic for the heating in winter. It may be sufficient for summer, but I suspect I will need more sophisticated logic for winter. 

Shelly Products Used
Shelly 1PM Mini Gen3

Shelly 1PM Mini Gen3

Prix habituel €16,07
Prix promotionnel €16,07 Prix habituel
Lumières
Appareils électroménagers
Serrure de porte
Sonnette
Ventilateur