Accessing Temperature property in payload (DS18B20 - Tasmota - MQTT)

Hi,

I am a newbie and want to bring my temperature from the ESP8266 to NodeRed.

This is my Payload:
payload: "{"Time":"2021-04-29T07:48:11","DS18B20-1":{"Id":"3C01D60745B0","Temperature":42.9},"DS18B20-2":{"Id":"3C01D607558B","Temperature":35.5},"DS18B20-3":{"Id":"3C01D607C8F9","Temperature":35.9},"DS18B20-4":{"Id":"3C01D607DBB3","Temperature":27.9},"TempUnit":"C"}"

I need the temperature of the individual sensors. Who can I split this?

thanks

Not sure if that is a json string or a object, Have you set the mqtt node to output an object. If you do then the temps will be available at
msg.payload.DS18B20-1.Temperature
msg.payload.DS18B20-2.Temperature
etc

yes it is an Object

Which node do I have to take

The split node is for splitting and it works for your case with default configuration. It makes multiple messages from that single object and sends all of them downstream. Then you can send every individual message to the separated branch of flow if needed.

Here is an example

[{"id":"86eb867f.fdaa38","type":"function","z":"c9512783.9493c8","name":"DATA","func":"msg.payload = {\"Time\":\"2021-04-29T11:11:37\",\"DS18B20-1\":{\"Id\":\"0417C3DCF9FF\",\"Temperature\":23.8},\"DS18B20-2\":{\"Id\":\"0417C43F83FF\",\"Temperature\":25.4},\"DS18B20-3\":{\"Id\":\"0517C458DEFF\",\"Temperature\":26.8},\"DS18B20-4\":{\"Id\":\"9C9D8D116461\",\"Temperature\":25.1},\"TempUnit\":\"C\"}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":380,"wires":[["f7ce04bb.e41528"]]},{"id":"bda6c376.ef5dd","type":"inject","z":"c9512783.9493c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":380,"wires":[["86eb867f.fdaa38"]]},{"id":"ac095bc6.147bc8","type":"debug","z":"c9512783.9493c8","name":"SPLITTED","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":340,"wires":[]},{"id":"f7ce04bb.e41528","type":"split","z":"c9512783.9493c8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":430,"y":380,"wires":[["ac095bc6.147bc8","f66474c3.1d8b38"]]},{"id":"f66474c3.1d8b38","type":"switch","z":"c9512783.9493c8","name":"","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"-1","vt":"str"},{"t":"cont","v":"-2","vt":"str"},{"t":"cont","v":"-3","vt":"str"},{"t":"cont","v":"-4","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":590,"y":420,"wires":[["6e7f9496.dad8ec"],["dad0e90b.c06558"],["3c44289f.6f7a58"],["38fd87bd.996d48"]]},{"id":"6e7f9496.dad8ec","type":"debug","z":"c9512783.9493c8","name":"D - 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":400,"wires":[]},{"id":"dad0e90b.c06558","type":"debug","z":"c9512783.9493c8","name":"D - 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":440,"wires":[]},{"id":"3c44289f.6f7a58","type":"debug","z":"c9512783.9493c8","name":"D - 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":480,"wires":[]},{"id":"38fd87bd.996d48","type":"debug","z":"c9512783.9493c8","name":"D - 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":520,"wires":[]}]

I configured the split node to copy the key of object to the msg.topic so the routing can be done more easily then.
image

No, your payload is a string - that is evident by the value starting with a " .

To be more precise, it is a JSON string.

If you set the mqtt node to parse that to an object you can easily access the values within...

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

https://nodered.org/docs/user-guide/messages

Sorry, my mistake to not notice that.... :flushed:

1 Like

I've got a solution:
return {payload: msg.payload ["DS18B20-1"]. Temperatur};
image

Thanks

No it's a json string. as the text is all red in the image.

As said before set the mqtt node to output a js object.

Is that not what i said in post 2?

es funktioniert

thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.