Need guidance parse Tasmota MQTT payload

Hey all,
Long timer lurker, first time posting to this forum.
So, I'm using Tasmota on ESP32 to monitor some Xiaomi Temperature and Humidity BLE sensors.

Similar to "Help me parse this payload" I'm having some trouble with how to parse the MQTT message. I'm intending to push this data into influxdb.

Here's the output from the MQTT In node (set to output 'a Parsed JSON Object')

As I have a number of different types of the Xiaomi sensors, there are identifiers prefixed with MJ_HT_V1 or ATC plus a suffix being part of the MAC address. Using the solution of change node as suggested for the post linked above means that I loose these identifiers.

So I'm after some guidance or pointers on what combination of Switch/Split/JSON/Join or function (code example welcome) nodes that I might need to extract this data, keep the identifier possibly add the name from the message topic and manipulate it into a format for inserting into influxdb.

Thanks
Andrew

You could use a change node to rearrange the object. As you have not supplied an example of the input (just an image) or how you would like the output , i can only guess

here is an example.

[{"id":"df1a9018.0b2828","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test","payload":"{\"time\":\"2021-07-17T12:18:24\",\"device1\":{\"humdity\":78,\"temp\":21},\"device2\":{\"humdity\":78,\"temp\":21}}","payloadType":"json","x":210,"y":3740,"wires":[["8de84be1.383a6"]]},{"id":"8de84be1.383a6","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$each($$.payload, function($v,$k){\t$k != \"time\" ? $merge([{\"device\": $k, \"time\": $$.payload.time, \"topic\": $$.topic}, $v])\t})\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":3740,"wires":[["380f2357.c19e5c"]]},{"id":"380f2357.c19e5c","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":3740,"wires":[]}]

Hey, thanks for looking at this.
So possible message from MQTT In node looks like;

{
   "topic":"tele/Nixon/SENSOR",
   "payload":{
      "Time":"2021-07-17T00:52:49",
      "ATC7e0a62":{
         "mac":"a4c1387e0a62",
         "Temperature":16,
         "Humidity":65,
         "DewPoint":9.4,
         "Battery":84,
         "RSSI":-89
      },
      "MJ_HT_V139a902":{
         "mac":"582d3439a902",
         "Temperature":21.5,
         "Humidity":52.3,
         "DewPoint":11.3,
         "Battery":99,
         "RSSI":-88
      }
   },
   "qos":0,
   "retain":false,
   "_msgid":"1836cffb.1d1f8"
}

and what I think I'd like to get out is something like;

[
   {
      "device":"ATC7e0a62",
      "time":"2021-07-17T12:18:24", // May not even need this for inserting into influxdb
      "host":"Nixon",      // Split from message topic
      "mac":"a4c1387e0a62",
      "Temperature":16,
      "Humidity":65,
      "DewPoint":9.4,
      "Battery":84,
      "RSSI":-89
   },
   {
      "device":"MJ_HT_V139a902",
      "time":"2021-07-17T12:18:24",  // May not even need this
      "topic":"Nixon",       // Split from message topic
      "mac":"582d3439a902",
      "Temperature":21.5,
      "Humidity":52.3,
      "DewPoint":11.3,
      "Battery":99,
      "RSSI":-88
   }
]

When I try using the message payload above with the flow provided, all I get is this error message.

Invalid JSONata expression: Argument 1 of function "merge" must be an array of "objects"

Thanks
Andrew

try

[{"id":"df1a9018.0b2828","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"tele/Nixon/SENSOR","payload":"{\"Time\":\"2021-07-17T00:52:49\",\"ATC7e0a62\":{\"mac\":\"a4c1387e0a62\",\"Temperature\":16,\"Humidity\":65,\"DewPoint\":9.4,\"Battery\":84,\"RSSI\":-89},\"MJ_HT_V139a902\":{\"mac\":\"582d3439a902\",\"Temperature\":21.5,\"Humidity\":52.3,\"DewPoint\":11.3,\"Battery\":99,\"RSSI\":-88}}","payloadType":"json","x":210,"y":3740,"wires":[["8de84be1.383a6"]]},{"id":"8de84be1.383a6","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$each($$.payload, function($v,$k){\t$k != \"Time\" ? $merge([{\"device\": $k, \"time\": $$.payload.Time, \"host\": $split($$.topic,\"/\")[1]}, $v])\t})\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":3740,"wires":[["380f2357.c19e5c"]]},{"id":"380f2357.c19e5c","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":3740,"wires":[]}]

The is cause of this is, my example used "time" in the object, but your object has "Time"

Are you sending this to an Influx Out node? If so then I don't believe the desired output you show is what you want. Have a look at the help pane for the node and see which format of payload you need.

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