Send command to serial port and receive a answer

I’m new to openhab and I want ask how to send a HEX command to serial port and then read a HEX answer from external device.
I already installed a serial binding and can see that’s online. But where add a command?
Thank you for help

1 Like


Are you using config files or GUI to setup?

There is an example in the Binding docs to get you started.

You may need to Transform you HEX using JS transformation.

maybe first I will try to make more detail explanation:
Via serial/usb port I have connected zone heating unit, which is able share data about temperature in each room and also is possible send a command for temperature change. To get data or make a temperature change is necessary send a HEX command and depends on this command heating unit will answer, also HEX. This HEX answer must be pocessed to get a usable data.
I know, it’s hard task for me, because I’m new to openHab, but somehow I must start and this is a key point for me.
I’m trying study guides and find a correct way, but without community help I think I don’t have a chance.
What I already did is, that I make a serial brige :

But there I can’t see a chance to send a HEX. So I’m now really not sure which next steps to do and I will be grateful for any help and advice. Doesn’t make sense if I will use a GUI or config files (not sure what is better way).


I don’t know anything about the serial bridge, but I can explain a concept.

A Bridge is simply a method of enabling a link between openHAB and the device / system you want to talk to.

You then need a Thing to represent the device.

This Thing will have a channels / triggers that represent the features of the Device you’re going to be talking to.

Items then attach to a Channel of a Thing which enables communication.

It seems a bit over complex to start with, but there are really good reasons why it’s done this way.

I would suggest that you now need to add a Thing to represent your heating device/s, that all look to the Bridge you’ve added.

1 Like

Aha, I understood from the tutorial that thing is this heating main unit representated by serial bridge :frowning:
And item is radiator head with temperature measurement and open/close function to correct a temperature :frowning:
Wrong understanding from my side ?
Also can see that thing is online :


You’re halfway there.

Now that you know a little more about how Bridge Things and Device Things interact.

Take a slow read of the docs again.

As @denominator suggests, there is an example in there to get you started.

Then do a search of the forum for examples.

Yes, here is a example, but in text mode and I think I’m in UI mode. Is it possible to a copy and place somewhere to see how it works ?

Check again tutorial and forum

ok I found my error
confused me this “online”:

but this is a brige and not a thing, so I pressed again + button a under serial binding:

choose a serial device:

but what isn’t clear for me now is what to place as pattern match (required):

as patern I place “test” and press create thing
then I have two :

under thing Heating main unit I go to channels:

and try add channel
strange that there is only receive command:

and rest isn’t clear for me…

You really are progressing well.

Please provide more information about the device you want to integrate into the system like a link to operation manual. The more information you provide the easier it is to get help.

So you have worked out the Bridge

Now you need to have the thing with a unique name and pattern.
The pattern is the bit of data at the front of each message.
This is the incoming data from the heating device to the serial port.

After you have a working thing you should create a string channel that will just display all of the data that comes into that thing.

Using the GUI or Config files is a personal choice and I will help if you decide either way. It is much harder to make a mistake in the GUI

