Solved: Modbus-tcp binding help - no values in openhab

Hi there,
for weeks I’m trying to get the modbus binding to work
with our central heating. Our central heating has a modbus-tcp interface, it’s configured and working with a modbus-client from my computer.
Data is in modbus holding register at 40210 and 40211.
I can get the wanted values in openhab, the sitemap always shows the following:
holding210: 0
holding211: 0

I set up the following in openhab:

modbus.things

    Bridge modbus:tcp:holzheizung [ host="192.168.11.240", port=502 ] {
     Bridge poller holding [ start=210, length=2, refresh=60000, type="holding" ] {
        Thing data holding210 [readStart="210", readValueType="int16", readTransform="default"]
        Thing data holding211 [readStart="211", readValueType="int16", readTransform="default"]
    }
}

heizung.items

Number holding210 "Modbus1 [%d]" {channel="modbus:data:holzheizung:holding:holding210:number"}
Number holding211 "Modbus2 [%d]" {channel="modbus:data:holzheizung:holding:holding211:number"}

Sitemap

Text item=holding210
Text item=holding211

I set the log level to debug for the following components

  • org.openhab.binding.modbus
  • org.openhab.io.transport.modbus
  • net.wimpi.modbus

When I have a look at the debug log, the following appears (Note, that it is getting a value from modbus (483)!):

2019-11-11 12:06:02.646 [DEBUG] [rt.modbus.internal.ModbusManagerImpl] - Executing scheduled (60000ms) poll task BasicPollTaskImpl@50de34eb[request=ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@7c4da78f[slaveId=0,functionCode=READ_MULTIPLE_REGISTERS,start=210,length=2,maxTries=3],endpoint=ModbusTCPSlaveEndpoint@4469cab2[address=192.168.11.240,port=502],callback=org.openhab.binding.modbus.internal.handler.ModbusPollerThingHandlerImpl$ReadCallbackDelegator@18d1e3a6]. Current millis: 1573470362646

2019-11-11 12:06:02.647 [DEBUG] [wimpi.modbus.net.TCPMasterConnection] - connect()
2019-11-11 12:06:02.675 [DEBUG] [handler.ModbusPollerThingHandlerImpl] - Thing modbus:poller:holzheizung:holding received registers RegisterArrayWrappingInputRegister(00 00 01 e3) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@7c4da78f[slaveId=0,functionCode=READ_MULTIPLE_REGISTERS,start=210,length=2,maxTries=3]

==> /var/log/openhab2/events.log <==
2019-11-11 12:06:02.677 [vent.ItemStateChangedEvent] - holding211 changed from 0 to 483

==> /var/log/openhab2/openhab.log <==
2019-11-11 12:06:02.678 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:holzheizung:holding:holding211 channels updated: {modbus:data:holzheizung:holding:holding211:number=483}. readValueType=int16, readIndex=Optional[211], readSubIndex(or 0)=0, extractIndex=1 -> numeric value 483 and boolValue=true. Registers RegisterArrayWrappingInputRegister(00 00 01 e3) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@7c4da78f[slaveId=0,functionCode=READ_MULTIPLE_REGISTERS,start=210,length=2,maxTries=3]

==> /var/log/openhab2/events.log <==
2019-11-11 12:06:02.682 [vent.ItemStateChangedEvent] - holding211 changed from 483 to 0

==> /var/log/openhab2/openhab.log <==
2019-11-11 12:06:02.682 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:holzheizung:holding:holding210 channels updated: {modbus:data:holzheizung:holding:holding210:string=0, modbus:data:holzheizung:holding:holding210:number=0}. readValueType=int16, readIndex=Optional[210], readSubIndex(or 0)=0, extractIndex=0 -> numeric value 0 and boolValue=false. Registers RegisterArrayWrappingInputRegister(00 00 01 e3) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@7c4da78f[slaveId=0,functionCode=READ_MULTIPLE_REGISTERS,start=210,length=2,maxTries=3]
2019-11-11 12:06:02.683 [DEBUG] [rt.modbus.internal.ModbusManagerImpl] - Modbus operation ended, timing info: {total: 36 ms, connection: 1, transaction=27, callback=8} [operation ID 02e35b5b-f036-4623-a8f1-19059c1c3776]
2019-11-11 12:06:02.684 [DEBUG] [rt.modbus.internal.ModbusManagerImpl] - Execution of scheduled (60000ms) poll task BasicPollTaskImpl@50de34eb[request=ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@7c4da78f[slaveId=0,functionCode=READ_MULTIPLE_REGISTERS,start=210,length=2,maxTries=3],endpoint=ModbusTCPSlaveEndpoint@4469cab2[address=192.168.11.240,port=502],callback=org.openhab.binding.modbus.internal.handler.ModbusPollerThingHandlerImpl$ReadCallbackDelegator@18d1e3a6] finished at 1573470362684. Was started at millis: 1573470362646 (=duration of 38 millis)

