MQTT Binding select nth value from list

I use Tasmota on an ESP8266 to send a Serial String to MQTT and currently I use a rule to pick out a value from a space delimited string. Can this be done using the MQTT2 bindings transformation tab?

I use *JSONPATH:$.SerialReceived to simplify the string to

 155.93 38.60 12.1 0.00 0.0000 0 0 0 0 0.0 0.00 0.99 0.00 0.00 1

and I currently get the values as separate numeric items using

 var stringItem = mqttString.state.toString.split("\t")
 var item1 = (Float::parseFloat(stringItem .get(0)) as Number)
 var item2 = (Float::parseFloat(stringItem .get(1)) as Number)

Yes, of course.

You can continue to do exactly the same thing you are doing now. Or you can chain transformations, doing the JSONPATH followed by a REGEX or JS transform. I don’t know how to do it in .things files but it’s documented in the PaperUI Chanel config for incoming transformations. You separate the transformations with an upside down U I think. I already just copy it from the instructions on the form.

After a lot of searching it seems I can use something like

 *JSONPATH:$.SerialReceived∩*REGEX:(.*?)

that returns the string

155.93 38.60 12.1 0.00 0.0000 0 0 0 0 0.0 0.00 0.99 0.00 0.00 1

Despite trying many combinations I can’t find the syntax that will pick out an individual value such as the second one 38.60. The list is seperated by spaces, what’s the syntax for REGEX to pick out a value? Usually they are seperated by commas

Well, the REGEX you provide is essentially a convoluted way to say “at least one character, but as many characters as are there, any type if character”. So it’s not surprising it returns everything. That’s what you’ve asked it to do.

You need to construct an expression that matches the full string, and then put in parens that part of the string you want to return. That means you need to give the expression some markers to go by.

You want the second value separated by spaces?

.* (.*) .*

Which means any number of any characters, a space, any number of any characters, a space and any number of any characters. The middle batch of characters gets returned.

Use regex101.com or any other online REGEX tester to build suitable expressions.

That returned nothing, but a combination of regex101.com and testing has given me this which works

*JSONPATH:$.SerialReceived∩*REGEX:..*\s(.*)\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*\s.*

I can select any value by moving the position of the brackets. Thanks for pointing me in the right direction

NOTE: For anyone else doing this. The code above ONLY works in PaperUI. Putting it in a config file throws many errors when the file is loaded.Changing “\s” into a simple space removes the errors but the translation doesn’t seem to work.