Seperating Strings with PatternMatch send by Arduino

I am using a RPi 3B+ with openhabian 3.3.0.

My problem is that I dont get it how to write a working patternMatch and how to seperate afterwards the data into two Items. I already tried some things out as written in the Manuals from the Serial Binding. I am sending the following String from a Arduino via the Serial Bridge to the RPi : “Arduino; pH=4.12; Light= 2000 lx;”.

At the end I need two Items, one with the pH value of 4.12 and one with the lx value of 2000.

Could someone please help me :frowning: If you need some more data, feel free to ask me, I try to give you as much information as possible.

Thank you!

You can do this with a transformation service, like regex: RegEx - Transformation Services | openHAB

Ok, that helped me actually a bit, these are the things I tried for the last one and half hours without a result. Maybe you see my mistake, I also cut the String I am sending to make it step by step.

I hope these pictures can help.

Not really. What string are you sending now? What goes wrong?

For diagnostic purposes, its often useful to make a string channel and Item to receive the whole message, for confirmation.
You can also use a rule to develop methods to analyse that, you get better diagnostic visibility and easier editing in a rule. When you’ve worked out what to do, you can always put that into a channel transformation.

If you use the functionality of the serial binding use the stateTransformation parameter. No need to also use the transformation service than.

The String i am Sending is: Arduino;pH=4.13;
I have made a String Channel and an Item (picture 3) there you can also see the String i am sending. How do I use Role or where can I build a rule?

But in my Serial Device there is this Pattern match required, I think I already got there something wrong and I thought the stateTransformation parameter is only working with this RegEx transformation service.

Yes, but it has a transformation that does not work.

I was suggesting that you could make another string channel/Item with no transformation, to capture the whole string, and play with that in a rule where it is easier to work.
But if you have never used a rule that might not help.

REGEX is one of many choices.

They are all optional add-ons, and will not work until you install them.

Thank you! I gona try it with rules, I think its the better way.

Screen shots are pretty useless for the most part. Please click on the “Code” tab and paste in the text you find there using code fences in the future.

code goes here

But I was able to zoo in enough to see that your transformation string on the State Transformation is very incorrect, at least for how OH does REGEX.

Firstly, what’s with the [ ]? That’s nowhere in the docs and is very much unneeded. In fact, there is a REGEX example in the description of that field and you see no [ ] surrounding the string there.

Secondly, in OH a REGEX follows two rules.

  1. The expression must match the full String of the message. Even if the String is a full web page, the expression must match the entire web page, not just a single line.

  2. Only the first matching group gets returned.

You are following rule 1 but not rule 2. You have two matching groups, one that matches everything and the other that matches the digits.

Another problem is you’ve unnecessarily escaped the \. You don’t need to do that in the UI typically. The value is escaped for you. So the \\d is probably looking for the string “\d” rather than trying to match a digit.

Something like this should work (assuming the message follows your example.


If you’ve stuff potentially before or after the digits:


You don’t really need to over specify the expression here. There’s no need to worry too much over matching digits and such if you know that the stuff beteen the “=” and “;” will always be a number.

UID: serial:serialDevice:55845d789a:84bac10a71
label: Arduino
thingTypeUID: serial:serialDevice
  patternMatch: Arduino;
bridgeUID: serial:serialBridge:55845d789a
  - id: pHMeter
    channelTypeUID: serial:string
    label: pHMeter
    description: ""
      stateTransformation: "REGEX: .*pH=(.*);"

This is my Code, still dont know whats wrong…

I’m pretty sure there should not be a space between the : and the start of the expression. It’s going to look for strings that start with a space if you do that.

Also make sure you’ve installed the REGEX add-on.

I removed, the space in the expression and checked again if the Add-On is installed. Everything is fine but still no result. The Item shows me always the value NULL, maybe I need to edit something in the Item configurations. The type of the Item is String. What kind of Informations could I send you to find the mistake.

And there has been a new message published to this Channel after making your changes? It won’t retroactively apply the transform to old messages.

Did you try REGEX:.*ph=(.*);.* like I mentioned above? If there is anything after the ; the expression won’t match (see rule 1 in my reply above).

Yes, it changes every 10s, +/- 0.01 in the value and yes I tried it too.

And there are no errors or other pertinent info in the logs?

No, this is everything what the logs show me. :frowning:

2022-11-12 18:19:16.993 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:55845d789a:data triggered PRESSED

2022-11-12 18:19:16.999 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from Arduino;pH=4.12;

 to Arduino;pH=4.11;

2022-11-12 18:19:18.993 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:55845d789a:data triggered PRESSED

2022-11-12 18:19:18.999 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SerialBridge_StringData' changed from Arduino;pH=4.11;

 to Arduino;pH=4.12;

I did such a stupid mistake… I was trying to write the stateTransformation into the serial Device, I wrote the expression now into the String Data Item and it worked.

Thank you for your Time and Help.