OH2.5.0 M1 modbus reset Read/Write coil

Hi

I changed from OH1 to nowOH2.5.0 M1 and started to make all new configs, I got most things to work, but I have an bit trouble with the modbus communication.

What I want to do is I have e.g. an switch for the light, I want to control the light with OH but I also have physical switches which have to work in paralell, so I did in OH1 just change from my PLC the state of the modbus coil if it was changed from the physical switch and OH1 just changed the state. In OH2 i can not do this in this way it looks like OH is always forcing its state and push it every cycle.

I tried to use different read and write adress but the state of the switch was always off and didn’t switched to the state of the read adress.

is there an different way?

here my is my setup:
PLC : Wago 8202 with e!cockpit
OS: 4.15.0-45-generic #48-Ubuntu
Running in an VM
java: OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

default.things

Bridge poller ReadLicht [ start=147, length=16, refresh=100, type="coil" ] {                        
                Thing data xReadLicht01 [ readStart="147", readValueType="bit" ]
}
 Bridge poller RwLicht [ start=33472, length=32, refresh=100, type="coil" ] {   
                Thing data xLicht01 [ readStart="33472", readValueType="bit", writeStart="33472", writeValueType="bit", writeType="coil" ] 
}

default.items

Switch xLicht01     "Licht UG Buero "   <light>  (home, gLight,GF)    {autoupdate="true", channel="modbus:data:endpointTCP:RwLicht:xLicht01:switch"}

You don’t usually want that with polled modbus Items. Set it false.

I don’t really understand your PLC setup. Is it -
the light can be turned on/off by writing to coil 33472?
the status of the light can be read from coil (?) 147

Maybe show us the OH1 setup that worked the way you wanted.

To get it right:

MODBUS address 148 (in the binding 147 because starts with 0 instead of 1 in the Wago) is the read address for the light status?

MODBUS address 33473 (33472 in the binding) in the write address to set the light status?

I use this (length 16 in my example is because I read/write 16 addresses in parallel) (In your example length should be 1?)

Bridge modbus:tcp:ADAM6050 [ host="xx.xx.xx.xx", port=502, id=1 ]
{
    Bridge poller discreteInputs [ start=147, length=16, refresh=1000, type="discrete" ]
    {
        Thing data di00 [ readStart="147",  readValueType="bit"]
    }

    Bridge poller coilsOutputs [ start=33472, length=16, refresh=1000, type="coil" ]
    {
        Thing data do00 [ writeStart="133472", writeValueType="bit", writeType="coil"]
}

items:

Contact ADAM6050_DI00            "Digital Input index 00 [%s]"       { channel="modbus:data:ADAM6050:discreteInputs:di00:contact" }
Switch ADAM6050_DO00             "Digital Output index 00 [%s]"      { channel="modbus:data:ADAM6050:coilsOutputs:do00:switch", autoupdate="false" }

to better Understand what i want to do:

on the PLC I want to do sth. like this

xLicht01 is an global Variable which is mapped to Modbus coil 33472
xDiSPS is an discrete input from the physical switch
xDoSPS is the output to the light relay

(*when OH xLicht is true and I get an impuls from my physical switch i want to switch off the light *)
if xLicht01 and xDiSPS then
  xDoSPS := false; //turn off the light relay
  xLicht01:= false; //switch off the modbus coil so that OH also know the light is off
end_if

so If I try to switch off the xLicht01 it always gets enabled again during each poll. So the current state of the modbus coil does not get read if there is an change. Do i need some extra code sniped to do this?

on OH1 I had it just so:

items:

Switch LICHT4 "Licht EG DU/WC" (Licht,EG,LichtEG,RETAIN, ALL) {modbus="slave3:<17:>17"}

openhab.cfg

# Start 12576 = %MX18.0
modbus:tcp.slave3.connection=10.50.0.30:502
#modbus:tcp.slave3.port=502
modbus:tcp.slave3.type=coil
modbus:tcp.slave3.id=1
modbus:tcp.slave3.start=12576
modbus:tcp.slave3.length=80
modbus:tcp.slave3.valuetype=bit

I would to this step by step.

first:
get all needed MODBUS status to OH items
xDiSPS (read of address 147?)
xDoSPS (write to address 147?)

use my example with a little change to check if this is correct and working

Bridge poller coilsOutputs [ start=147, length=16, refresh=1000, type="coil" ]
    {
        Thing data do00 [ readStart="147", readValueType="bit", writeStart="147", writeValueType="bit", writeType="coil"]
    }

Item

Switch ADAM6050_DO00             "Digital Output index 00 [%s]"      { channel="modbus:data:ADAM6050:coilsOutputs:do00:switch", autoupdate="false" }

should reflect the status. The status is read and write by item change. Try this.

I just want OH to be passive and do all main things in the PLC

the PLC has an read only range all coils bellow 32768 and above are read write.

with your example I put the register 33472 and there I could use it from OH site. so Enable and disable it via OH but I cannot disable it from PLC site.

So, I think you want your data Thing to have a read start at 33472 and a write start at 147 ? That’s fine, you just need to make sure the poller that “owns” that data Thing includes the read address (write address doesn’t matter)

None of that is anything like the OH1 config you’ve shown us, though.
That would convert to
xxx.things

Bridge modbus:tcp:slave3 [ host="10.50.0.30", port=502, id=1 ]
{
    Bridge poller slave3coils [ start=12576, length=80, refresh=1000, type="coil" ]
    {
        Thing data .....
        Thing data licht4 [ readStart="12593",  readValueType="bit", writeStart="12593", writeValueType="bit", writeType="coil" ]
        // that's 12576 + 17
    }
}

xxx.items

Switch LICHT4 "Licht EG DU/WC" {channel="modbus:data:slave3:slave3coils:licht4:switch"}