Combined input/output

Hi, I’ve recently discovered the joys of openHAB and I’m currently trying to get it working with my existing home automation on my Raspberry Pi. Most of my things are controlled by shell scripts so I’m using the Exec binding to execute these.

The problem I have is I’d like a control on the PaperUI panel that does both input and output. For example, I have a script that shows the state of the lounge light, either on or off, and I have another script that turns the light on or off. So, I’d like a widget that shows me the current state but also lets me change the state of the light. So I have my two exec binding things, a getter with an output and a setter with an input.

For the single control on the panel I set some rules as follows:

rule "Lounge Lamp State On"
when
Item LoungeLampState_Output changed to ON
then
LoungeLamp_Input.sendCommand(“ON”)
end

rule "Lounge Lamp State Off"
when
Item LoungeLampState_Output changed to OFF
then
LoungeLamp_Input.sendCommand(“OFF”)
end

This sort of works ok but I have some feedback lag. If I press the control to switch the lamp it can briefly flick back to the other state because it has just received a state update from the output item, then after a short delay it will switch back again to where I set it when the ouptut item reports the newly set state.

I’m assuming this is quite a common requirement to have a control that combines input and output so I’m thinking I’m inplementing this in the wrong way. I’d be very grateful if somebody could point me in the right direction.

Thanks

You can be doing this with a single Item, configured to accept both inbound and outbound channels.
Exactly how you do that depends if you are using PaperUI or old-fashioned OH1 file editing for configuring.

You need to use a little care in rules handling the Item.
Understand that commands sent to the Item, by rules or UI, get processed by the outbound channels and sent to device. Updates do not.
Messages from device get processed by channels and actioned as updates to the Item.

The distinction between command and update prevents the whole thing getting in a loop. And allows your rules to do the same.

To complicate, OH has a autoupdate feature by default. Sending a command to an Item eventually arrives at the autoupdater, which acts like a dummy binding and updates the Item too. Where you have ‘real’ updates from a device, you would usually want to disable that for the Item.

I think your current rules misbehave because they may or may not run before the autoupdate.

Thanks for the reply. I wasn’t aware of the subtle difference between an item receiving a command and an item receiving an update. That does indeed sound like the functionality I’m missing. So, when an item receives an update it will simply reflect that new value in my widget on the panel display, but when I click on a widget in the panel it will send a command and my thing should act upon it. Is that correct?