Hi,
I’m running OpenHab 2 on my windows 10 machine. Java version “1.8.0_221”. I’m connecting to an Allen Bradley PLC with a modbus binding.
My goal is to let the light switch behave as a push button. Based on the state of the light (which I can read from discreteInput[0]) the switch is either ON or OFF. Toggling the button should always immediately turn on or off my light.
Expected behaviour:
- State living_state == ON => Switch is ON => Toggle switch => Lights go off => State living_state == OFF
- State living_state == OFF => Switch is OFF => Toggle switch => Lights go on => State living_state == ON
Actual behaviour:
- Toggle switch => Lights go on
- Toggle switch => Nothing
- Toggle switch => Lights go off
- Toggle switch => Nothing
I always have to toggle double. I’ve tried several things so far, but can’t get it to work. And I’m also not able to take the state of the light into account.
I’ve been able to setup my configuration based on the documentation and some posts I’ve read here:
I’ve ran out of ideas and my last resort is coming here… So if anyone can help me, that’ll be greatly appreciated. If you need more information, let me know.
.things
Bridge modbus:tcp:plc [ host="x.x.x.x", port=x, id=2 ] {
Bridge poller coils [ start=0, length=25, refresh=1000, type="coil" ] {
// Note the zero based indexing: first coil is index 0.
Thing data living "Living" [ readStart="0", readValueType="bit", writeStart="0", writeValueType="bit", writeType="coil" ]
}
Bridge poller discreteInputs [ start=0, length=25, type="discrete" ]{
Thing data living_state [readStart=0, readValueType="bit"]
}
}
.items
Switch living "Digital Output index 0 [%d]" { channel="modbus:tcp:plc:coils:living:switch", autoupdate="false"}
Switch living_state "Digital Output index 0 [%d]" { channel="modbus:tcp:plc:discreteInputs:living_state:contact"}
.sitemap
sitemap modbus_verlichting label="Verlichting"
{
Frame {
Switch item=living label="Living" mappings=[ON="ON"] icon="switch-off" visibility=[living_state == OFF]
Switch item=living label="Living" mappings=[ON="OFF"] icon="switch-on" visibility=[living_state == ON]
}
}