I am still trying to integrate MQTT into OpenHAB so that OH subscribes to a topic, and turns on/off a light when the topic changes from on to off.
Long story short, I want a button on a remote device to write to:
/myhouse/office/switch1/
And when OH sees “on”, it triggers a switch. I have configured the switch as follows (line breaks added for readability, but in the config is it all one line):
I have reviewed the MQTT binding document, but I am a bit lost. I want the switch to respond to “command” and publish “state” - where have I gone wrong here?
Usually, it works in the following way: A command is issued by openHAB to an item (for example by using a switch on a sitemap) and then the mqtt config will publish the command to the outbound topic. (with a transformation from ON to 1 and from OFF to 0). Additionally, the status of the remote device is read by openHAB using the inbound configuration (assuming that the remote device publishes status info on the topic).
So, for outbound (>), you would use the command and for inbound (<), you would use the state.
Of course, you can have the state in an outbound config and the command in an inbound.
Remember the way that things are connected:
OH2 <-> Broker <-> remote device
So: OH2 publishes something (a command) to a topic and in turn the remote device subscribes to it.
The other way works similarly: the remote device publishes something (its state) to a topic and OH2 subscribes to it.
I don’t think that you should use autoupdate="false". If you do, then the state of the item will not be updated by the commands issued to it.
This publishes state to one topic and subscribes to another - works like a charm without the loops that I was running into during troubleshooting
Thanks!