[SOLVED] How to configure mqtt 2 binding

Hi There,

I’ve started to migrate form 1.x to 2.x mqtt binding and getting stuck just at the beginning.
Having a look at the MQTT Documentation it tells us to configure something like Thing mqtt:topic:mything but even copy and past the example from documentation leads to an validation error

Validation issues found in configuration model 'mqtt.things', using it anyway:
Provide a thing type ID and a thing ID in this format:
 <thingTypeId> <thingId>

So first of all I’ve changed it to something valid like Thing mqtt mything but I’m not sure if this is correct.

For now I’m only getting this message, even after setting loglevel to DEBUG log:set DEBUG org.eclipse.smarthome.binding.mqtt

2018-12-20 12:48:57.296 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to ''. Next attempt in 10000ms
2018-12-20 12:48:57.657 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '' with clientid openhab2 and file store '/openhab/userdata/mqtt/'

Any suggestions, how to debug this? The same connection information worked for a long time with 1.x binding.

Here is the full configuration file:

Bridge mqtt:broker:mosquitto [
] {
    Thing mqtt openhab_slave {
      Type number : humidity_gf_diningroom [ stateTopic="openHAB/slave/Humidity_GF_DiningRoom/state"]

Thanks allot

Are you sure you have a secure (https) connection? Secure does not mean, that username/password is used. Those credentials do not make the connection safe, they are plain send over the wire (everybody with a network sniffer can read them).

Thanks, I’ve misinterpreted this value in the way you described it :smiley:

Is the way I’ve defined the thing correct? And could you tell me, why we need the “Channels:” Parameter, which isn’t needed on other bindings?

Because MQTT is the first OH2 binding that allows Generic channel definitions. The new http2 binding also uses this syntax and my new CoAP binding will also use it. It is really just for bindings that do not fully work with auto discovery, like MQTT, HTTP, CoAP etc.

Finally I’ve got it running. But obviously the example is correct but I’m getting the validation error. Maybe this is a bug?

But your definition is incorrect as well. It must be a Thing of type “topic”. No idea about the syntax I don’t use text files.

No, it’s just that the VSCode plug in has not been updated for this binding yet.
Ignore the VS code warning

1 Like

Can you post your working config. That may help other users. Thanks

Here’s my working example. Especially the naming of the channels is missleading in the documentation. But the plugin will write log output with the correct names:


Bridge mqtt:broker:mosquitto [
] {
    Thing mqtt:topic:energy {
      Type number : smart_meter_external_supply [ stateTopic="openHAB/slave/evs_0181/state"]
      Type number : smart_meter_external_production [ stateTopic="openHAB/slave/evs_0281/state"]
      Type number : smart_meter_photovoltaic_production [ stateTopic="openHAB/slave/pv_0281/state"]


/* Energy Consumption general */
Number:Energy  Energy_Consumption_External_Supply      "Fremdbezug [%.0f kWh]"   <energy> (gCounters) { channel="mqtt:topic:energy:smart_meter_external_supply" }
Number:Energy  Energy_Consumption_External_Production  "Einspeisung [%.0f kWh]"  <energy> (gCounters) { channel="mqtt:topic:energy:smart_meter_external_production" }
Number:Energy  Energy_Photovoltaic_Production          "Produktion [%.0f kWh]"   <energy> (gCounters) { channel="mqtt:topic:energy:smart_meter_photovoltaic_production" }

Not sure what I am doing wrong here. I still have the validation issues appearing in my log:
Validation issues found in configuration model ‘mqtt.things’, using it anyway:

Provide a thing type ID and a thing ID in this format:
 <thingTypeId> <thingId>

My configuration looks just like yours, I even tried removing the channel name-strings on the second thing:

Bridge mqtt:broker:localmosquitto  "Mosquitto MQTT Broker"   [
    Thing mqtt:topic:drachenbaum "Drachenbaum" {
            Type number : light             [ stateTopic="miflora/drachenbaum", transformationPattern="JSONPATH:$.light" ]
            Type number : battery           [ stateTopic="miflora/drachenbaum", transformationPattern="JSONPATH:$.battery" ]
            Type number : temperature       [ stateTopic="miflora/drachenbaum", transformationPattern="JSONPATH:$.temperature" ]
            Type number : conductivity      [ stateTopic="miflora/drachenbaum", transformationPattern="JSONPATH:$.conductivity" ]
            Type number : moisture          [ stateTopic="miflora/drachenbaum", transformationPattern="JSONPATH:$.moisture" ]
    Thing mqtt:topic:bonsai "Bonsai" { 
            Type number : light         "Light Intensity"   [ stateTopic="miflora/bonsai", transformationPattern="JSONPATH:$.light" ]
            Type number : battery       "Battery Charge"    [ stateTopic="miflora/bonsai", transformationPattern="JSONPATH:$.battery" ]
            Type number : temperature   "Temperature"       [ stateTopic="miflora/bonsai", transformationPattern="JSONPATH:$.temperature" ]
            Type number : conductivity  "Soil Fertility"    [ stateTopic="miflora/bonsai", transformationPattern="JSONPATH:$.conductivity" ]
            Type number : moisture      "Soil Moisture"     [ stateTopic="miflora/bonsai", transformationPattern="JSONPATH:$.moisture" ]

Am I not seeing something here? Everything works fine, I am just wondering what openhab wants me to do. I am running the latest milestone (2.5.0.M2).

My setup differs from yours in the Thing-lines,
instead of your:
Thing mqtt:topic:drachenbaum "Drachenbaum"
I’m using it like:
Thing topic drachenbaum "Drachenbaum"
I’m using a single thing file for the bridge and the things as well.
(although I’m still on 2.4).


Short update, this finally worked. However I needed an explanation with little more detail. Found it here: [SOLVED] New MQTT binding 2.4

1 Like