OH2 / Classic UI: lights are only switched after a second click

After migrating my working OH 1.8 installation to OH2 Beta 5 (within a docker container), classic UI is behaving strangely when it comes to switching of lights:

When switching on a light (by clicking on the switch icon) everything works as expected: The light immediately is switched on and the state of the switch and icon is correctly updated to “on”.

When clicking a second time on the switch, the switch is shown as “off” but the light itself is still on. Only after clicking on the switch for a second time, the switch briefly is shown as “on” but then turns into “off” again and the light itself is switched “off”.

The switch is assigned to the light by a modbus binding (classic 1.9 binding).

This is whats showing up in the events.log:

``

//First click -> light is switched on

21:03:00.099 [ItemCommandEvent ] - Item ‘LR_LIGHT’ received command ON
21:03:00.122 [ItemStateEvent ] - LR_LIGHT updated to ON
21:03:00.143 [GroupItemStateChangedEvent] - GroundFloor_LR changed from OFF to ON through LR_LIGHT
21:03:00.242 [ItemStateChangedEvent ] - LR_LIGHT changed from OFF to ON
21:03:00.603 [ItemStateEvent ] - LR_LIGHT updated to ON

//Second click -> icons “light” and “switch” are shown as “off” but light is still “on”

21:03:20.021 [ItemStateEvent ] - LR_LIGHT updated to OFF
21:03:20.056 [GroupItemStateChangedEvent] - GroundFloor_LR changed from ON to OFF through LR_LIGHT
21:03:20.067 [ItemStateChangedEvent ] - LR_LIGHT changed from ON to OFF

//Third click -> icons are briefly shown as “on” again, the turn “off” and light is finally switched off
21:03:38.222 [ItemCommandEvent ] - Item ‘LR_LIGHT’ received command ON
21:03:38.249 [ItemStateEvent ] - LR_LIGHT updated to ON
21:03:38.249 [ItemStateChangedEvent ] - LR_LIGHT changed from OFF to ON
21:03:38.268 [GroupItemStateChangedEvent] - GroundFloor_LR changed from OFF to ON through LR_LIGHT
21:03:38.570 [ItemStateEvent ] - LR_LIGHT updated to OFF
21:03:38.570 [ItemStateChangedEvent ] - LR_LIGHT changed from ON to OFF
21:03:38.583 [GroupItemStateChangedEvent] - GroundFloor_LR changed from ON to OFF through LR_LIGHT```

What seems to be missing there is a command event for the middle OFF. Without that, no OFF will be sent out on Modbus.

Is your device a simple relay or an impulse type (i.e. pushbutton stylecontrol) ?

I hope I get your question right:
My modbus devices are impulse driven: a short impulse switches between “on” and “off”.

Regarding your hint about the missing command event: The second click contains no ItemCommandEvent while the 3rd click contains one but to “ON”! There is no command event that switched to “OFF”. Do you know which event is causing modbus to trigger the switch event?

I think we need to go back a step here.
Your lighting control relays are impulse driven, i…e. a push of a switch turns them ON, another push of the same switch turns them OFF, yes?

Openhab knows nothing about that, it knows only On and OFF static states for switches. So to operate your relays there needs to be a means (probably using rules, or perhaps built into your mystery Modbus device) to convert a wanted Light-ON into a Push-ON followed by a Push-OFF. The same needs to be done for a wanted Light-OFF, you need to generate a Push-ON followed by a Push-OFF. That leaves the issue of how Openhab can determine what the current state is.

As you say it used to work for you, I think there is some detail in Items and Rules that you haven’t shared with us yet?

Ha, that’s a good point.

You’re right, there must be a relation between a static change of state (from the switch) and the impulse (needed for the relay).

Here’s an example of a switch item:

Switch MBR_Light  "MyRoom"  (GroundFloor)   {modbus="slave1:<7:>6"}

I didn’t use any “magic” rules to transform a state into a short event or pulse. But I guess the modbus binding is taking care of that (or at least was taking care of that within OH 1.8). Here’s a link to the Modbus section describing the usage of a switch.

In the absence of knowing what your slave’s 7 and 6 coils actually do - guessing that it used to work by luck in timing. Sending ON to the OH switch Item gets sent onwards to the Modbus device, and so on to the impulse relay. Sometime later, the Modbus device gets polled and whatever your slave coil (contact?) 7 represents gets updated back to the OH switch Item and cancels the ON.

Before Modbus binding 1.9 there was an issue that sending ON to an Item that was (apparently) already ON did not result in an On getting sent out on Modbus. I’ll bet this comes into play somewhere too.

In OH2 and/or binding 1.9 the timings or sequence of events is likely different - your luck has run out.

I think you need to take positive steps to understand what your Modbus device needs to be told to do, to supply a consistent pulse for relay on/off. Then you can construct OH rules to make that happen.

1 Like

You nailed it!

After enabling full logging for modbus I was able to see, that the modbus binding was correctly sending out the false (when pressing for the first time on the “off” switch) but my CodeSys program was ignoring that.

Checking the CodeSys program on my Wago (my modbus master that is controlling all my switches, lights and plugs in my house) reacted on true only events. Seems that I was abusing the old modbus 1.8 binding behaviour.

After correcting that now everything works as expected.

Thank you very much for your kind and patient support!