[Solved] Split datasets received via serial connection from Arduino

first I would like to emphasize what a great project this is!
Many of the articles from the documentation and found in the forum helped me to get that far, that my Arduino is “heard” by openhab running on my raspberry running OH1 1.83. I’m able to display (and update) temperature data in form of strings
T1 20.45
T2 22.05

on the webpage of “myopenhab”-installation. Data is received via serial line from the Arduino (with several DS18B20) using the serial binding.

Extract from items-file:

String     Temperature        "My Temp. Sensor [%s]"    <serial>       { serial="/dev/ttyAMA0@9600" }

Extract from sitemap:

Text item=Temperature

On the webpage it looks like this:

My Temp. Sensor T2 22.05

while the last part is continiously changing between T1 and T2.
So far as expected…

Now my question is how to handle and format the output in that way that I get:

  • a singel line per key/value-pair
  • only displaying value and omitting the key

Means something like:

My Temp. Sensor1       20.45 °C
My Temp. Sensor2       22.05 °C

I tried with regular expressions (appended to the serial port statenment in “items”) already what looks promising, but did not succeed - probably due to my lack of experience.

Thanks in advance for any hint and kind regards,

My understanding is you have two temperature sensors (probably more given the “…”).

Create two Items, one for each sensor. Then, like you anticipate, use a REGEX.

I believe this will work for T1:


And this for T2:


These are a bit loosie but I think they will match appropriately. They basically mean"

Match the line that has any number of any characters, a T1, any number of any characters and give me everything from the first digit to the end of the line.

1 Like

Hi Rich,

thanks for the very quick answer!
Unfortunately it does not work with this line (or did I get something wrong?)

String     Temperature        "Temp Sensor T1 [%s]"    <temperature>       { serial="/dev/ttyAMA0@9600,REGEX(.*T1.*(\d.*))" }

parsing the serial port gives an error (Binding configuration of type ‘serial’ of item ‘Temperature‘ could not be parsed correctly.)

Just to test anything, I reverted the backslash you proposed into a forward slash ( I’m under linux, does this matter?)
I got the following result:

[DEBUG] [i.s.RegExTransformationService:42   ] - about to transform 'T1 20.31

' by the function '.*T1.*(/d.*)'
23:50:37.193 [DEBUG] [i.s.RegExTransformationService:48   ] - the given regex '^.*T1.*(/d.*)$' doesn't match the given content 'T1 20.31

' -> couldn't compute transformation
23:50:37.205 [INFO ] [runtime.busevents             :26   ] - Temperature state updated to T1 20.31

Any other idea maybe?

I’m not familiar with this binding so I’m not sure what to do from here. The backslash is needed. The “\d” means a numerical digit in REGEX.

The first error complains about the config String not being valid. It looks right to me though.

Solved by using a rule, found in this post dealing with a similar problem: