MQTT Binding Command & State

My simple binding:

Switch Aeon "Switch [%s]" <switch> { zwave="4:command=switch_binary", mqtt="<[octopus:hgm_andrea/items/switch:command:default],>[octopus:hgm_andrea/items/switch:state:*:default]"}

It works. But, when I click the item on the OH web interface to change its value, there is a loop: I saw infinite message in the logs:

2016-09-22 14:26:28.682 [INFO ] [runtime.busevents             ] - Aeon state updated to ON
2016-09-22 14:26:28.687 [INFO ] [runtime.busevents             ] - Aeon state updated to ON
2016-09-22 14:26:28.688 [INFO ] [runtime.busevents             ] - Aeon state updated to ON
2016-09-22 14:26:28.689 [INFO ] [runtime.busevents             ] - Aeon state updated to ON
2016-09-22 14:26:28.691 [INFO ] [runtime.busevents             ] - Aeon state updated to ON

It is reasonable that it happens: when the state changes, the mqtt publish a message on the channel items/switch.
That channel is the same of the command channel which receives the message and changes again the switch, and so on…
There is something I am missing? Or I have to separate command channel from state update channels? Please read channels == topics.

Use autoupdate=false which should prevent the incoming updates from triggering the Item’s other bindings.

Alternately you can create a Proxy Item to represent the Switch, separate Items to bind to zwave and mqtt, and a rule/rules to interpret the state and commands from these Items and sendCommand/postUpdate as necessary.

autoupdate does not solve the problem.
At this point, I think the WiKi is misleadgin.
Could you provide an example of what you mean for separate items?

Switch Aeon "Switch [%s] <switch>
Switch Aeon_zwave  { zwave="4:command=switch_binary"}
Switch Aeon_mqtt {mqtt="<[octopus:hgm_andrea/items/switch:command:default],>[octopus:hgm_andrea/items/switch:state:*:default]"}

But how openhab “knows” that the Aeon_mqtt is a zwave device??

As I said above, and as demonstrated in the thread I linked to, you need to write a rule or rules that trigger on the Aeon_zwave and Aeon_mqtt Items and update the Aeon Switch appropriately, and a rule that triggers on the Aeon Switch and sends the command on to Aeon_zwave and Aeon_mqtt as needed.

Got it. But, pardon for what I am saying, it is a bit “tricked” this solution.
I prefer to use in this case different channels. And about this solution, I really will appreciate your opinion.
Thank you.

If autoupdate=false doesn’t work for this case the Proxy Item approach is the only solution I know of to make it work.

The Proxy Item is a well defined and well understood design pattern in openHAB Rules appropriate for many situations. If you search the forum for “Proxy” and “Virtual Item” (another name some people call this) you will find dozens of example.

I am late coming in on this but I found, doing virtually the same thing but this time on OH2, that

does work.
My items line looks like:

Switch Light_GF_Dining_Table “Dining Table” (GF_Dining, Lights) {autoupdate=“false”, channel=“zwave:device:c958462a:node13:switch_binary2”, mqtt="<[localbrokerrb:myhome/items/switch:command:default],>[localbrokerrb:myhome/items/switch:state:*:default]"}

Plus I have not used a rule as suggested in the link above. So maybe the functionality is a bit different with OH2.

1 Like