Openhab talking to mosquitto?

How can I test if Openhab and mosquitto are working together?

there are many, many threads in here on how to troubleshoot the openHAB <-> Broker connection… did you search the forum?

One example:

1 Like

The basics…

Assuming you installed the mosquitto clients,… (sudo apt-get install mosquitto-clients if not)

Subscribe to a topic…
mosquitto_sub -h hostname-or-ip -v -t whatever-your-topic-is

(The -h is optional, only needed if mosquitto is running on a different host than the console you’re on. Also, you can use # as a wildcard if you want to see numerous messages coming in, eg: mosquitto_sub -v -t openhab/frontdoor/# )

Publish a message to a topic…
mosquitto_pub -h hostname-or-ip -t whatever-your-topic-is -m whatever-your-message-is

Again, -h optional.

For example, I have an item that displays the state of an ESP8266 device (whether its up or not), as follows…

Number frontdoorControllerState "Front Door [MAP(]" <settings> (gDoors) { mqtt="<[mqttbroker:openhab/frontdoor/status:state:default]" }

So if you want to test to see if this gets updated in OpenHAB, then just use the mosquitto_pub command to publish a test message to the topic, such as:

mosquitto_pub -t openhab/frontdoor/status -m 1

In my transform file, I simply have:


So if I publish the message 1 to the topic openhab/frontdoor/status then it will show up in OpenHAB the state “Alive”. If I then publish 0 to the same topic, in OpenHAB is should show “Down”

Of course, when this is working under normal circumstances, my ESP8266 sends MQTT message of “1” every 30 seconds to indicate its alive. If MQTT broker doesn’t receive a status of 1 after I think its 60 seconds, it will automatically change to 0 and show as down (uses MQTT LWT, Google that if you want to learn more)

Hope that helps.

@Dim to the rescue again. I had speed read that post but completely missed what I needed. Thank you. Its working as its supposed to.

@chimera thank you too your example helped me to get MQTTlens working.

1 Like

how do i mark this solved?


1 Like

how do I add the connection using the GUI?