How can I fix this?

Thank you all!

The likelihood is that you have leftover “stuff” hanging around from that.

The setup you’ve shown looks reasonable now - but it sounds like you have been through other versions along the way. Perhaps using PaperUI too?Note that editing Modbus Things without restarting the binding can be problematic - existing pollers may remain running.

So far as I can see from the other info, this Item is getting updates from two different modbus channels. Linking an Item to more than one channel is permissable in openHAB - but of course you don’t want that here!

As a confidence test, before doing anything else I would create brand new Number Items and assign carefully.

Number testhold210 "Modbus1 [%d]" {channel="modbus:data:holzheizung:holding:holding210:number"}
Number testhold211 "Modbus2 [%d]" {channel="modbus:data:holzheizung:holding:holding211:number"}

If that works, there is only a clean-up operation to do.

@rossko57 Thank you so much for your fast response.
Creating a new number items assignment worked perfectly.
Now I have to look at the clean-up operation.
I will post an update

1 Like

After checking PaperUI for anything unexpected, look into “clean cache” perhaps.

@rossko57
After many days of learning and playing with modbus, I got it working.
I created new items, restarted openhab and it’s working perfectly!

Thank you very much for your support.

to share some knowledge:
I checked the connection to my modbus device with this tool
http://qmodbus.sourceforge.net/
then entered it in openhab.

my config looks like this:

Bridge modbus:tcp:holzheizung [ host="192.168.11.240", port=502 ] {
    
     Bridge poller holzheizungAbgas [ start=210, length=2, refresh=60000, type="holding" ] {
        //Abgastemperatur
        Thing data holzheizungAbgas [readStart="211", readValueType="int16", readTransform="JS(divide10.js)"]
    }
    
    Bridge poller holzheizungKessel [start=200, length=2, refresh=60000, type="holding"] {
        //Holzheizung Kesseltemperatur
        Thing data holzheizungKessel [readStart="201", readValueType="int16", readTransform="JS(divide10.js)"]
    }

    Bridge poller holzheizungPufferOben [start=230, length=2, refresh=60000, type="holding"] {
    //Puffer Oben Temperatur
        Thing data holzheizungPufferOben [readStart="231", readValueType="int16", readTransform="JS(divide10.js)"]
    }

    Bridge poller holzheizungStatus [start=204, length=2, refresh=60000, type="holding"] {
    //Status
        Thing data holzheizungStatus [readStart="205", readValueType="int16", readTransform="default"]
    }
}

Most (but not all) Modbus slaves will support reading a block or span of registers that includes registers undefined by the slave maker.
openHAB binding is quite happy to poll blocks without defining data Things for all registers.

So you can restructure along these lines -

Bridge poller holzheizungKessel [start=200, length=6, refresh=60000, type="holding"] {
        //Holzheizung Kesseltemperatur
        Thing data holzheizungKessel [readStart="201", readValueType="int16", readTransform="JS(divide10.js)"]
        //Status
        Thing data holzheizungStatus [readStart="205", readValueType="int16", readTransform="default"]
    }
}

Fewer pollers with larger read blocks lead to greater efficiency on the Modbus serial or TCP channel, and less overheads at openHAB and slave.

I now think a part of your original problem is that you really should avoid duplicate Thing names - keep them unique.

// avoid this
Bridge poller holzheizungKessel [start=200, ...
        Thing data holzheizungKessel [readStart="201", ...

// do this
Bridge poller holzheizungKesselPoll [start=200, ...
        Thing data holzheizungKessel [readStart="201", ...

Of course after any of these changes you will need to review the channels links in your Items, and probably do the reboot stuff again to clear away old pollers etc.