# Usage of push buttons to toggle output + feedback on design

**URL:** <https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685>\
**Category:** Beginners\
**Tags:** designpattern\
**Created:** [June 8, 2017, 7:10pm UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685 "2017-06-08T19:10:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jelle\_Victoor](https://community.openhab.org/user_avatar/community.openhab.org/jelle_victoor/32/72366_2.png) [@Jelle\_Victoor](https://community.openhab.org/u/Jelle_Victoor)\
**Post date:** [June 8, 2017, 7:10pm UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/1 "2017-06-08T19:10:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [June 8, 2017, 7:19pm UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/2 "2017-06-08T19:19:20Z")

</div>

> [@Jelle\_Victoor](#):
>
> Now i see on my sitemap, that the status of my out switch is not updated,

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.

---

<div class="post-metadata">

**Author:** ![Jelle\_Victoor](https://community.openhab.org/user_avatar/community.openhab.org/jelle_victoor/32/72366_2.png) [@Jelle\_Victoor](https://community.openhab.org/u/Jelle_Victoor)\
**Post date:** [June 8, 2017, 8:07pm UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/3 "2017-06-08T20:07:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![vegarroe](https://community.openhab.org/letter_avatar_proxy/v4/letter/v/3da27b/32.png) [@vegarroe](https://community.openhab.org/u/vegarroe)\
**Post date:** [June 8, 2017, 9:34pm UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/4 "2017-06-08T21:34:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [June 9, 2017, 9:26am UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/5 "2017-06-09T09:26:46Z")

</div>

> [@Jelle\_Victoor](#):
>
> like this?  
> Switch modbusSwitchOut1 “modbus switch 1 out” (ALL) {modbus=“\<[plc:512],\>[plc:512]”}

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

---

<div class="post-metadata">

**Author:** ![Jelle\_Victoor](https://community.openhab.org/user_avatar/community.openhab.org/jelle_victoor/32/72366_2.png) [@Jelle\_Victoor](https://community.openhab.org/u/Jelle_Victoor)\
**Post date:** [June 9, 2017, 11:06am UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/6 "2017-06-09T11:06:49Z")

</div>

My wemo?

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [June 9, 2017, 11:31am UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/7 "2017-06-09T11:31:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jelle\_Victoor](https://community.openhab.org/user_avatar/community.openhab.org/jelle_victoor/32/72366_2.png) [@Jelle\_Victoor](https://community.openhab.org/u/Jelle_Victoor)\
**Post date:** [June 10, 2017, 10:08am UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/8 "2017-06-10T10:08:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [June 10, 2017, 2:12pm UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/9 "2017-06-10T14:12:34Z")

</div>

> [@Jelle\_Victoor](#):
>
> Oh, the Outputs start at 512, the inputs at 0.

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

---

<div class="post-metadata">

**Author:** ![Jelle\_Victoor](https://community.openhab.org/user_avatar/community.openhab.org/jelle_victoor/32/72366_2.png) [@Jelle\_Victoor](https://community.openhab.org/u/Jelle_Victoor)\
**Post date:** [June 11, 2017, 7:20am UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/10 "2017-06-11T07:20:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [June 11, 2017, 9:35am UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/11 "2017-06-11T09:35:51Z")

</div>

> [@Jelle\_Victoor](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Jelle\_Victoor](https://community.openhab.org/user_avatar/community.openhab.org/jelle_victoor/32/72366_2.png) [@Jelle\_Victoor](https://community.openhab.org/u/Jelle_Victoor)\
**Post date:** [June 11, 2017, 12:14pm UTC](https://community.openhab.org/t/usage-of-push-buttons-to-toggle-output-feedback-on-design/29685/12 "2017-06-11T12:14:43Z")

</div>

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?
