MQTT Publish Command


in my home.items I have this:

Contact TuereWg "Wohnungstür" <door-closed> (FF_Wg) {mqtt="<[mysensor:mygateway1-out/10/1/1/0/16:state:OPEN:1],<[mysensor:mygateway1-out/10/1/1/0/16:state:CLOSED:0]"}

I wonder, for testing purposes, what is the correct command if I want to switch this by just publishing through mosquitto directly. When sending directly

mosquitto_pub -d -t mysensor:mygateway1-out/10/1/1/0/16:state:OPEN:1

I get an error. What do I have to send so openhab understands it?

mosquitto_pub -t mysensor:mygateway1-out/10/1/1/0/16 -m 1

-m for message
-t for topic


This part of your item config


will transform the MQTT message from 1 to OPEN and the Contact item will update in OH2

mosquitto_pub -d -t out/10/1/1/0/16 -m “OPEN”

Assuming you are doing a command line publish to localhost

will this work with a transformation configured (not using state:default) ? maybe yes… I will test :slight_smile:

great, this one works for me very well, thanks for your quick replies guys!

strange that it worked :slight_smile: … i made a copy/paste mistake and I added your broker name in the topic :stuck_out_tongue:
it should have been: mosquitto_pub -t mygateway1-out/10/1/1/0/16 -m 1 (without the mysensor:)

oh, sorry, I just did not enter the “mysensor:” part! So you are absolutely right with this one:

mosquitto_pub -t mygateway1-out/10/1/1/0/16 -m 1