REGEX in serial binding

Im new to openhab, and have been struggeling a few days getting my arduino to send sensordata to my raspberry pi running openhabianpi.

Finally I can see the serialstream in the openhab terminal running:;

cat /dev/ttyACM0

Resulting output is the datafeed from the arduino.

p1 -7.10 p1s t1 19.00 t1s l1 46.00 l1s

The values update every 3 seconds.

I then try to add the following line to default.items

β€œTemp” (Teknisk) { serial="/dev/ttyACM0@9600,REGEX(t1.([0-9.]))" }

This gives me:

[WARN ] [binding.serial.internal.SerialDevice] - Unable to convert regex result 't1 20.00 t1s

l1 41.00 l1s

’ for item Teknisk_Temp to number

Can anyone please help me with the regex-formula?


You can test your regex online

@Tommy_Lian Be aware that the " " definition of serial is a string.
And the \ is the escape sign which lets you use something like " in a string by writing \". As the backslash has a special function you need to escape it, with an escape sign, so \\ wil give you \ in the string.

{ serial="/dev/ttyACM0@9600,REGEX(t1.(\\d+.\\d+))" } 

Hopefully this helps.

1 Like

Thanks a lot.

The code you posted made sense and worked in, but when i added it to the item it still gives error.

this time;

[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model β€˜default.items’ has errors, therefore ignoring it: [7,80]: mismatched character β€˜d’ expecting set null

[7,111]: mismatched input β€˜+’ expecting RULE_STRING

[7,114]: missing β€˜}’ at β€˜d’

[7,115]: mismatched input β€˜+’ expecting RULE_ID

[8,39]: missing RULE_ID at β€˜" (Teknisk) \t \t{channel="’

[8,91]: missing EOF at β€˜"}\r\nNumber Teknisk_PH \t\t\t"’

[12,34]: mismatched character β€˜β€™ expecting β€˜"’

entry in defaoult .items is
{ serial="/dev/ttyACM0@9600,REGEX(t1.(\d+.\d+))" }

That last edit did the trick. Thanks a lot for the help. Regex seems a bit hard to get into. I can use this formula for all my sensors over the serialstream.