Modbus Poll service

Platform: raspberry pi3
Openhab 2
Modubus binding: 2.4.0
Hi all,
I have installed Modbus Binding and create modbus.cfg in /etc/openhab2/services/
and create modbus.items and finally file.sitemap.
I also restarted but from the modbus (serial) not
there is communication, in the modbus.cfg file I put
poll = 1000.
My question is:
is what I have done for afre sufficient so that every second the mobbus interrogates the slave (s)?
Or is something missing to make sure that the polling starts?

You´ll need to post your cfg. Without it´s highly difficult to suggest anything.
You should also keep an eye on the log, if there is any kinds of activitet related to modbus.

Thanks for reply, my cfg is:


#this is an input device

#device ID = 1

#the starting register for the Voltage variable is 0 (device dependant)

#the variable is two 16bit world lenght (4 byte)

#it's a float32 variable

#for each other variable it needs a similar configuration set


Your config is for the old modbus binding 1 - 1.13.0 and i think you installed the new binding-modbus - 2.4.0 your config should look something like this


Bridge modbus:serial:slave10 [ port="/dev/ttyUSB0" ,id=10 , baud=38400, stopBits="1", parity="none",timeBetweenTransactionsMillis=1,dataBits=8, encoding="rtu" ]{ 
Bridge poller slave10Inputs [ start=0, length=16, refresh=500, type="discrete" ]{ 
       Thing data di00 [ readStart="0", readValueType="bit" ]
       Thing data di01 [ readStart="1", readValueType="bit" ]
       Thing data di02 [ readStart="2", readValueType="bit" ]
       Thing data di03 [ readStart="3", readValueType="bit" ]
       Thing data di04 [ readStart="4", readValueType="bit" ]
       Thing data di05 [ readStart="5", readValueType="bit" ]
       Thing data di06 [ readStart="6", readValueType="bit"]
       Thing data di07 [ readStart="7", readValueType="bit" ]
       Thing data di08 [ readStart="8", readValueType="bit" ]
       Thing data di09 [ readStart="9", readValueType="bit" ]
       Thing data di10 [ readStart="10", readValueType="bit" ]
       Thing data di11 [ readStart="11", readValueType="bit" ]
       Thing data di12 [ readStart="12", readValueType="bit" ]
       Thing data di13 [ readStart="13", readValueType="bit" ]
       Thing data di14 [ readStart="14", readValueType="bit" ]
       Thing data di15 [ readStart="15", readValueType="bit" ]

You can read the doc of the new binding for more info

1 Like

I ask you to be patient but I am at the very first time that I use OH,
Is it enough to create a .things file with the contents of Rado1, do restart and then the serial line starts polling?
Or is there another configuration to do because polling (modbus starts)?

yes you have to make a .things file but you have to set it to your needs i have 16 DI i dont know what you have?You can see in paper ui configuration -things if the regular pol, modbus data and modbus slave is online.When they are online you have to make a .items file to read your inputs this should look like this

Group Verlichtinginputs <verlichting>

Contact verlichting1 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di00:contact" }
Contact verlichting2 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di01:contact" }
Contact verlichting3 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di02:contact" }
Contact verlichting4 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di03:contact" }
Contact verlichting5 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di04:contact" }
Contact verlichting6 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di07:contact" }
Contact verlichting7 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di05:contact" }
Contact verlichting8 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di06:contact" }
Contact verlichting9  "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di08:contact" }
Contact verlichting10 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di09:contact" }
Contact verlichting11 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di10:contact" }
Contact verlichting12 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di11:contact" }
Contact verlichting13 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di12:contact" }
Contact verlichting14 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di13:contact" }
Contact verlichting15 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di14:contact" }
Contact verlichting16 "[MAP(]"  { channel="modbus:data:slave10:slave10Inputs:di15:contact" }

Then you have to make a .sitemap file that looks liken this

Frame label="keuken" {
        Switch item=keuken1 mappings=[ON="AAN"]
        Text item=verlichting1 icon="light" 
        Switch item=keuken2 mappings=[ON="AAN"]
        Text item=verlichting2 icon="light"
        Switch item=keuken3 mappings=[ON="AAN"]
        Text item=verlichting3 icon="light" }
Frame label="living" {
        Switch item=living1 mappings=[ON="AAN"]
        Text item=verlichting4 icon="light"
        Switch item=living2 mappings=[ON="AAN"]
        Text item=verlichting5 icon="light"
        Switch item=livingwand mappings=[ON="AAN"]
        Text item=verlichting6 icon="light"}

Frame label="eetkamer" {
        Switch item=eetkamer1 mappings=[ON="AAN"]
        Text item=verlichting7 icon="light"
        Switch item=eetkamer2 mappings=[ON="AAN"]
        Text item=verlichting8 icon="light"}

Frame label="bureau" {
        Switch item=bureau mappings=[ON="AAN"]
        Text item=verlichting9 icon="light" }

Frame label="inkomhal" {
        Switch item=inkomhal mappings=[ON="AAN"]
        Text item=verlichting10 icon="light"} 

If it is not working you have to show the log file’s

Thank you because I finally managed to make something work.
What I would like to do is manage the board of the image attached in a complete way both reading the inputs and activating the outputs.
To read the inputs you must send a “02” "read Discrete input with starting address 0x0000 and n of input 0x0000 then

Bridge poller slave1Inputs [start = 0, length = 0, refresh = 1500, type = "discrete"] {

Therefore the modbus in binary:

request: 01 02 00 00 00 00 crcH crcL
response: 01 02 01 01 crcH crcL

As you can see, the answer is only one byte

01 = ADR slave
02 = function
01 = N. bytes
01 = Data (in my case Input 1 is HIGH)

So the first problem is how to extract the data being only a byte?
I have also seen readstart X.Y but I seem to have understood that it serves to extract a certain bit but from a 16-bit data not 8-bit. Or am I wrong about something?
Once this is done I should then write with the function 05 (write single coil) to activate or deactivate the relays

The response to a Modbus FC02 comes in bits. ‘Discrete’ inputs are binary inputs, represented in a bit.
You don’t have to worry about getting the bits out of a byte, that is the binding’s job.

You configure the poller to read-poll discrete inputs by register address.
You configure data things to choose which discrete input as a bit by register address.
You connect an openHAB Item to the channel of that data thing, usually as a switch or contact type.

I was able to read the discrete register,
in the .thing in Bridge poller I store in

di00 bit 0
di01 bit 1

in .items associo in questo modo:

Contact in1   { channel="modbus:data:slave1:slave1Inputs:di00:contact" }
Contact in2  { channel="modbus:data:slave1:slave1Inputs:di01:contact" }

In .sitemap

Frame label="uno" {
    Text item=in1  
	Text item=in2 

Now how do I put the light icon (light-on light-off) and what state changes according to the value read (in1, in2 etc).
I read we talk about dynamic icons (
but I didn’t understand how to configure the .sitemap (if that’s where I need to change)

Thank you

I’ve no idea what that is. It’s no use in an xxx.things file.

But that’s good, you got something working.

Okay, let’s guess that you want to display those Contact Items with a lightbulb icon, and you want to have the OPEN/CLOSED state displayed as different words.

Amend your Item

Contact in1 "text label [MAP(]" <myLamp> { channel="modbus:data:slave1:slave1Inputs:di00:contact" }

We’ve added an <icon> part, names myLamp.
You will need to provide three icons in /conf/icons/classic/
myLamp.png (or .svg, depending which you use)
You must provide a default icon, and you should provide one for each state.
If the state doesn’t match (NULL for example) you get the default.
You can copy your icons from a set like this

We’ve also added a label with a mapping part [MAP(]
That tells the mapping service to use the state to look up a new description in a little file named mywords.
The %s part says to display it as a string.
You will need to install the mapping service in your openHAB.
You will need to create a file in /conf/transform/


Every part of this is in the documentation and many examples in this forum.

I seem to have done everything right, but there are these problems:

  1. the word on / off (input 1) when the state changes bit0 without page refresh changes. That other referred to at bit1 (Input 2) changes only if I refresh the page
  2. the icons do not change state always remains presumed light-on or light default.
    my objects below:


Contact in1 "Ingresso 1 [MAP(]" <light> { channel="modbus:data:slave1:slave1Inputs:di00:contact" }
Contact in2 "Ingresso 2 [MAP(]" <light> { channel="modbus:data:slave1:slave1Inputs:di01:contact" }




Bridge modbus:serial:slave1 [ port="/dev/ttyUSB0" ,id=1 , baud=9600, stopBits="1", parity="none",timeBetweenTransactionsMillis=1,dataBits=8, encoding="rtu" ]{ 
Bridge poller slave1Inputs [ start=0, length=2, refresh=1500, type="discrete" ]{ 
       Thing data di00 [ readStart="0", readValueType="bit" ]
	   Thing data di01 [ readStart="1", readValueType="bit" ]


sitemap mysitemap label="My home automation" {
Frame label="uno" {
    Text item=in1  
	Text item=in2

thanks for your patience

Not really sure what you mean there. Various UIs can be reluctant to refresh, which one do you use?

What is the filename of your sitemap, it must match what you put in first line
sitemap mysitemap
i.e. filename should be mysitemap.sitemap

light is a default icon name that comes with openHAB. The default light iconset does not include light-open.svg or .png or light-closed.svg so it isn’t going to work with a Contact Item. This is why I described setting up your own custom icons using a name that isn’t one of the default icon names.

You need to set up in PaperUI for your ordinary UI to use svg or png icons