[SOLVED] Nested REGEX and JSONPATH transformations

from my mqtt topic i get the following back:

{"POWER":"ON","Dimmer":98,"Color":"250,162,0,0","HSBColor":"39,100,98","Channel":[98,64,0,0]}

with

 JSONPATH:$.Color

i get back

250,162,0,0

which is RGBW, now i need RGB, i could do that with a regex

((,?\d+){3}).+$

which holds in $1 the result i want

250,162,0

Is there a way i can nest those transformations ?

Yes, with any version of the bindings after 2.5 M1 I think. It’s pretty self explanatory in PaperUI how to chain the transformations, separating them with the union symbol.

Intersection symbol MQTT Things and Channels - Bindings | openHAB

Hello,

I am little bit new in REGEX on openhab. Maybe you can help me.

I receive from mqtt broker firmware version string using JSONPATH:

transformationPattern="JSONPATH:$.StatusFWR.Version"
I receive string “v8.1.0(tasmota)

now I want to apply REGEX to that result to remove “v” and “(tasmota)”.
regix which I want to apply: ^[^\d](\d[.]\d*[.]\d*).*$ with substitution $1

what is correct syntax I need to use for transformationPattern to use JSONPATH & REGEX together?

Ed

In openHAB the regex must match the entire string. The first matching group (i.e. stuff in parens) is what get’s returned. That pattern doesn’t do that. For one, \d matches digits, not letters so it won’t match the starting “v”.

I find it easiest to be simple. We don’t really care about efficiency here as the strings are usually very short and the regex is not called that often. So keep it simple.

v(\d\.\d\d)\(tasmota\)

Or even simpler:

v(.*)\(tasmota\)

Just in case there is some white space before or after you can use

.*v(.*)\(tasmota\).*

See MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters, only the regex will go second instead of first as shown in that example.

Hello.

Not sure yours answer helps me. I still do not understand what i need to put in my things file.

Ed

2020-01-31, pn 16:06, Rich Koshak via openHAB Community bot@community.openhab.org rašė:

This… :grinning:

.* any string (to skip possible whitespace)
v the letter ‘v’
(.*) captures the firmware version string after the ‘v’ in $1
\( matches the opening bracket
tasmota matches ‘tasmota’
\) matches the closing bracket
.* captures any whitespace or other string at the end

Thanks.

Bur how i need to use it with jsonpath with my example. Sorry. I am strugling.

Ed

2020-02-01, št 07:52, Ron via openHAB Community bot@community.openhab.org rašė:

I don’t use MQTT with REGEX but according to the docs I think it should be something like this:

"JSONPATH:$.StatusFWR.Version ∩ REGEX:.*v(.*)\(tasmota\).*"

Note the ‘∩’ character that chains the transformations: first the complete version string is extracted from the JSON response and then the actual version number is regex’ed from that string.

Syntax is wrong :frowning:

I don’t use nor recommend the use of .things files so I can’t help with that. But in Ron’s example, I’m pretty sure there should not be a space on either side of the .

1 Like