MQTT on OH2 - help needed


As an OH newbee, for me it seems rather painful to configure the MQTT binding on OH2.
What I did for a small sample:

  1. Installed OH2 snapshot 2.0.0

2: sidemap

sitemap actor label=“menue”
Frame {
Group item=gAct1 label=“Actor 1” icon=“Actor 1”

  1. items

// Gruppen
Group gAct1 // Gruppe Actor 1

Switch LED11 “LED11” (gAct1) { mqtt=">[mosquitto:actor1/ch0:command:ON:ch0_255],>[mosquitto:actor1/ch0:command:OFF:ch0_0]" }
Switch LED12 “LED12” (gAct1) { mqtt=">[mosquitto:actor1/ch1:command:ON:ch1_255],>[mosquitto:actor1/ch1:command:OFF:ch1_0]" }
Switch LED13 “LED13” (gAct1) { mqtt=">[mosquitto:actor1/ch2:command:ON:ch2_255],>[mosquitto:actor1/ch2:command:OFF:ch2_0]" }
Switch LED14 “LED14” (gAct1) { mqtt=">[mosquitto:actor1/ch3:command:ON:ch3_255],>[mosquitto:actor1/ch3:command:OFF:ch3_0]" }

  1. Bindings in addons
    binding.mqtt.1.8.3 // I tried 1.9.0.b2 too

  2. services\runtime.conf
package = standard
remote = true
legacy = true
binding = mqtt
ui = basic,paper
persistence = influxdb,rrd4j,mapdb
action = nma,mail
transformation = xslt,map,regex,javascript

As result, OH2 generates the nice ui, but if I toggle the switches, no MQTT messages are sent out.

I have implemented the same sample on OH1, this works perfectly.
Meanwhile I have read a lot of documentation and hints, but the more I read, the more confused am I.

Many thanks for your help and best regards

Hi @waltert,

Let’s validate a couple of things (step by step) to get this working.

First of all: Check if the binding is correctly installed and up & running:

Try not to use manual installation methods but rather use Paper UI for installing bindings.

  • Remove the .jar mqtt binding files from /usr/share/openhab2/addons/
  • Install MQTT (binding-mqtt1) from Paper UI
  • Use mqtt1 (not mqtt) for the binding= name in your /etc/openhab2/services/addons.cfg (since MQTT is still a 1.x binding)
  • Fix your /etc/openhab2/services/mqtt.cfg (not runtime.conf) file to contain something like:

and post some log output from /var/log/openhab2/openhab.log related to MQTT.

You can enable DEBUG level of logging for this binding from the Karaf Console (ssh openhab@localhost -p 8101 with password habopen) by:

log:set DEBUG org.openhab.binding.mqtt

Ps: A lot of the MQTT binding info that you will find online refer to OH1. There are some differences in OH2. These are explained here:

Hi Dim,

Many thanks for your quick help.

I did, as you suggested.
Because my paperui (on windows 7) was empty (?), I have used the karaf console in order
to install mqtt binding and io-transport with feature:install. The log looks not bad now:

21:18:49.705 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at /start
21:18:49.737 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
21:18:49.955 [INFO ] [] - MQTT Service initialization completed.

21:18:49.955 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosqu
21:18:52.089 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
21:18:59.190 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘LED11’ received command ON

All green, no error! But it did NOT generate mqtt publications.
Any idea?

Again many thanks

Now for the next step: Check if the Mosquitto broker is getting the messages (when you press the switch on your sitemap by subscribing to all topics under actor1:

mosquitto_sub -t actor1/#

You could use any MQTT client also (like mqttlens) to subscribe to this topic also to check.

Check also the DEBUG logs of the MQTT binding for any errors/messages

Hi Dim,

Many thanks again for your reply.

I have attached the Mosquitto-log:

C:\Mosquitto>mosquitto -v
1484991929: mosquitto version 1.4.10 (build date 24/08/2016 21:03:24.73) starting
1484991929: Using default config.
1484991929: Opening ipv6 listen socket on port 1883.
1484991929: Opening ipv4 listen socket on port 1883.
1484991989: New connection from on port 1883.
1484991989: New client connected from as openhab (c1, k60).
1484991989: Sending CONNACK to openhab (0, 0)
1484992049: Received PINGREQ from openhab
1484992049: Sending PINGRESP to openhab
1484992052: New connection from ::1 on port 1883.
1484992052: New client connected from ::1 as mosqsub/2480-Walter-MCU (c1, k60).
1484992052: Sending CONNACK to mosqsub/2480-Walter-MCU (0, 0)
1484992052: Received SUBSCRIBE from mosqsub/2480-Walter-MCU
1484992052: # (QoS 0)
1484992052: mosqsub/2480-Walter-MCU 0 #
1484992052: Sending SUBACK to mosqsub/2480-Walter-MCU
1484992109: Received PINGREQ from openhab
1484992109: Sending PINGRESP to openhab
1484992112: Received PINGREQ from mosqsub/2480-Walter-MCU
1484992112: Sending PINGRESP to mosqsub/2480-Walter-MCU

OH logs in and no publications have been sent after toggeling some switches. No subscribes arrived.

C:\Mosquitto>mosquitto_sub -t “#”


Could something be wrong with the mqtt-comand in the item?

Best regards

Let’s check:

Switch LED11 "LED11" (gAct1) { mqtt=">[mosquitto:actor1/ch0:command:ON:ch0_255],>[mosquitto:actor1/ch0:command:OFF:ch0_0]" }

It seems to be correctly formatted…

Try (for testing) a slightly simpler version (without transformations) just to see if the messages reach MQTT:

Switch LED11 "LED11" (gAct1) { mqtt=">[mosquitto:actor1/ch0:command:ON],>[mosquitto:actor1/ch0:command:OFF]" }

Sorry, no change.

I have read somewhere in the forum from “openhab-transport-mqtt”.
But I could not install it with feature:install => no entry

Do you know what this is and if it is necessary, how to install it?

Best regards

I don’t think that this is necessary.

In my OH2 system i have only openhab-binding-mqtt1 installed (and started)

openhab> feature:list | grep MQ
esh-tp-paho                               | 0.9.0.b4         |          | Uninstalled | distro-2.0.0-SNAPSHOT   | MQTT v3 Client
openhab-transport-mqtt                    | 2.0.0            |          | Uninstalled | distro-2.0.0-SNAPSHOT   | MQTT Transport
openhab-action-mqtt                       | 1.9.0            |          | Uninstalled | addons-2.0.0-SNAPSHOT   | MQTT Action
openhab-binding-mqtt1                     | 1.9.0            | x        | Started     | addons-2.0.0-SNAPSHOT   | MQTT Binding
openhab-binding-mqttitude1                | 1.9.0            |          | Uninstalled | addons-2.0.0-SNAPSHOT   | OwnTracks (formerly MQTTitude) Binding
openhab-persistence-mqtt                  | 1.9.0            |          | Uninstalled | addons-2.0.0-SNAPSHOT   | MQTT Persistence

On the other hand, if I see the following in the bundles:

openhab> bundle:list |grep MQ
193 | Active   |  80 | 1.9.0                 | openHAB MQTT Binding
198 | Active   |  80 | 1.9.0                 | openHAB MQTT Transport Bundle

I believe that the Transport binding is used as a shared mechanism for other bindings to use the MQTT protocol.

For regular items, you only need the standard mqtt1 binding.

I would try to fix the Paper UI and install MQTT binding again from there… You wrote that your Paper UI shows nothing?

I have the same bundles installed:

openhab> feature:list | grep MQ
esh-tp-paho | 0.9.0.SNAPSHOT | | Uninstalled | distro-2.0.0
-SNAPSHOT | MQTT v3 Client
openhab-transport-mqtt | 2.0.0.SNAPSHOT | | Uninstalled | distro-2.0.0
-SNAPSHOT | MQTT Transport
openhab-action-mqtt | 1.9.0.SNAPSHOT | | Uninstalled | addons-2.0.0
openhab-binding-mqtt1 | 1.9.0.SNAPSHOT | x | Started | addons-2.0.0
openhab-binding-mqttitude1 | 1.9.0.SNAPSHOT | | Uninstalled | addons-2.0.0
-SNAPSHOT | OwnTracks (formerly MQTTitude) Binding
openhab-persistence-mqtt | 1.9.0.SNAPSHOT | | Uninstalled | addons-2.0.0
-SNAPSHOT | MQTT Persistence

openhab> bundle:list | grep MQ
220 | Active | 80 | | openHAB MQTT Binding
221 | Active | 80 | | openHAB MQTT Transport Bundle

Yes, my paperui is empty.

What do do with openhab-addons…kar?
It is now in my Openhab2.folder, I copied it into the addon-folder, but no effect.

Best regards

If you donwloaded openhab-addons-2.0.0.RC1.kar and placed it in your /usr/share/openhab2/addons folder, you should have all you need.

I don’t like that your Paper UI is broken… something is not working with your OH2 installation…

Try enabling DEBUG on the mqtt binding in Karaf:

log:set DEBUG org.openhab.binding.mqtt

and check/post the logs from /var/log/openhab2/openhab.log

Should be

log:set DEBUG org.openhab.binding.mqtt

mqtt1 is part of the feature name, not the logger/package name.

1 Like

I got the following messages in the openhab.log:

2017-01-21 17:15:39.705 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2017-01-21 17:15:39.752 [INFO ] [] - MQTT Service initialization completed.
2017-01-21 17:15:39.752 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto’
2017-01-21 17:15:41.342 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2017-01-21 17:15:41.352 [DEBUG] [org.openhab.binding.mqtt ] - BundleEvent STARTING - org.openhab.binding.mqtt
2017-01-21 17:15:41.354 [DEBUG] [.binding.mqtt.internal.MqttActivator] - MQTT binding has been started.
2017-01-21 17:15:41.393 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - MQTT: Activating event bus binding.
2017-01-21 17:15:41.393 [DEBUG] [org.openhab.binding.mqtt ] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler,}={event.topics=openhab/,,,,, service.bundleid=220, service.scope=bundle} - org.openhab.binding.mqtt
2017-01-21 17:15:41.394 [DEBUG] [org.openhab.binding.mqtt ] - ServiceEvent REGISTERED - {org.openhab.model.item.binding.BindingConfigReader, org.openhab.binding.mqtt.MqttBindingProvider}={,,, service.bundleid=220, service.scope=bundle} - org.openhab.binding.mqtt
2017-01-21 17:15:41.397 [DEBUG] [org.openhab.binding.mqtt ] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler}={event.topics=openhab/
,,,, service.bundleid=220, service.scope=bundle} - org.openhab.binding.mqtt
2017-01-21 17:15:41.400 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - Initializing MQTT Event Bus Binding
2017-01-21 17:15:41.400 [DEBUG] [ng.mqtt.internal.MqttEventBusBinding] - MQTT Event Bus Binding initialization completed.
2017-01-21 17:15:41.407 [DEBUG] [org.openhab.binding.mqtt ] - BundleEvent STARTED - org.openhab.binding.mqtt
2017-01-21 17:15:41.788 [INFO ] [assic.internal.servlet.WebAppServlet] - Started Classic UI at /classicui/app

Perhaps you can see something.

Best regards

After a reinstallation of Java and the new release of openHAB2 all works fine!!!
Even the paperui is filled with the addons.

Many thanks to Dim for his splendid support.

Best regards

1 Like