Connect Mosquitto to openHAB

Good day guys,

I have trouble connecting openHAB to my MQTT Mosquitto server. I really tried a lot of things and searched through the forum but I just cannot figure it out.

I have openHAB v2.4 running and also Mosquitto v3.1. Mosquitto is working I believe because when I use the commands:

mosquitto_pub -t "/test/light1" -m "0"


mosquitto_pub -t "/test/light1" -m "1"

I see my LED going ON and OFF. My LED is connected to a ESP8266. Also I can see the topic change in MQTT.fx topic = test/light1. It is a simple switch.

In my items file I have the following line:

Switch MQTTLED {mqtt=">[localbroker:/test/light1:command:ON:1],>[localbroker:/test/light1:command:OFF:0]"}

when using the openHAB log I can see that MQTTLED is being switched.

12:16:16.526 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'MQTTLED' received command OFF
12:16:16.540 [INFO ] [smarthome.event.ItemStateChangedEvent] - MQTTLED changed from ON to OFF
12:16:16.975 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'MQTTLED' received command ON
12:16:16.985 [INFO ] [smarthome.event.ItemStateChangedEvent] - MQTTLED changed from OFF to ON

I got a MQTT broker running in openHAB and it is online (it says). I am at a loss at the moment.

hopefully someone can give me some tips how to connect every thing together.

Regards Piet

This is a configuration for MQTT binding version 1.
Which version do you have installed?
version 2 uses things and channels.

There should be only one broker. There is an embedded broker available in OH, but you have already installed mosquitto, so you should not use that embedded broker.
Perhaps you mean you have set up a Thing to connect OH binding to your mosquitto broker?
If you do have a thing working, you are using MQTT binding version 2.

1 Like

Eh, Rosko thanks for the help. That the MQTT binding was for v1.x I did not know that. A while after I posted my message I got it working thought (not with that binding). I found out that when I toggled the switched in paper UI the topic was published. If that was the case all along I would not know. Maybe it was some other configuration I did during experimenting. Whenever my server crashes I will have to figure it out all over again :unamused:

After I found out the topic was being published I added the switch using:

Switch  mqttsw1 "sw1" <switch> (gswitch) { channel="mqtt:topic:ed023040:switch" }

Thanks anyway.

Don’t delete your posts. Whatever problem you had, someone else may run into one day. It costs nothing to leave them to help others.

Ok np. Thought I had nothing usefull in the beginning.

gr Piet