[SOLVED] Help need! modbus read but not shown in sitemap

I’m using openhab for some time now and I’m very happy with it. Just started with modbus binding to integrate my new wall switches into my home automation. So I have very little knowledge about modbus and need help on this.

I’m able to read data from modbus but for any reason I’m not able to assign it to items and can’t show it on my sitemap.
According to the log you can see that the value for “light1” is set to “1” but in sitemap it’s still “OFF”. Also the “temperature” (temp/kitchenTemp) is read correctly from modbus with value of “00 f6” (dec 246 is equal to 24.6 celcius). Same with “humidity” (hum/kitchenHum) with value of “01 b9” (dec 441 is equal to 44.1 %). All values are correct but not displayed at all in sitemap. Also need to write them back from sitemap - but this is next step. :blush:

Please help!!

many thanks!

system:

  • openHABianPi with openHAB 2.4.0-1 (Release Build)
  • updated to latest updates
  • binding-modbus - 2.4.0

modbus.things:

Bridge modbus:tcp:kitchen [ host="192.168.1.150", port=502, id=1] {
    Bridge poller coils [ start=0, length=6, refresh=100, type="coil" ] {
        Thing data light1 [ readStart="0", readValueType="bit", writeStart="0", writeValueType="bit", writeType="coil"]
        Thing data light2 [ readStart="1", readValueType="bit", writeStart="1", writeValueType="bit", writeType="coil"]
        Thing data light3 [ readStart="2", readValueType="bit", writeStart="2", writeValueType="bit", writeType="coil"]
        Thing data light4 [ readStart="3", readValueType="bit", writeStart="3", writeValueType="bit", writeType="coil"]
        Thing data light5 [ readStart="4", readValueType="bit", writeStart="4", writeValueType="bit", writeType="coil"]
        Thing data light6 [ readStart="5", readValueType="bit", writeStart="5", writeValueType="bit", writeType="coil"]
    }
    Bridge poller inputRegisters [ start=0, length=2, refresh=1000, type="input" ] {
        Thing data temp [ readStart="0", readBalueType="int16", readTransform="JS(divide10.js)"]
        Thing data hum  [ readStart="1", readBalueType="int16", readTransform="JS(divide10.js)"]
    }
}

transform/divide10.js:

(function(inputData) {
    // on read: the polled number as string
    // on write: openHAB command as string
    var DIVIDE_BY = 10;
    return parseFloat(inputData) / DIVIDE_BY;
})(input)

modbus.items:

Switch kitchenSwitch1Light1 "Kitchen Light Switch 1" <light> { channel="modbus:tcp:kitchen:coils:light1:switch" }
Switch kitchenSwitch1Light2 "Kitchen Light Switch 2" <light> { channel="modbus:tcp:kitchen:coils:light2:switch" }
Switch kitchenSwitch1Light3 "Kitchen Light Switch 3" <light> { channel="modbus:tcp:kitchen:coils:light3:switch" }
Switch kitchenSwitch1Light4 "Kitchen Light Switch 4" <light> { channel="modbus:tcp:kitchen:coils:light4:switch" }
Switch kitchenSwitch1Light5 "Kitchen Light Switch 5" <light> { channel="modbus:tcp:kitchen:coils:light5:switch" }
Switch kitchenSwitch1Light6 "Kitchen Light Switch 6" <light> { channel="modbus:tcp:kitchen:coils:light6:switch" }

Number kitchenTemp            "Kitchen temperature is [%d]"    { channel="modbus:tcp:kitchen:inputRegisters:temp:number" }
Number kitchenHum            "Kitchen humidity is [%d]"    { channel="modbus:tcp:kitchen:inputRegisters:hum:number" }

home.sitemap:

            Switch item=kitchenSwitch1Light1
            Switch item=kitchenSwitch1Light2
            Switch item=kitchenSwitch1Light3
            Switch item=kitchenSwitch1Light4
            Switch item=kitchenSwitch1Light5
            Switch item=kitchenSwitch1Light6
            Text item=kitchenTemp
            Text item=kitchenHum

Logging of modbus:

2019-02-24 19:44:48.585 [DEBUG] [handler.ModbusPollerThingHandlerImpl] - Thing modbus:poller:kitchen:coils received coils BitArrayWrappingBitVector(bits=100000) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@190319f[slaveId=1,functionCode=READ_COILS,start=0,length=6,maxTries=3]
2019-02-24 19:44:48.600 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:kitchen:coils:light2 channels updated: {}. readValueType=bit, readIndex=Optional[1] -> numeric value 0 and boolValue=false. Bits BitArrayWrappingBitVector(bits=100000) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@190319f[slaveId=1,functionCode=READ_COILS,start=0,length=6,maxTries=3]
2019-02-24 19:44:48.612 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:kitchen:coils:light3 channels updated: {}. readValueType=bit, readIndex=Optional[2] -> numeric value 0 and boolValue=false. Bits BitArrayWrappingBitVector(bits=100000) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@190319f[slaveId=1,functionCode=READ_COILS,start=0,length=6,maxTries=3]
2019-02-24 19:44:48.625 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:kitchen:coils:light5 channels updated: {}. readValueType=bit, readIndex=Optional[4] -> numeric value 0 and boolValue=false. Bits BitArrayWrappingBitVector(bits=100000) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@190319f[slaveId=1,functionCode=READ_COILS,start=0,length=6,maxTries=3]
2019-02-24 19:44:48.634 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:kitchen:coils:light4 channels updated: {}. readValueType=bit, readIndex=Optional[3] -> numeric value 0 and boolValue=false. Bits BitArrayWrappingBitVector(bits=100000) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@190319f[slaveId=1,functionCode=READ_COILS,start=0,length=6,maxTries=3]
2019-02-24 19:44:48.645 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:kitchen:coils:light6 channels updated: {}. readValueType=bit, readIndex=Optional[5] -> numeric value 0 and boolValue=false. Bits BitArrayWrappingBitVector(bits=100000) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@190319f[slaveId=1,functionCode=READ_COILS,start=0,length=6,maxTries=3]
2019-02-24 19:44:48.655 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:kitchen:coils:light1 channels updated: {}. readValueType=bit, readIndex=Optional[0] -> numeric value 1 and boolValue=true. Bits BitArrayWrappingBitVector(bits=100000) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@190319f[slaveId=1,functionCode=READ_COILS,start=0,length=6,maxTries=3]
2019-02-24 19:44:48.747 [DEBUG] [handler.ModbusPollerThingHandlerImpl] - Thing modbus:poller:kitchen:inputRegisters received registers RegisterArrayWrappingInputRegister(00 f6 01 b9) for request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@440f1e[slaveId=1,functionCode=READ_INPUT_REGISTERS,start=0,length=2,maxTries=3]

It’s the data channels you want for Items; as the debug log is telling you

So you’d use that in your Item channel

Switch ... { channel="modbus:data:kitchen:coils:light1:switch" }

modbus:data: , then refer to the data channel name by bridgename:pollername:dataname: and finally the chosen type of channel

You are my hero!! Works now for the switches like perfect! :tada::tada:

Any idea for the “temp” and “hum” inputRegisters?

Well, the same fix aplies to Item channel spec of couse.

Plus there’s a typo on your actual data things

If there’s still trouble, we’d better see latest data thing and Item definitions, and anything relevant in openhab.log and events.log

Thanks so much for your quick help. Didn’t see the typo. Works now perfectly!!!

Just need to fix now the function “transform/divide10.js”. Doesn’t work currently. Just gives back the full value and not divide by 10. But will find the bug. :wink:

You do need to have the javascript transform service installed.

Just forgot this. Thanks, now all is working! :yum::yum:

hi, i’ve similar problem, everything works from paperui but not configuring by files.

I’m just making simple test, but from sitemap no way to make it work.

things:

Bridge modbus:tcp:localhostTCPex2 [ host="192.168.1.3", port=510 ] {
    Bridge poller coil [ start=8192, length=2, refresh=1000, type="coil" ] {
    Thing data Coil8192 [ readStart="8192", readValueType="bit", writeStart="8192", writeValueType="bit", writeType="coil" ] }  } 

items:

Switch iCoil8192 “Coil 8193” { channel=“modbus:data:localhostTCPex2:coil:Coil8192:switch” }

sitemap:
Switch item=iCoil8192

I also noticed that in paper ui channel are not enabled by default!
very simple but i can’t understand wht’s wrong.

thank you for help

What doesn’t work? No data display? Unexpected data display? No command function?

Go at it one step at a time.

Does your xxx.things file load successfully? Your openhab.log will tell you.
Does your xxx.items file load successfully? Your openhab.log will tell you.
Does your xxx.sitemap file load successfully? Your openhab.log will tell you.

What happens when you click the switch widget in your UI? Your events.log will tell you, if it doesn’t then look in your openhab.log Show us what you get.

This is the “control” tab perhaps? What Item are you looking at there? It’s often difficult to tell, click it and see what your events.log tells you.

There is no enable/disable for channels. What is this about?

Thank you!
Log files help me! just end of file missing inj item file! i don’t know why!

thanks a lot!

Items parser complaining about unexpected EOF is about an error earlier in the file. Mistakes with brackets and quote marks can be hard to spot. Using VSCode editor with openHAB extension highlights syntax errors.