Use MQTT Binding to talk to Raspberry Pi

Hey OpenHAB Community,

I try to get the MQTT Bindung to talk to some other Raspberry Pis. Previously I used the MQTT Action Binding with some rules to send specific text values to the berries.

With the new released openHAB 2.5 I want to implement the MQTT Binding using switches and channels. Even If I tried several guides and the official description of the binding, I cant receive any messages on other berries.
I am using the embedded broker, created a MQTT generic thing and connected to a Switch Channel (“MQTT command topic” is “test”). Changing the state of the switch to ON or OFF shall send “ON” or “OFF”.
No error messages are at the log files and the broker and generic thing are ONLINE / INITIALIZED.

With the other PI I subscribe to the topic “test” (like I did with the MQTT Action binding) :

mosquitto_sub –t test

Switching the MQTT-Switch doesn’t give me any response at the subscribed topic.

I really don’t know my mistake – Could be the subscription to the topic “test” by the mosquitto client the wrong approach?


I think your subscription is wrong :wink: Try it with this command:

mosquitto_sub –t test/#

A good little Guide for the Client…

Simplify and make changes gradually. Presumably if you had this working with the MQTT v1 binding working using the MQTT Action, you have Mosquitto or some other external broker running. Keep using that. Honestly, the embedded broker is no longer maintained and probably shouldn’t be used anyway, but you definitely don’t want to move from a solid broker like Mosquitto to that.

Keep your Rules the same. Once you have your Broker Thing connected and Online, you can publish messages using

actions.getAction("mqtt", "broker:thing:id").publishMQTT("topic", "message", false) // last argument is the retained flag

Once that works, then move to creating the Generic MQTT Things and Channels to replace your Rules.

Minimize your changes to make it easier to find where it went wrong.

Changing the subscripted topic like you mentioned didn’t help.

I adjusted settings are now:


Bridge mqtt:broker:testbrokername [ host="", secure=false ] {
Thing topic testtopic {Channels:Type switch : testswitch "label" [
stateTopic="topicstate", commandTopic="topiccommand", on="ON", off="OFF"]}}

Switch testswitch_sitemap "Dummy" channel= "mqtt:topic:testbrokername:testtopic:testswitch" }

Switch item=testswitch_sitemap

subscription of the other pi
I tried:

  • mosquitto_sub -t topicstate
  • mosquitto_sub -t topicstate/
  • mosquitto_sub -t topicstate/#
  • and the same with topiccomand

I also tried your code with the embedded broker - I wasn’t able to transfer any messages. How to use mosquitto for that?

The problem might be roundabout 40cm in front of the screen :smiley:

It doesn’t matter what the broker is. If the configuration is correct it will work. You configure the connection to the Broker in the MQTT Broker Thing.

So do you see errors in the logs? Get MQTT Explorer and monitor all of the messages on your broker instead of just mosquitto-sub.

I think this Config is not correct…

Try it like this…

Bridge mqtt:broker:testbrokername [ host="",port=1883,secure=false,retainMessages=false, retain=false ]

Thing mqtt:topic:testtopic "MQTT - Testtopic" (mqtt:broker:testbrokername) {
    Type switch : testswitch "Test Switch" [ stateTopic="/topicstate/state", commandTopic="/topiccommand/command", on="ON", off="OFF"]

And Subscribe the Topic with this Command:

mosquitto_sub –t /topicstate/state
mosquitto_sub –t /topiccommand/command


Whats the difference between:

  1. with curly bracket
    Bridge mqtt: .... { Thing mqtt: ... }

  2. without curly bracket
    Bridge mqtt: .... Thing mqtt: ...

Nevertheless, using your code doens’t work at my side.
Where is the connection to the embedded mqtt broker? Shall the bridge make this connection and how do I see this in the code?

Right now at the PaperUI I have three Brokers

When I connect to my openhabserver with the following settings I don’t get any message (no error logs, no $SYS or something else)

The MQTT-Client ID is jsut a name not the connected MQTT Server ID, isn’t it?

Is this Item really connected to your testswitch Thing?

NO … 2 Brokers and 1 Thing


seems that the item testswitch_sitemap is connected to the geneic mqtt thing using the channel testswitch

:smiley: it works.

My way:

  • At PaperUI I created a new MQTT Broker (not the System MQTT Broker)
  • Broker Hostname/IP: localhost
  • and gave them a username and a password (I didn’t do that the last times) --> could this be a problem?

Afterwards the same procedure as last time:

  • Generic MQTT Thing with a bridge
  • Channel with a linked item

Thank you guys for your help and patience.

If your Broker is configured to require a username and password than yes, of course, you must supply the username and password to connect to it.

Where can I see If an username or pw is required or not? I didn’t choose a secure connection or something similar

This is based on how mosquitto was set up in the first place. If you never set up a username and password, how did you know what username and password to use to get it to work?

I gave my own created broker an user with a password

user/password values are not required so left them empty at the first tries.