Here is a serial thing from example

    Thing serialDevice relay [patternMatch=".*"] {
            Type switch : serialRelay [onValue="Q1_ON\n", offValue="Q1_OFF\n"]

Change your pattern match from test to .*
That will allow any message on serial bus to your thing
Add a Channel to your thing of type string with no other settings.
See if your device is sending data to openHAB

1 Like

Communication protocol I have complete from supplier, but not in the English, so I will try translate and then answer on all questions if necessary.

Request command :

B0 B1 B2 B3 B4 B5 B6 B7 B7+n B8+n B9+n B10+n

DLE = 10H, SOH = 01H
BUSH ,BUSL main unit address, in my case: BUSH = FFH ,BUSL = FFH
RAMH,RAML - memory address of main unit where from we will read/write a data
DC - command code. If DC is n8 means : 8 = read data and n : send ((n+1)*2) byte of data
if DC is nC : write data, D0 … Dn from adress RAMH:RAML
D0 … Dn data of command
ADDS control sum (ADD B0 … B7+n) + XOR 0xAA
XORS control sum (XOR B0 … B7+n) + XOR 0xAA
0FFH end byte

answer from main unit in the next post :slight_smile:

answer from main unit :

B0 B1 B2 B3 B4 B5 B6 B6+n B7+n B8+n B9+n B10+n

0FFH, 0FFH - start bytes
DLE = 10H, ETB = 17H
BUSH ,BUSL main unit address, in my case: BUSH = FFH ,BUSL = FFH
D0 … Dn - data
S0, S1 - answer status. when both 0x00 = all ok, when both 0x04 = unknown address or command, not executed
ADDS = control sum (ADD B2 … B8+2n)
XORS = control sum (XOR B2 … B8+2n)

ok it’s answer. Next post important memory addresses for reading and examples

memory addresses (not all only some):

0060H-006FH - real temperature address 1-16

0070H-007FH – údaje vysílané na sběrnici ETATHERMnext informations
b0-b4 : requested temperature address 1-16
b5-b7 : regime of address
000: summer regime
001: HDO (PWM)
010: Operation change
011: keep temperature
100: via program
111: not used or bad type

1010H-101FH - name of main unit (format: NAME)
1030H-1037 - name address 1 [string ends 0)
1038H-103F - name address 2 [string ends 0)
1040H-1047 - name address 3 [string ends 0)
1048H-104F - name address 4 [string ends 0)
1050H-1057 - name address 5 [string ends 0)
1058H-105F - name address 6 [string ends 0)
1060H-1067 - name address 7 [string ends 0)
1068H-106F - name address 8 [string ends 0)
1070H-1077 - name address 9 [string ends 0)
1078H-107F - name address 10 [string ends 0)
1080H-1087 - name address 11 [string ends 0)
1088H-108F - name address 12 [string ends 0)
1090H-1097 - name address 13 [string ends 0)
1098H-109F - name address 14 [string ends 0)
10A0H-10A7 - name address 15 [string ends 0)
10A8H-10AF - name address 16 [string ends 0)

next examples

10H 01H FFH FFH 00H 60H 08H 02H D3H D1H FFH – main return 2B – real temperatures for first and second address

["0x10","0x01","0xFF","0xFF","0x10","0x10","0x78","0x02","0x03","0xC1","0xFF"] - name of main unit

["0x10","0x01","0xFF","0xFF","0x10","0x50","0xF8","0x02","0xC3","0x01","0xFF"] - name address 5-8

["0x10","0x01","0xFF","0xFF","0x00","0x60","0x78","0x02","0x43","0xA1","0xFF"] - real values

hope will help to understand

As a first step I want send let say request for addresses names :
and look if answer will arrive.

thing I have :

also channel was created:

but heating main unit will not send data without request

your code:

Thing serialDevice relay [patternMatch=".*"] {
            Type switch : serialRelay [onValue="Q1_ON\n", offValue="Q1_OFF\n"]

it’s from GUI? Where I can find it ?

Your Pattern will be your main unit address. If its the only thing on that seral bus just leave it as .*

That is a config file example. it can give you clues as to what to put where.

To see the “Data Received” channel create a string item and link it to it.

Create a way to poll the channel.
As always this can be done more than one way.

You can create a rule and have it run at a set time say 10 sec and you create a script DSL rule

The command would be


Another way is to create another switch channel and set the on value to the string you want to send.
Then create an item to control the on off of the channel.

use code fences to preserve text formatting so " is not changed to ”


I suspect you have nearly got it and only need a little help to get it going.

What I would do is connect your serial port up to another serial port on your computer or to your main computer and have a terminal that you can see the data coming out of your openHAB is correct. You can do it with an arduino or ftdi or usb to rs232. Whatever you have lying around. Just know the voltage that the device is using so you don’t have any issues.

It would also help to connect your heating up to a console so you can just type the bare code in to see what you get back. Only one application can connect to a serial port at a time.

ok, I think I have correctly thing and also string channel and string item:

What isn’t clear for me, where I can see a received string. Any label…

Regarding a way to poll the channel :
I want learn both ways, means create a rule and also switch, because some commands I want send only when user will click ans some when some other conditions are reached.

As a first I want try switch way:
So I created next channel switch and added on command:

and then item switch :

under this item I can see a analyse :

but where to see a response ?

I still don’t understand where from you have this data :


I know it’s example, but I don’t know where it’s used, because similar code I can’t see anywhere.

Also like this code :


Thats a example for config files

Type is a switch channel with the name serialRelay when turned on its sends Q1_ON \n is the serial command for newline. \r is Carriage-return

Your Item looks like the On Value may not be formatted correctly

Change to


may need a \n or \r after command to operate

Next Create new rule with cron trigger like

Then Add action / run script / Rule DSL

Then add command - I am not sure of exact command you want to send maybe


ok rule is done :

but status is still IDLE, even if i click the arrow

and were I can monitor received string ? (I need monitor sending switch and received data together)

Now I’m working on the next PC connection to be able “listen” what we are sending