Usage of push buttons to toggle output + feedback on design

I’m fairly new with openhab, I have been working with it for a small week now.
My input is driven by on mqtt and my output is driven by modbus.
I’m communicating with a wago 750-881 plc.
I’m using push buttons to handle my output. one push is on, a second push is off.

When I push a button i receive a ‘ON’ command, when i release the button I receive an ‘OFF’ command.

I’m working with the ON and OFF on the push button to get to the next level where I’m able to dim my lights by a long press

I have created a mqtt switch

Switch mqttSwitchIn2 "mqtt switch 2 in" (ALL) {mqtt="<[mqtt:dev/switch/2:command:ON:ON],<[mqtt:dev/switch/2:command:OFF:OFF]"}

that handles both events.

My output is just a switch with a binding to my modbus

Switch modbusSwitchOut1 "modbus switch 1 out" (ALL) {modbus=">[plc:512]"}

and my rule to handle the press on the button is the following

rule "toggle"
when
    Item mqttSwitchIn2 received command OFF
then
    if (modbusSwitchOut1.state != ON)
        modbusSwitchOut1.sendCommand(ON)
    else
        modbusSwitchOut1.sendCommand(OFF)
end

This is all very straight forward.

Now i see on my sitemap, that the status of my out switch is not updated, this means when I turn on the lights, i have to click twice in my sitemap to turn out the light.
I’m wondering what I’m doing wrong, do I need to send a event to the sitemap to make sure it is updated to the new model?

  • I know this works, but is this a good design for openhab buttons?

If you can get feedback from the Wago as to the real state of the output, that would be the best way to go. Else have the rule postUpdate the new switch state.

thus this means I would need to bind the same input as output to my button?
like this?
Switch modbusSwitchOut1 "modbus switch 1 out" (ALL) {modbus="<[plc:512],>[plc:512]"}

Is this a good design for what I’m trying to achieve?

Do you really see the state of mqttSwitchIn2 changing? I experienced that all MQTT messages were handled as STRING values.

That all depends on what your Wemo does, I don’t know.

My wemo?

Sorry, Wago
I don’t know how your Wago is configured or what you might have in your modbus.cfg so I do not know how your Switch item should be bound.

Modbus binding entity number 512 is a bit surprising though … just how many Items are associated with the Wago?

Oh, the Outputs start at 512, the inputs at 0. I found that there are a
some people with this setup that don’t really get it workjng the first
time.

You can configure modbus.cfg to start reading from 512, and not read all the other registers beforehand

Thus i would have 2 bindings, one starting at 0 for my inputs and one
starting at 512 for my outputs? I was thinking about that but I did not
know it was better than having 1 binding

Yes. That would mean the modbus polling service makes two polls of small groups of registers instead of a one poll of many hundreds. Even if not all the possible registers are bound to OH Items, the binding will read all of the specified (read or r/w) registers across Modbus.

The choice is yours - “better” depends on your whole situation.

ok, thanks, I was doubting about splitting it up, but now I certainly will. The modbus length property is how many registers need to be read, right?