Tasmota/NodeMCU DS18B20 Temps into Emoncms via Node Red -Heatpump App

Hi All,

Wondering if someone could point me in the right direction. I would like to set up the heatpump app on emoncms. I have a emon tx with a current clamp measuring the power input.
Today I flashed a ESP8266 node mcu and connected 3 of the DS18b20 temp sensors to the flow in and out and one underneathe the unit for ambient.

Using MQTT explorer I can see these coming in and the topic is tele/heatpump/SENSOR.

If I parse these into Node red this is is the message in the debug window.

Ive knocked up this simple flow for now. Im trying to set the message payload to temperature for the DS18B20-1 and its just return the whole message payload.

Has anyone else done this before or know how to set a message payload for just the temperatures and send them to emoncms?

Any help would be much appreciated :slight_smile:



The final challenge is how do I get these into emoncms as an input?

I think you should specifiy the temperature MQTT topics and simply publish them again.

You topic on the left side would probably be:


Easiest way to get this topic would be to copy the path from the nodered debug panel.

An example topic for the emoncms would be:


You also have to make sure, that the MQTT output topic for emoncms is published on the MQTT broker of the emonpi or on the broker configured on the emonpi.

Following is an example of mine from a Shelly device:

It does depend how you have setup the Tasmota messages (if starting out, set them up for HomeAssistant as you will likely use it eventually and changing it over is a PITA). You just need to adjust the incoming payload part of the function below.

Assuming you are going to send these to the MQTT Broker your Emoncms instance talks to, to get as an input you just need to use the base topic emon/ and it will pull them in. In this case I use the topic emon/Tank.

If you have correctly setup the Tasmota for time (I suggest using an Epoch integer), you can use that time rather than the Emoncms received time.

I use a function which gets data from 2 Tasmota devices (you can only have 8 temp sensors on one ESP8266/Tasmota). The advantage is I can add sensors and they get automatically decoded.

You can also set up Tasmota to send the temperature at a specified frequency (I use 10s).

So put this in a NR Function;

var newmsg ={};
var data = msg.payload;
var dataout = {};

newmsg.time = msg.payload.Time;

for (var key in data){
    if (key.search("DS18B20") === 0) {
        dataout[data[key]['Id']] = data[key]['Temperature'];

dataout['time'] = msg.payload.Time;

newmsg.payload = dataout;

return newmsg;

I rate limit the messages to Emoncms, although I’m not sure this is still needed and is just a hang over from when I sent each message individually (and emoncms could not keep up).

NR object (you could set the message topic in the function - I set it in the MQTT node).


The MQTT message looks like this


Emoncms Inputs look like this (note 2 different times - 2 different Tasmota devices)

It is far more efficient to read and send the values in one go (so read shellies/balh/blah/emeter/#) then pull out the bits you need, then send to emoncms as a single JSON object. If you send messages too quickly to emoncms via MQTT, it can miss them.


Thanks for your replies. I did read the working with messages on node read webpage.

I did try copying the link for one temp sensor but it kept outputting the whole message for some reason? @bekesizl thats exactly what I wanted to do. For some reason I could not extract just the temperature readings from the json string.

So @borbin gave me an idea. Because I use HA and have alot of data inputting to HA and running automations, I have the node red plug in running. I decided add the sensors to the HA sensor yaml file. Then using node red plug in, I ping the current state of the sensors then output the message payload to my emonpi broker.

Logged into emoncms local and hey presto.

I would like to know how to pull out the temps straight from the message. See below.

I tried the following:


But to be honest I was just guessing. Do you know what it would be for the mqtt topic for each sensors? This is the complete message below.

	"Time": "2021-10-24T13:21:30",
	"DS18B20-1": {
		"Id": "0119143EC83C",
		"Temperature": 17.3
	"DS18B20-2": {
		"Id": "01191EBB523B",
		"Temperature": 14.1
	"DS18B20-3": {
		"Id": "0119272A7261",
		"Temperature": 13.8
	"TempUnit": "C"

I like the idea of a function node but dont really understand much of the code.



As you saw from the answer of borpin I am also not the expert.

Here is my code how I have rewritten the Shelly data publication via a JSON object.

var emeter_L1 = msg.payload.emeters[0]; //this gets data from the input payload (see copy path in my first post)
var emeter_L2 = msg.payload.emeters[1];
var emeter_L3 = msg.payload.emeters[2];
var emeter = {"H_tarifa_L1_power": emeter_L1.power, //this assembles a new payload as key/value pairs
              "H_tarifa_L1_pf": emeter_L1.pf,
              "H_tarifa_L1_current": emeter_L1.current,
              "H_tarifa_L1_voltage": emeter_L1.voltage,
              "H_tarifa_L1_total": emeter_L1.total,
              "H_tarifa_L1_total_returned": emeter_L1.total_returned,
			  "H_tarifa_L2_power": emeter_L2.power,
              "H_tarifa_L2_pf": emeter_L2.pf,
              "H_tarifa_L2_current": emeter_L2.current,
              "H_tarifa_L2_voltage": emeter_L2.voltage,
              "H_tarifa_L2_total": emeter_L2.total,
              "H_tarifa_L2_total_returned": emeter_L2.total_returned,

			  "H_tarifa_L3_power": emeter_L3.power,
              "H_tarifa_L3_pf": emeter_L3.pf,
              "H_tarifa_L3_current": emeter_L3.current,
              "H_tarifa_L3_voltage": emeter_L3.voltage,
              "H_tarifa_L3_total": emeter_L3.total,
              "H_tarifa_L3_total_returned": emeter_L3.total_returned,

var msgout = { payload : emeter };

return msgout;

above is the content of the first function
It publishes 24 values to emoncms in one shot.

Try this one with an MQTT publish node with the topic “emon/heatpumptemps”

var temp1 = msg.payload.SENSOR.DS18B20-1.Temperature; //try copy path for this part
var temp2 = msg.payload.SENSOR.DS18B20-2.Temperature;
var temp3 = msg.payload.SENSOR.DS18B20-3.Temperature;
var temps= {"T1": temp1,
              "T2": temp2,
              "T3": temp3,
var msgout = { payload : temps};

return msgout;

The problem with this is the timing will be out, ut for temperatures, that doesn’t really matter.

Received from where?

To workout

I’m never that confident doing it on the fly (my object decoding is not that good) so;

  1. Paste the JSON into an Inject Node payload and link that to a Debug Node outputting the payload.
  2. Click on the inject and you will get the payload in the debug side panel.
  3. As @bekesizl said above, click on the path link in the debug output to get the ‘path’ to the info you want.
  4. Try than in the debug node and presto.


You can’t pull this out of the SENSOR MQTT message directly (well you can but I doubt you want to delve into JSONATA).

so pull tele/heatpumpSENSOR/ as the payload, and output payload["DS18B20-1"].Temperature to the /emon/yourNode/YourInput


Yes as its just for temperatures timing is not critical so I can get away with it :). I could if it were and automation.

I use MQTT explorer to to view the messages recieved from my tasmota devices.

Thats a good idea. Not thought of coping the message into an inject node. I will have a play and try and get a function node working.

Thank you for your help :slight_smile:

You can also use the mqtt_statestream in your HA configuration.yaml

  base_topic: emon
      - sensor.mi_h_4c65a8d8de98
      - sensor.mi_h_4c65a8d8e00c

This sends the state when the sensor is updated (I think). These are different sensors (Mija Bluetooth temp/hum sensors).