Processing rs232 commands

OpenHAB version: 4.1 / Openahabian / RPI4
It is a more question wat is in your opninion the best approach for this issue.

I have a serial device where the pressbuttons in house are connected to.
So I receive 2 commands from that device.
There are a little similar. The idea was in the past that it should also stay working without the special things (past my pc , now openhab).
Command like:
B0202 as soon when that processor can determine which button it is.
followed by B02005.

  • B is for the several loops (wires) in house. (From A to L possible)
  • 02 - Button 02 (01 -12 possible)
  • 02 (first) Or 00-Off 01On 02-Switch
    Or 005 (second) the time the button is pressed

So there are a lot of possibilities. Even short and long pressed.
How would be a nice way to process these several possibilities (A01 A02 … short / long)?
I can put all in the routine that is triggered after the serial device is changed.
I can make for all pushbutton were you can put also a trigger.
It is a bit and also not.
Has someone a good advise?

Thanks
Pieter

How are you getting these into OH? Though a binding? Which binding? How is the Thing configured?

Ideally I would set this up as an event Channel which just passes the string through. A rule triggered by the events will parse the string to determine which button it represents and which command and issue the right command to the right Item in OH in response.

But that depends on whether the binding supports an event Channel in the first place.

I use the Serial binding with a serial device, so that I can make trough the pattern a difference between the first and second string.
Then with a trigger on the update of that channel of that serialdevice.
At this moment, I’m thinking of 2 switch command to handle those.
Then it is a long routine all in code (no gui) but I know what I’m starting.

OK, the Serial binding’s data Channel won’t work for this as it only sends PRESSED and doesn’t send the original data.

So I’d create two Switch Chanels for each button, one for pressed and one for double pressed.

For the stateTransformation add a REGEX to match the first part of to the Switch name and then a MAP to match the second part.

REGEX:(B02[0,1]{2})

and set the onValue to 'B0200and theoffValuetoB0201`.

The REGEX will only match for messages B0200 and B0201. If the REGEX doesn’t match the message will be ignored.

The second Channel for the switch to detect the double press will use

REGEX:(B02005)

The REGEX will only match “B02005” and set the onValue to “B02005” so that message is converted to ON.

Use an Expire metadata on the Linked Item for double press to set it back to OFF, or just look for updates to the Item to trigger your rules.

You might be able to use one of the button press profiles with this configuration. I’ve no experience with that.

That would be the Thing/Channel way to implement it.

Ok thank you for the feedback
I gone play in that direction with a few possible button and compare the 2 approaches.
In function of what is the easiest to maintain and to adapt to new needs of the house.
Thanks