OpenHab on Pi with Mosquitto MQTT not working

Hi everybody :slight_smile:

I installed OpenHAB and Mosquitto on Raspberry Pi as a server. And i am using habmin.

I can use the command “mosquitto_sub -v -t topic” and get the messages from my esp8266.
I can also use “mosquito_pub…” and it works good. But i add a switch to my sitemap configured the bindings as Binding Name: mqtt Binding String: >[mosquitto:topic:command:ON:1] , >[mosquitto:topic:command:OFF:0] and it does not publish neither subscribe. :frowning:

I use MQTT-spy to see whats happening… and i can pub/sub with command line but not with the switch on my sitemap. What im doing wrong? I didnt touched any config files. And i installed openhab with apt-get method.

HELP :smiley: peace

I presume you just did a quick summary, and that the above is not actual content from your items file?

Just in case, a correct item binding should look something like this:

Switch mySwitch { mqtt=">[myBroker:myTopic:command:ON:1], >[myBroker:myTopic:command:OFF:0]" }

myBroker must match the name of your broker from the openhab.cfg file, and myTopic must match the topic that your ESP8266 publish to.

My apologies if this is all clear to you.

Ps! I just saw this:

As I mention above, you need to do some configuration in openhab.cfg to setup the MQTT binding to work with you mosquitto broker. If you have not done that - then there’s probably your problem. Please have a look at the Wiki page for the binding to see what needs to be done.

Thanks a lot for your time.

Yes, my items.default file as the mqtt binding defined as the wiki says.

And its allright with the topic names.

Im just not sure what i have to modify in openhab.cfg

Where should i add the broker name?

You need to locate the section called “MQTT Transport” (under the section “Transport configuration”) in your openhab.cfg file. This is where you define the settings needed for openhab to connect to your MQTT broker. As a minimum you need to change the following line:


to something like the following:


Here you state that you will refer to your MQTT broker as ‘mosquitto’ (e.g. in the item bindings), that it is running on the same computer as openhab does (i.e. the local host) and that it can be contacted on port 1883.

With this in place you will refer to your MQTT broker as ‘mosquitto’ in the item bindings (as you did in your example above).

For explanation of the other settings (that are all optional) please refer to the wiki:

MQTT binding - transport configuration

Hope this clears it up for you.

MQTT broker data:
mosquitto_sub -h -v -t "#"
emonhub/tx/12/values 925,320,605,46,13,54,55,20

Binding Sample: