How it works - binding-mqtt - 2.4.0

I started to configure communication with MQTT.
After reading a lot and struggling with all the version differences and therefor not working tutos, I have one test ITEM running.
But I do not know why or better to say - I do not know why it is not working like in the tutos.

I use openHAB 2.4.0 Release Build -It is a Openhabian on an RaspPI
I installed mosquito with “sudo openhabian-config”
In PaperUI:

  • added the MQTT Binding binding-mqtt - 2.4.0 and NOT MQTT Binding (1.x) binding-mqtt1 - 1.13.0
  • added via INBOX MQTT Broker A connection to a MQTT broker -> mqtt:broker:65167b30 (no channels)
  • added via INBOX Generic MQTT Thing -> mqtt:topic:e7f66367
  • added a channel
  • MQTT state topic = Keller/Licht/Power1
  • MQTT command topic = Keller/Licht/Power1
  • -> mqtt:topic:e7f66367:test

With Texteditor

Switch mqtt_testsensor {mqtt="<[mqtt:topic:e7f66367:test]"}

Switch item=mqtt_topic_e7f66367_test
Switch item=mqtt_testsensor

If I send from cmd-line
mosquitto_pub -u openhabian --pw xxx123456 -t “Keller/Licht/Power1” -m ON
the switch with



the item



So that’s my problem.
How should the ITEMS look like?
Thank you!

Try upgrading to the latest stable 2.5 version. 2.4 is well over a year old.

You are using mqtt1.x item syntax (mqtt=…) but need 2.x (channel=…)


Thank you!

I’ve updated OpenHAB with “sudo openhabian-config”
After some struggles (ssh, ip:9001 was working, ip:8080 did not respond),
OpenHab is now running on “openHAB 2.5.3 Release Build”

You are using mqtt1.x item syntax (mqtt=…) but need 2.x (channel=…)

Yes I think that’s the Problem. There are so many versions out there and most examples do not write for which version it works.

I want edit my items,rules,…files with an texteditor. So could you please give me on proper line for my item?

In ITEMS file

Switch mqtt_testsensor2 { channel=“mqtt:topic:e7f66367:test”, autoupdate=“false”}

is working.
But if I want use the TOPIC and the THING name, what do I have to do - to write?

What do the official documents tell you? We are not here as a replacement for the documentation.

Every topic will result in a channel, that’s what you will find in the docs and what you have working in your example.
Items have to be configured on channels, unless it is an openHAB 1.x Binding.

@Asus as @hmerk mentioned the item has to be configured on the channel. When you have the Thing created, go to the channel and copy the channel info. The info you copied will be placed in the items file (as the channel).


Switch CouchLight "Couch Light" <light>  ["Lighting"]  { channel="mqtt:topic:pibroker:sonoff2:power" }

This is the part copied from PaperUI channel:


The item type needed to match the device e.g. my item is a Switch. The item name and tagging is whatever you want to use.

Hope this helps.

Thank you H102

But that’s what I mentioned.

is a little bit cryptic and you need some copy/past.

If you could use the full topic, eg. broker:Keller/Licht/Power1:command its more like the idea behind mqtt, imho.
I think the old syntax was more intuitive

But I think that’s not possible in opebenHAB with mqtt2.x

Once you create the Generic Thing in PaperUI the channel get created for you. No guessing about the correct syntax involved.

In the item example the channel does use the broker name e.g pibroker.

Example of Thing in files:

Bridge mqtt:broker:pibroker "pibroker" [ host="", port=1883, secure=false, username="xxxxxx", password="xxxxxxx" ]

Thing topic sonoff2 "Couch Light" @ "Couch Light" {
        Type switch : power        "Power"         [ stateTopic="stat/sonoff2/POWER", commandTopic="cmnd/sonoff2/POWER" ]
1 Like

Thank you H102

I think, I have to acept this and think differently.
MQTT uses topic like a path to one “Item”
OpenHAB uses ITEM internal and you have to link it to MQTT with 4 steps

  • install bridge
  • make thing
  • define channel (with mqtt-topic-path)
  • define ITEM in itemsfile using “new path” like bridge:thing:channel

In my opinion, we do double nearly the same thing.
wasn’t it in mqtt-binding 1x more the way mqtt itself works?

But now, my project is running in the first step and now I will explore further on the land of openhab-arduino,mqtt.

Thank you all and please be lenient with my half-baked thinking.

mqtt binding was developed for openHAB 1.x which did not use the thing concept. Things have been introduced with openHAB 2.0.
Please check the concept docs to get a better understanding.

openHAB isn’t about mirroring the protocol and structure of MQTT or Modbus or any other communication.

It’s a home automation system, so it tries to model simple machines.
Example, a thermostat device.
We can model that as a single Thing.
It has several data channels - room temperature, setpoint, heater on/off

Whether that data is three different MQTT topics, or one topic sharing all with JSON, doesn’t matter to the model.

Thank you all!

I’m now working and thinking the way,openhab works.
And it’s not bad :grinning:

1 Like