Newbie: How to parse temperature data from Sonoff TH10

Have a node red flow successfully processing 16 Sonoff basics {Tasmota firmware} with Pete Scargill's Big Timer on a RPi and it works perfectly. The dashboard for these Sonoffs also works fine.

I am now beyond my expertise in Node Red with a Sonoff TH10 {Tasmota firmware}.

I can turn on/off the TH10 via a couple of inject nodes.

Where I am limited { no experience in JSON or Node Red functions} is how to:

  1. Extract the temperature value from this:
    {"Time":"2018-12-20T20:17:26","AM2301":{"Temperature":69.3,"Humidity":26.8},"TempUnit":"F"}"

  2. Once the value is parsed out I then need simple logic to send: .
    If the temperature <74 cmnd/Mysonoff_TH10/power ON
    If the temperature > 75 cmnd/Mysonoff_TH10/power OFF.

While the ability to change these set points via a dashboard would be nice, they will change so infrequently that hard coding them in the Node Red code will be sufficient.

Thanks in advance for any assistance.

Start by sending the input to a debug node, then in the debug pane expand the payload till you can see the temperature value. If you hover over this then some little buttons will appear to the right. If you click one of those (the right most one if I remember correctly) it will say Path Copied. If you paste that somewhere you will see that it is the path in the message to get the value you want. Then in a Change node set it to Move, paste the path into the From field and put msg.payload in the To field. That should give you the temperature in the payload.
Look at the Switch node for the next bit, or write some code in a Function node.

2 Likes

Fantastic! Thanks Colin. I'm heading out right now but I'll try this when I get back home.

I am using tasmota based/driven devices as well.
The MQTT message is in JSON format, so I first convert it to Javascript object format (using a JSON node), then split the payload into individual Objects. Each Object then is passed to a switch node to extract/act on it.
For access objects at a deeper level in the Object-Tree, catch the desired level in the switch node, then resend it through the split node again to catch the next level of objects again.
In your example the Sensor is am AM2301 and the temperature is an Object one level below the Sensor Name.
Luckily all Objects in the tasmota messages are quite unique, so you can re-use the same split-switch node combo.

Here is an example for my TH16 with a single DS18B20 Sensor, running tasmota:

msg: {"Time":"2019-01-03T21:36:33","DS18B20":{"Temperature":20.6},"TempUnit":"C"}

tasmota-parse_Temp

and the flow for it:

tasmota_parse-msg-temperature_I.txt (5.1 KB)