Managing a boiler with NodeRED and Sonoff


#1

Finally I've got my boiler smarter with NodeRED :slight_smile: It now has automatic mode which heats the water based on usual family needs (as scheduled). During the day it maintains 45C for daily needs.
It also has manual mode and "warm once" feature which warms the water up to 60C if needed (outside the schedule).

The project uses Sonoff TH16 with its original firmware but was tricked to use local sonoff server hosted in NodeRED. Very neat Cloud / Internet / Vendor independent solution.

Sensor's cable was lengthen and the sensor was attached to boiler's water tank just behind the mechanical thermometer (the only available option without the need to break the insulation). The sonoff is itself placed in an isolated plastic box:

I had to develop a new Node specifically for Sonoff TH series which reports temperature and humidity (this node was proposed to the author of node-red-contrib-sonoff-server and hopefully it will be included in the suite).

The logic is based on Norelite which has powerful rule engine and tools for date/time limits:

image

Here is the complete flow which drives the boiler:

Basically it says:

  • warm the water to 60C everyday between 23:00 - 01:00, 04:30 - 07:00 and 17:00 - 18:30 (we have two tariffs , the night tariff is cheaper);
  • During the day keep water's temp at 45C;
  • Allow the water to be heated once up to 60C;
  • In all cases if the water exceeds the temp threshold - stop the heating.

There's logic to check for sensor malfunction which is important when playing with electricity. In case of failure all rules are disabled. I plan to add notifications.

The boiler can be managed and monitored via new Dashboard page where you have a few sliders, status indicator and simple temperature graph:

It is driven by the following flow:

Since I log all temperature and switch status readings to a MySQL database they are displayed in a meaningful chart using Grafana:

The green is the water's temperature, the yellowish rectangles show the time when the sonoff switch was on (i.e. heating mode). Here you can see, analyse and make conclusions about:

  • Temperature losses of your boiler
  • Human behavior. That can be further analysed to create dynamic heating schedule;
  • How much energy is used based on daily uses

Recently I've upgraded to more recent version of MySQL (manual compilation from source files, duh) which supports Windowing functions. So it will be easier to calculate the total power consumption over specified period.

Roughly speaking the boiler is working 3-4 hours less a day which results in great savings.

TODOs:

  • Create dynamic scheduling based on behavior analysis
  • Fast warm when someone is reaching the house based on GPS coordinates
  • Vacation mode
  • Heating failure detection - i.e. detect if the switch is on, but the water does not get heated + notifications

A caution regarding sonoff TH16: According to the specs it can drive up to 16A. But it seems there are batches with cheaper relays that can be troublesome. In my case the boiler is 3KW and the relay got broken after a few days of work. So I had to replace it (with 20A equivalent in my case).


#2

Nice project ! What is the firmware version of your Sonoff device ? As far as I understand the manufacturer implemented (not long ago) SSL certificates that now prevents people from hacking the device (for OTA upgrade for instance). I wanted to know if the communication Sonoff - Node-RED (local sonoff server) would still work even with the latest firmware .


#3

My sonoff th16 is labeled as model PSA-BHA-GL and has fw version 2.0.4. I'll have to check the other sonoffs (touch, dual and basic) but I did upgraded them to the latest firmware not long time ago. And they all work with the local sonoff server.


#4

Sonoff devices are based on the ESP8266 so you can upload a new firmware like Tasmota or ESPEasy.
Have a look here:


or
https://www.letscontrolit.com/wiki/index.php/ESPEasy

MQTT is a good choice for the connection with node-red.


#5

@cflurin Agree. But it is way faster to use the original firmware with zero hardware intervention for simple uses like switches and temp sensors. Why will one need to bother with compilation and configuration instead of simply pressing the button for 7 secs? Again this is fine for simple cases. For advanced scenarios I would recommend Tasmota, Espurna or MongooseOS.


#6

Ok, I never used the original fw so I don't know the details. I use several Wemos and Sonoff devices all communicating via MQTT so no need to install extra server software.

Does the original fw support MQTT?


#7

Natively no. But once paired with the local sonoff server you can bind it to MQTT or do whatever NodeRED supports :slight_smile: .


#8

I use a number of Wemos D1 Mini boards (ESP8266 based controllers) that I've reflashed with ESP Easy.
These can be updated OTA as they have 4Mb of flash.

I also have some in-line SonOff and S20 Sonoff mains switches. These I've flashed with Tasmota as all they do is turn an applicance on/off. Once the Tasmota firmware has been flashed on to the SonOff it can be upgraded by OTA. It's a two step process. First OTA a minimal version over the current version, then OTA the new version over the minimal version. Works like a dream.


#9

I didn't try but this seems to work for ESPEasy too:


#10

Would you consider releasing the code for this PK ?