[SOLVED] MQTT Broker correct initialization

Hello,
i tried to add a mqtt broker to openhab2.4 since it was changed recently.

Here is my topic which I want to subscribe to

40.686264
qos : 0, retain : false, cmd : publish, dup : false, topic : weather/outTemp_C, messageId : , length : 33

Here is my approache but it is not working at all

Bridge mqtt:broker:mosquitto [ host="*******", secure=false ]
{
    Thing topic weather {
    Channels:
        Type number : outTemp_C "outTemp_C" [ stateTopic="weather/outTemp_C", commandTopic="weather/outTemp_C" ]
    }
}

the broker itself is connected only the display of the value is not working

Is the broker thing online?
Is the weather thing online?
Your thing syntax doesn’t match mine:

Bridge mqtt:broker:mosquitto [ host="*******", secure=false ]
{
    Thing mqtt:topic:weather "weather" {
    Channels:
        Type number : outTemp_C "outTemp_C" [ stateTopic="weather/outTemp_C", commandTopic="weather/outTemp_C" ]
    }
}

Next question, why do you need an outgoing command topic on a temperature sensor?

the paper ui display the broker thing is online

MQTT Broker
MQTT Broker

A connection to a MQTT broker

Status: ONLINE

the weather thing is not online

Status: OFFLINE - COMMUNICATION_ERROR java.lang.Exception: No MQTT client

No i don’t need to have a outgoing command topic I thought this is the syntax haven’t found an example.

This syntax is not valid anymore. Was an error in the blog post and documentation.

If you would have used the forum search, you would have found that this is a known bug with the OH 2.4 release and got fixed just the same day as the release already.

To avoid this look into:

–>MQTT Generic Thing: java.lang.Exception: No MQTT client

Solution

Bridge mqtt:broker:mosquitto "MQTT Broker: Mosquitto" [ host="smarthome.fritz.box", port=1883, secure="false"]
Thing mqtt:topic:outTemp_C (mqtt:broker:mosquitto) {
Channels:
Type number : outTemp_C "outTemp_C" [ stateTopic="weather/outTemp_C"]
}

I updated to openhab2.4 today.
Before that I had openhab2.3 on my Synology.

I used the old version of mqtt binding.

In this version, the mqtt broker was configured using the .cfg file.

Define your MQTT broker connections here for use in the MQTT Binding or MQTT
Persistence bundles. Replace <broker> with an ID you choose.
URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
broker.url=ws://192.168.xxx.xxx:9001

My items were then configured like this.

Switch Kinderzimmer “Kinderzimmer Licht” [ “Lighting” ] {mqtt=">[broker:shellies/shelly1-XXXXX/relay/0/command:command:*:MAP(shelliesonoff.map)],<[broker:shellies/shelly1-XXXXX/relay/0:state:MAP(shelliesonoff.map)]"}

It all worked out fine, too.
Now since openhab2.4 and the new mqtt binding there is no .cfg file anymore.

For the new Mqtt binding I created a Thing for testing. It looks like this. In PaperUI it is also shown as connected.

mqtt:broker:unsecureBroker [ host=“192.168.xxx.xxx”, secure=false ]

What is not clear to me now is what my items must look like, that everything works again.
Can someone help me?

Start here and then do a search on the forum and you’ll find plenty of examples.

If your still having issues then post both things and items someone will be glad to help.

@H102
It would be easiest if there were an example of a Shelly1 in the new version. I tried it like this. But it doesn’t work.
My items from the old version can be seen in the post before. If I understand that correctly, does the new version work without items?

Bridge mqtt:broker:myUnsecureBroker [ host="192.168.XXX.XXX", secure=false ]
{
    Thing mqtt:topic:mything {
    Channels:
        Type switch : lamp "Kitchen Lamp" [ stateTopic="ON/OFF", commandTopic="shellies/shelly1-XXXXX/relay/0/command" ]
    }
}

Please consider to bring you up to speed on the openHAB 2 concepts which are Things / Channels / Items (in contrast to openHAB 1 which only had items).

You still need items, but they have no configuration anymore, only one(!) for the linked channel. As @H102 wrote, there are many examples by now in the forum.

Cheers, David

1 Like

I have found the solution here.