MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters

Tags: #<Tag:0x00007f617fbb47b0> #<Tag:0x00007f617fd03e68>

I checked in PaperUI and looked there:

only JSonPath:
image

RegEx + JsonPath
image

got it, it’s working as long as the channel type is a string…:frowning:

AdditionalQuestion:

Is it possible to link a number item to a string channel?

Then it would not make much a difference if the channel is already a number or not ?

according to the docs not:

image

Okay, either ignoring the warnings or use string and transform in a rule…

I don’t think so. If it only works for the String channel you may need to file an issue. How to file an Issue

opend an Issue

image

1 Like

@rlkoshak the problem with regex chained with json resolved in 2.5 release but new problem appeared. After restarting OH in PaperUI in transform value field symbol “∩” replaced with ? and item stop get new values. I suppoused this problem in unicode encoding but how i canresolve it? I add in start.sh file
this string: export EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyS1 -Dfile.encoding=UTF8" but it not resolve this problem, but resolve another problem with unicode symbols in paperUi web interface.

image

What happens if you edit the field again copying the ∩ from the text under that field and replacing the “?” with it? Does it revert back to ? or does that fix it?

1 Like

Now working just fine. I copied this symbol after restarting OH with -Dfile.encoding=UTF8 option.
The symbol did not change after restart OH.
Thank you. @rlkoshak

1 Like

I’m also trying to move my OpenHAB 2.4 configuration with MQTT v1 binding towards a test config with OpenHAB 2.5.1 and the new MQTT v2.5.1 binding. My config is completely text based for 2 reasons: I generate all things, items, rules and sitemaps from a small Python script; secondly: it enables me to easily copy parts of the configuration from one OpenHAB instance to another. I really need thorough testing to avoid issues with our heating system and big trouble with my wife :open_mouth:
I tried to use same combination of transformations, but I can’t get the special “∩” saved: it’s converted into the letter “n”. I also tried to add this line in the /etc/default/openhab2 file:
EXTRA_JAVA_OPTS="-Dfile.encoding=UTF8"
but no luck.

Here’s what I’ve got in the old items file (MQTT v1 binding):

Number Temp_Wemos4_CV_Ketel “Wemos4_CV_Ketel_T [%.2f C]” (gTemperature) {mqtt="<[mozquitoin:MBroadCast:state:JSONPATH($.TempValue):.“Temp_Wemos4_CV_Ketel”.]"}

And I added this in the new things file (MQTT v2.5.1 binding):

Thing topic MBroadcaster "MBroadcastR1" @ "MBroadcast" {
Channels:
    Type number : Temp_Wemos4_CV_Ketel "Wemos4_CV_Ketel_T"    [ stateTopic="MBroadCast", transformationPattern="REGEX:(.*Temp_Wemos4_CV_Ketel.*)∩JSONPATH:$.TempValue" ]
}

When looking in PaperUI I see this:
image

No errors in the logs… All help is welcome.

There is debate in java circles about UTF8 or UTF-8

How you can put this symbol? I put it by COPYING ctrl c ctrlv in to paperui. But in my situation all cyrillic symbols was ‘?’. Adding UTF8 option resolve this problem in my case.

It’s working fine now. I first started to implement it via PaperUI and it worked immediately. After that I came to the conclusion that my text editor didn’t really save the file in UTF8 format, even though I explicitely set the option. I had to change the “default encoding” of the editor to have it right.
Thanks for this post !

This ∩ character really complexifies everything as it forces us to use UTF-8 format, only for this. Isn’t there an alternative way, can it be replaced by some other character / combination of characters that allows us to keep using ASCII instead of UTF-8? If not possible, is there a platform where we can raise the question?

Important

All text files must be created with UTF-8 encoding.

From

You can file an issue on the openhab2-addons github, but as rossko57 points out, UTF-8 is the requirement anyway. So the issue is moot.

Hi @rlkoshak,

I’ve this:

        Type string : name      "Name"                  [ stateTopic="home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/E72E014260FF", transformationPattern="REGEXP:(.*name.*)∩JSONPATH:$.name"]
        Type number : rssi      "WiFi Signal Strength"  [ stateTopic="home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/E72E014260FF", transformationPattern="REGEXP:(.*rssi.*)∩JSONPATH:$.rssi"]
        Type number : distance  "WiFi Distance"         [ stateTopic="home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/E72E014260FF", transformationPattern="REGEXP:(.*distance.*)∩JSONPATH:$.distance"]
        Type number : temperature   "Temperature"       [ stateTopic="home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/E72E014260FF", transformationPattern="REGEXP:(.*tem.*)∩JSONPATH:$.tem"]
        Type number : humidty   "Humidity"              [ stateTopic="home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/E72E014260FF", transformationPattern="REGEXP:(.*hum.*)∩JSONPATH:$.hum"]
        Type number : battery   "Battery"               [ stateTopic="home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/E72E014260FF", transformationPattern="REGEXP:(.*batt.*)∩JSONPATH:$.batt"]

But now I’ve more warnings :slight_smile:

 20-08-02 18:08:29.252 [WARN ] [t.generic.ChannelStateTransformation] - Transformation service REGEXP for pattern (.*name.*) not found!
2020-08-02 18:08:29.253 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.name' in '{"tem":29.6}'

Can you point my error?

Doesn’t look like you have the REGEX transformation service installed?

PaperUI -> Add-ons -> Transformations -> RegEx Transformation -> Install

@hafniumzinc Yes I’ve it:

openhab> list | grep -i reg
277 │ Active │  75 │ 2.5.7                   │ openHAB Add-ons :: Bundles :: Transformation Service :: RegEx

And I use it in anothers places, like this:

{ udp="<[192.168.1.65:*:'REGEX(.*<chan id=\'0\'>.*<day units=\'wh\'>(.*)</day></chan><chan id='1'>.*)']" }

But you have to spell it right. You asked for REGEXP, it told you you haven’t got one.

1 Like

The most difficult mistake is always the most obvious :wink: