Two-way asynchronous MQTT item binding

I added MQTT to an HDMI switch and have it working to change the switch via OpenHAB. A python script on a Raspberry Pi subscribes to the change event and activates the switch accordingly.

If I change the switch manually using the remote, I’d like to update the value of the item in OpenHAB without firing another change event. I have another python script that can get the current assignment of the switch and can publish to MQTT.

How do I configure the items or rules in OpenHAB?

This is the current item for the switch

Number TvSwitch “TV Switch” (usPlayroom) { mqtt=">[mymosquitto:home/tvswitch:command:*:default]" }

And the Sitemap entry

Selection item=TvSwitch mappings=[1=“Xbox One”, 2=“Fire TV”, 3=“Xbox 360”, 4=“NES Classic”] label=“TV input”

I would have the switch publish to a different topic and add that new topic to the TvSwitch using state instead of command:

Number TvSwitch "TV Switch" (usPlayroom) { mqtt=">[mymosquitto:home/tvswitch:command:*:default],<[mymosquitto:home/tvswitch/status:state:*:default]" }

That did the trick, thanks!