[SOLVED] Syntax to publish to mqtt broker defined in .things from mosquitto_sub terminal

Hey,

I can’t figure out how to link my MQTT broker with items, and send an command from a mosquitto_sub shell.

For instance:

something.things:

Bridge mqtt:broker:mosquitto [ host="0.0.0.0", secure=false ]
{
    Thing mqtt:topic:mything "mqtt_test" {
    Channels:
        Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set", on="ON", off="OFF" ]
    }
}

someitems.items:

Switch dummy "dummy Switch" (gPiscine) {channel="mqtt:broker:mosquitto:mything:lamp"}

I have installed Mosquitto & I know it works, if I open 2 terminal I can mosquitto_sub -t sometopic

mosquitto_pub -t "sometopic" -m "hello world"

However if I do:

mosquitto_pub -t “lamp” -m “ON”

Or any of the 55 thousands variations I could think of ("mqtt:broker:mosquitto:mything… etc.) nothing seems to work.

What’s the syntax I need to be able to publish to the topics defined in my Bridge mqtt broker from a mosquitto_pub terminal? Or is my item suscription to the channel wrong?

mosquitto_pub knows nothing about your things, you need to publish to the complete command topic.

1 Like

Yes - but then what is that syntaxe? WHat do I need to write?

That part is a topic

Your lamp you can control with

mosquitto_pub -h <mqttserver here> -t lamp/enabled/set -m 'ON'

And if you set another window with:

mosquitto_sub -h <mqttserver here> -t lamp/enabled

When you run the pub command above your lamp should respond on the state topic. And if you control via openhab, again your lamp should respond on the state topic.

To verify that OH is sending the correct command to the lamp (regardless if the lamp is getting it or not), then sub to the command topic:

mosquitto_sub -h <mqttserver here> -t lamp/enabled/set

Does that help?

1 Like

That’s what I needed. Thanks a bunch.