Help out with mqtt binding - beginner


I have installed mqtt - broker on openhab2 (linux ubuntu)

Seems to work:

2018-02-28 20:55:47.587 [INFO ] [] - MQTT Service initialization completed.
2018-02-28 20:55:47.593 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘localbroker’

and i have an esp8266 with a dht22 attached to it.

The log of the esp says its connects to the mqtt broker
5498 : MQTT : Connected to broker

what i do not get is - how to get the info of the esp to display in my basicUI.

What do i put in the .items file

please help me out to understand

That is pretty simple:
Create an item that subscribes to the data that are sent to the MQTT Broker by your ESP.
In my case, I do have an ESP that is using the pubsubclient to publish the following data:

  if(MQTT_Client.connect("ESP32_GardenSensors", MQTT_User, MQTT_Pass))
    MQTT_Client.publish(SensorRaisedBed.MQTT_BatteryTag, "-1");
    MQTT_Client.publish(SensorRaisedBed.MQTT_ValueTag, "-1");

The value of SensorRaisedBed.MQTT_ValueTag is:


And the MQTT_Client is an instance of the PubSubClient:

PubSubClient MQTT_Client(MQTT_Server, MQTT_Port, MQTT_callback, espClient);

And on the other hand, I do have the following item:

String MoistureRaisedBed			"Feuchtigkeit Hochbeet [%s]"	        {mqtt="<[mosquitto:Home/Garden/RaisedBed/HumiditySensor/Value:state:default"}

So once the ESP boots up and connects to the WiFi it sends “-1”.
This currently is for testing purposes since i am waiting for the rest of the hardware. But you should get the idea.

If Sascha’s reply did not help, check out my thread here as it gives you rules and items to send and receive MQTT messages. The first post in the thread is long but it should spark some ideas and you have the knowledge that they are working examples you can copy and adjust to what you need…

i installed MQTT.fx - here i have a reading on the esp through the broker on the same computer as openhab. So the MQTT broker works and the esp get’s its data to the broker

i added this to .item

Number		Temperature_dht     "Temperatuur DHT22 [%.1f °C]"						<temperature> {mqtt="<[localbroker:dht22_01/temp/Temperature:state:default]"}

and this to the sitemap:

Text item=Temperature_dht

but then the site map does not work any more.

The mistake is an the .item file put where ?

Can you show your sitemap file?

Map works, but i do not get a value

You said that you added your item to .item
The item definition looks right
What is the name of your items file
It must end with .items NOT .item


It’s items. i added the mqtt in an exesting items file.
i tried differrent versions as ik guessing the mistake is in the broker name:

|Number||Temperature_dht     "Temperatuur DHT22 [%.1f °C]"||||||<temperature> {mqtt="<[localbroker:dht22_01/temp/Temperature:state:default]"}|
|Number||Temperature_dht1     "Temperatuur DHT22_01 [%.1f °C]"||||||<temperature> {mqtt="<[localBroker:dht22_01/temp/Temperature:state:default]"}|
|Number||Temperature_dht2     "Temperatuur DHT22_02 [%.1f °C]"||||||<temperature> {mqtt="<[openHab:dht22_01/temp/Temperature:state:default]"}|

But no luck yet

What does your mqtt.cfg looks like?
Mine is:


If your broker is running in the same machine then you can use tcp://
the clientId doesn’t really matter as long as it is unique to the broker
I have set up mosquitto for username and password
If you haven’t you don’t need the last two lines and can be commented out with ‘#’


Then one of my items definition:

Switch	LivingRoom_WallSwitch	      "Wall Switch"	                 <switch2> (LivingRoom, Switches, MSwitches)     { mqtt="<[mybroker:House/LivingRoom/WallSwitch:state:default]" }

I just re-read the topic and it looks like the openhab is connecting to mosquitto
your broker name is localbroker (no capitals) so your first item definition is correct

What topic does your ESP publishes the value under
The topic in openHAB must be exactly the same.


in mqtt.cfg i have this:


I installed MQTTfx and there this value produceses a temp


So i was thinking that this

Number		Temperature_dht1     "Temperatuur DHT22_01 [%.1f °C]"                   <temperature> {mqtt="<[localBroker:dht22_01/temp/Temperature:state:default]"}

would produce a value in the site map but it does not

Change your mqtt.cfg as follow:


Remove the “mqtt:” in front of each line (Not necessary in OH2)
You are on a local machine so the qos is really not needed


Victory - while banging my head against the wall


Spot the diffenrence

Yes of course
Sorry I missed that!
As I said, the topics need to be exactly the same