Serial Binding and Regex - no transformation

  • Platform information:
    • Hardware: RPI4
    • OS: RapsOS; Docker
    • openHAB version: 3.0


I have some problem with new Serial binding. Communication with Arduino USB serial and Regex transform not works as espect. I’m doing something wrong, but after couple of hours I don’t know what. I need help.

From Arduino I sending command (temperature) in this format (example):


First column is sensor ID and second is value.

Things file:

Bridge serial:serialBridge:sensors [serialPort="/dev/ttyUSB0", baudRate=115200, charset="ASCII"] {
    Thing serialDevice temperatureSensor [patternMatch="0;.*"] {
                    Type number : temperature [transform="REGEX:0;(.*?)"]

    /* Test thing. */
    Thing serialDevice irreceiver [patternMatch=".*"] {
                    Type string : ircode [transformationPattern="REGEX:0;(.*?)"]

Each of Thing has one Item:

Number   Temperature_Living_Room   "Teplota"   { channel="serial:serialDevice:sensors:temperatureSensor:temperature", homekit="TemperatueSensor" [minValue=5, maxValue=40] }

String   IR_Receive_Code  "IR kód"   { channel="serial:serialDevice:sensors:irreceiver:ircode" }

I set every modules containing “serial” in name to “log:set trace”. Same for Regex.This is everything in log:

2021-01-27 17:24:30.225 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:sensors:data triggered PRESSED
2021-01-27 17:24:30.227 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'IR_Receive_Code' changed from 1;52.20 to 0;23.50
2021-01-27 17:24:30.230 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'IR_Receive_Code' changed from 0;23.50 to 1;52.30

Item “Temperature_Living_Room” is not set and IR_Receive_Code is set as log say.

I expect value “23.5” in “Temperature_Living_Room” as number and “23.5” in “IR_Receive_Code” as string…

What I’m doing wrong?

The examples in the documentation are wrong, you need to use stateTransformation instead of transform

You also need to replace transformationPattern with stateTransformation

so that explains …

can’t directly link number channel to String Item.
The documentation shows number type channels, which is what you need (when the other stuff is fixed)

Like a charm!

Thanks a lot :slight_smile:

==> /opt/openhab/userdata/logs/events.log <==
2021-01-27 18:27:38.891 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:sensors:data triggered PRESSED

==> /opt/openhab/userdata/logs/openhab.log <==
2021-01-27 18:27:38.896 [DEBUG] [.internal.RegExTransformationService] - about to transform '0;23.60' by the function '(.*?)'

==> /opt/openhab/userdata/logs/events.log <==
2021-01-27 18:27:38.903 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Temperature_Living_Room' changed from 23.8 to 23.60

Number channel (temperature) is link to number item (Temperature_Living_Room). Its OK.
@MikeJMajor has a solution :slight_smile:

Thank you