Separate Two MQTT Temperature Payloads?

How do I separate these two MQTT temp payloads so that I can work with them. I have tried using a function node but, I'm really lost.

I have a nodemcu running tasmota with two DS18B20 sensors attached and returning 2 separate temperature readings using MQTT.

This is the debug I get from my MQTT input on Nodered.

nodered

object

topic: "tele/relaystack/SENSOR"

payload: "{"Time":"2021-09-22T16:10:36","DS18B20-1":{"Id":"0516A37095FF","Temperature":23.6},"DS18B20-2":{"Id":"3C01F095CECB","Temperature":23.7},"TempUnit":"C"}"
qos: 0
retain: false
_msgid: "4cb28f7c.a6be3"

Tasmota output

16:09:46.424 MQT: tele/relaystack/SENSOR = {"Time":"2021-09-22T16:09:46","DS18B20-1":{"Id":"0516A37095FF","Temperature":23.6},"DS18B20-2":{"Id":"3C01F095CECB","Temperature":23.7},"TempUnit":"C"}

firstly, set the MQTT in node to parse JSON

image

Next, you can use the "copy path" button in the debug to get the path to any item - then use 2 change nodes to move the values around


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




PS, please use the "copy value" button when posting values / code on the forum. Also, use the </> code button so that code is formatted correctly

Thanks for the help.

I have switched it as you said to JSON object.

I'm not sure what to put in the change node.

image

[{"id":"2451fec2.edb1b2","type":"mqtt in","z":"c74b932.e47c17","name":"DS18B20 Temp Sensors","topic":"tele/relaystack/SENSOR","qos":"0","datatype":"json","broker":"389dd264.7716de","nl":false,"rap":true,"rh":0,"x":390,"y":1820,"wires":[["6fb9b1fa.e3e9a","7f1002d3.21145c","7d2b290.61cfcd8"]]},{"id":"698c33fb.3193cc","type":"debug","z":"c74b932.e47c17","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":1860,"wires":[]},{"id":"682f8968.4c2698","type":"debug","z":"c74b932.e47c17","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":1800,"wires":[]},{"id":"7f1002d3.21145c","type":"change","z":"c74b932.e47c17","name":"","rules":[{"t":"set","p":"payload[\"DS18B20-1\"].Temperature","pt":"msg","to":"","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":1800,"wires":[["682f8968.4c2698"]]},{"id":"7d2b290.61cfcd8","type":"change","z":"c74b932.e47c17","name":"","rules":[{"t":"set","p":"payload[\"DS18B20-2\"].Temperature","pt":"msg","to":"","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":1860,"wires":[["698c33fb.3193cc"]]},{"id":"389dd264.7716de","type":"mqtt-broker","z":"c74b932.e47c17","name":"","broker":"192.168.10.65","port":"1883","clientid":"Node-Red","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]



Set msg.payload to the path (from Copy Path button) of the element you want.

For example
Untitled 8

Or, if you prefer, which I generally do as it seems more intuitive, is use Move rather than Set. Then it is Move msg.payload.whatever To msg.payload.

I couldn't figure out the "set msg.payload"

But the "move msg.payload" worked.

Thanks for the help.

Here is the flow.

image

image

[{"id":"2451fec2.edb1b2","type":"mqtt in","z":"c74b932.e47c17","name":"DS18B20 Temp Sensors","topic":"tele/relaystack/SENSOR","qos":"0","datatype":"json","broker":"389dd264.7716de","nl":false,"rap":true,"rh":0,"x":350,"y":1860,"wires":[["6fb9b1fa.e3e9a","7f1002d3.21145c","7d2b290.61cfcd8"]]},{"id":"698c33fb.3193cc","type":"debug","z":"c74b932.e47c17","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":1880,"wires":[]},{"id":"682f8968.4c2698","type":"debug","z":"c74b932.e47c17","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":1840,"wires":[]},{"id":"7f1002d3.21145c","type":"change","z":"c74b932.e47c17","name":"Prob 1","rules":[{"t":"move","p":"payload[\"DS18B20-1\"].Temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":1840,"wires":[["682f8968.4c2698","864641df.89983"]]},{"id":"7d2b290.61cfcd8","type":"change","z":"c74b932.e47c17","name":"Prob 2","rules":[{"t":"move","p":"payload[\"DS18B20-2\"].Temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":1880,"wires":[["698c33fb.3193cc"]]},{"id":"389dd264.7716de","type":"mqtt-broker","z":"c74b932.e47c17","name":"","broker":"192.168.10.65","port":"1883","clientid":"Node-Red","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

I am building a pool controller with an Arduino for the sensors and relays inside the steel control panel and a raspberry pie with a built in 5 inch touch screen placed on the patio, to replace my old dated goldline pool controller.

1 Like

I don't know why the Set syntax is confusing. It is perfectly logical. If I said Set the volume control To 50% you would know exactly what I meant, and it would be obviously incorrect if I said Set 50% To the volume control. But if I put, in the Change node, Set msg.payload To msg.payload.some_property then for some unfathomable reason it isn't immediately obvious and I have to think about what it means. That is why I almost always use Move.

2 Likes

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