Hi, its taken me a long while to debug a problem where I want to capture all the sensor info I care about from a bunch of sensors (water, temp/humidity, motion, remotes) via Zigbee2Tasmota and I've got quite stuck where my jsonata code works perfectly in the test panel, but when applied to real incoming messages it does not. I've hit a brick wall and could do with some help. This jsonata takes some getting used to! I wish there was a really full nodered/jsonata tutorial or cookbook - it would really help. Browsing the forums has been really helpful so far, but I'm needing some specific help with getting the Temperature extracted.
Any solutions, pointers or tips to making this better would be much appreciated. Currently the flow switches according to the sensor type (parsing the name) which pipes into topic creators, then to this payload node.
Ah ok. So are you are trying to split the value in FE03/0020 by a , and divide the last element by 100?
Ps, can you capture and post a real sample message that doesn't work? I suspect the order of properties are different in you incoming data & as you are using $keys it may not be the property you are actually wanting.
Yep, I'm trying to get that temperature value but that string `FE03/0020' isn't static amongst all the sensors, but I could regex it. You're right about the ordering, I'd considered this but my jsonata isn't good enough to find the value matching ENV via search rather than ordering.
I'd prefer jsonata as I'm trying to master it, unless it wasn't designed for this kind of extracting. But I will try it in JS.
That was the real sample message in debug and this is what I see in MQTT.
Its failing with that error because your jsonata received a payload that doesnt include a value that can be $split ? It worked fine if Water or Power were missing but $split didnt like the absent value
Tried that code UnborN but unfortunately it didn't pickup the temperature. I'm struggling with the JS too, but I'd like to think jsonata can do this, searching through the value strings, to find one matching ENV and presenting that containing string, for manipulation.
It's in the payload property/object and is, afaik, a default from zigbee2tasmota
It works! Your idea with the $temp function/expression works very well, I'll use that again. Thanks very much.
You're right, that worked too, thanks! I hadn't realised I'd needed to add payload explicitly. I'm mindful not to rely on positional checks though, so the additional $temp method from @UnborN is the way to go.
As can be seen in both solutions I get lots of errors from msg.payloads that don't parse well. I take it, even though it may not be damaging, its good form in node-red to eradicate errors and have the msg flow dropped cleanly with logging maybe?
Here's the full flow with both solutions. I need to add on the import of all the measurements found to InfluxDB which is the pimary task. I'll loop through the key/values per topic/payload.