Managing a boiler with NodeRED and Sonoff

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:


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.


  • 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).


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 .

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.

1 Like

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


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

@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.

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?

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

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.

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

Would you consider releasing the code for this PK ?

Very nice and quite powerful.

Unfortunately, or fortunately, I finally got my TH10 to accept the Tasmota firmware as I wanted to get off the EweLink and all its demands for my data. I have 16 Sonoff Basic devices all flashed with Tasmota running on Node Red with Zero problems.

However I am now stuck with a TH10 that I can turn on/off via Node Red but so far nothing I have tried has returned the Temp/Humidity sensor status. I can view it via a web browser and of course the Tasmota Console.

The best I can get returned is a message with an empty payload such as below:
12/20/2018, 10:26:05 AM[node: f371cac4.c9b7b8]
( : msg : Object

{ _msgid: "81d8255d.408d68", topic: "stat/Mysonoff_TH10/Status", payload: "" }

Changing the msg to "stats/Mysonoff_TH10/Status 8" yields the same empty payload but works perfectly via a web browser.
Browser msg: 8
Yields: {"StatusSNS":{"Time":"2018-12-20T16:52:46","AM2301":{"Temperature":67.8,"Humidity":27.2},"TempUnit":"F"}}

My application is simple and even though it would be nice to alter upper/lower temp set points via my phone it would rare and I could do it directly in node red.

I don't even need the humidity data as all I want is Turn on if < 74F and Turn off if >75F.

I would greatly appreciate any assistance. While I can program 8 core true multitasking micros in assembly, for some reason I am terrible at this MQTT stuff.

Have you set the module type to TH10 in the device?

Thanks for the quick reply!

Yes I believe so. In the Module configuration I have set it to: "04 Sonoff TH" which seems to be the only setting for a Sonoff temp/humidity module.

Yes, I think that is right. If you subscribe to all MQTT topics from the device you should see tele/STATE from the device with the wifi info etc every minute (or whatever it is configured for), but you should also see tele/SENSOR with the sensor data.

[Edit] Also if you browse to the ip address of the device you should see the web interface, and if you select Console you should see the sensor data there too.

I have just re-read your original message. Are you not using MQTT? If not then you definitely should be, it is by far the easiest way to communicate with such devices.

Thank you Colin!
I am running a mqtt@localhost:1883 which works for the other 16 Sonoff basics.

I have finally retrieved this from the TH10 using an mqtt input node. {tried this yesterday but I must have done something right today}


As I am such a newbie at this, rather than contaminate this thread further, I will post a separate request as to how to just parse the temperature and send a "cmnd/Mysonoff_TH10/power "on/off" depending on the temperature.

Thank you once again for taking the time to look at this.

For the temperature comparison you might like to look at node-red-contrib-ramp-thermostat (you can ignore the ramp bit of it).

By the way, did you realise you could do it all in the TH10 using the Rules feature of the tasmota s/w? Then you would not be reliant on the wifi being operational for the basic control. You could still use node-red for the UI and for tweaking the rules if the temperature setpoint changes. I use TH10s for room temperature control, running a PID control loop in the device with the relay controlling the heating, with node-red for the UI and influxdb and Grafana for real time and historical charts.

would you mind and share your flow, I would like to use it for my Sonoff that is using the Tasmota FW.

If I got it up and running I would share the flow again.

would you mind to share your node-red flow with me, because this is exactly what I'm looking for.
I got a mqtt broker and openhab where I would like to integrate my sonoffs to contral my heaters.

Which particular feature of the flows?