MQTT 2.5 binding setup question

Hi Comm,

I am kind of struggling with the setup of MQTT on my OH-system.
Here is how far I am.

I am sending an update to shiftr.io (broker.shiftr.io) with my NodeMCU.
In OH, I have installed the MQTT 2.5 Binding.
Also one System Broker is setup and under that broker, a channel is configured.

I also added two items to an items-File which look like this:
String key1 “Key1 [%s]” {mqtt="<[Keychain:precense/keys/key1:state:default]"}

Now a little background:
The node mcu is sending either “Arrived” or “Left” to the topic “Precense/keys/key1”.
This all works fine.

The problem now is somehow in the OH-config because all I see in the openhab.log, is that it cannot reach the broker or get the topic.

Also what I dont get is how it all come together.
I did configure the channel. In the channel-configuration (I’m using PaperUI for this btw.), I put “precense/keys/key1” or “precense/keys/+” as MQTT-Topic but that does not change much. The connection just keeps failing.

Here is also a piece of the log. This is written, when saving the configuration in PaperUI:

2020-05-11 10:01:42.348 [WARN ] [.transport.mqtt.MqttBrokerConnection] - Failed subscribing to topic precense/keys/key1
java.util.concurrent.CompletionException: java.util.NoSuchElementException
at java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture.uniApply(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:1.8.0_251]
at com.hivemq.client.internal.mqtt.mqtt3.Mqtt3AsyncClientView.lambda$handleSubAck$0(Mqtt3AsyncClientView.java:64) ~[?:?]
at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) [?:1.8.0_251]
at com.hivemq.client.rx.FlowableWithSingle$SingleFutureSubscriber.onComplete(FlowableWithSingle.java:385) [bundleFile:?]
at com.hivemq.client.internal.rx.operators.FlowableWithSingleCombine$SplitSubscriber.onComplete(FlowableWithSingleCombine.java:183) [bundleFile:?]
at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.checkTerminated(FlowableObserveOn.java:199) [bundleFile:?]
at io.reactivex.internal.operators.flowable.FlowableObserveOn$ObserveOnConditionalSubscriber.runAsync(FlowableObserveOn.java:641) [bundleFile:?]
at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.run(FlowableObserveOn.java:176) [bundleFile:?]
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66) [bundleFile:?]
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57) [bundleFile:?]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_251]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
Caused by: java.util.NoSuchElementException
… 13 more
2020-05-11 10:01:44.270 [WARN ] [.transport.mqtt.MqttBrokerConnection] - Failed subscribing to topic homeassistant/#
java.util.concurrent.CompletionException: java.util.NoSuchElementException
at java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture.completeThrowable(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture.uniApply(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:1.8.0_251]
at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:1.8.0_251]
at com.hivemq.client.internal.mqtt.mqtt3.Mqtt3AsyncClientView.lambda$handleSubAck$0(Mqtt3AsyncClientView.java:64) ~[?:?]
at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) [?:1.8.0_251]
at com.hivemq.client.rx.FlowableWithSingle$SingleFutureSubscriber.onComplete(FlowableWithSingle.java:385) [bundleFile:?]
at com.hivemq.client.internal.rx.operators.FlowableWithSingleCombine$SplitSubscriber.onComplete(FlowableWithSingleCombine.java:183) [bundleFile:?]
at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.checkTerminated(FlowableObserveOn.java:199) [bundleFile:?]
at io.reactivex.internal.operators.flowable.FlowableObserveOn$ObserveOnConditionalSubscriber.runAsync(FlowableObserveOn.java:641) [bundleFile:?]
at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.run(FlowableObserveOn.java:176) [bundleFile:?]
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66) [bundleFile:?]
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57) [bundleFile:?]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_251]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_251]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
Caused by: java.util.NoSuchElementException
… 13 more
2020-05-11 10:01:44.270 [WARN ] [g.mqtt.handler.AbstractBrokerHandler] - Failed to subscribe org.openhab.binding.mqtt.homeassistant.internal.discovery.HomeAssistantDiscovery@4016ecd8 to discovery topic homeassistant/# on broker mqtt:systemBroker:Keychain

I hope there is someone who can help me or at least push me in the right direction.
Thx in advance :slight_smile:

Update:
Little update on the situation. I kept testing and switched to mosquitto. The connection from OH to mosquitto works good. I see no error (just the one where it tells me that it cannot connect to +/+/homie (which is annoying that this cannot be turned off). But still the problem is, that if I publish something on the topic precesense, I see that mosquitto is sending this to OH but in OH I have no way to display this state from mosquitto.

So maybe I just need help to understand how to use stuff I get with the publish-trigger in OH, for rules or inside the Sitemap.

Okay

This is an MQTT binding version 1 configuration. It will not work with binding 2.5. Binding 2.5 uses Things and channels, and you link Items using channels, as per binding docs.

Beware old tutorials and posts.

Ah ok. but when I use the following Item-config it also does not show anyhting:

String test “[%s]” { channel = “mqtt:systemBroker:my_broker:cha1” }

(where my_broker is the broker I configured and cha1 is the PublishTrigger that is subscribed to presence)

is there maybe a better explaination then the documentation for the mqtt-binding where I can see working examples for item-file using mqtt?

If you don’t use the documentation, you won’t get very far.

There are literally hundreds of examples in this forum, and a search feature at top-right of your screen.
Take care with older examples, using mqtt= style links.

But what is SystemBroker in this context? How you have configured your Things is of vital importance here, and you’re keeping it secret.

You almost certainly do not want to use publishTrigger, and should read on in the docs to the “Things and channels” MQTT setup.
Define a Thing to represent to the remote “box”
Define channels for the MQTT topics in and out of openHAB

Thanks for claifying that…
Sorry for not being one of those guys who post before they read or search the forum.
I did that. That is why I have tried with the old item-string “{mqtt=”<[Keychain:precense/keys/key1:state:default]"}" and the new one. I also tried using mosquitto and shiftr.io because I though it makes a difference.

All the posts I found where about other stuff with MQTT and therefor not the way to solve my problem.

The MQTT binding description does not really tell you alot on how to implement MQTT in OH (especially if you compare it to other binding-descriptionslike the HUE-binding).

I did not write down what “SystemBroker” was, because I saw it in the posts I found and therefor thought it was somekind of fixed value.

Also, what else is there, than the “publishTrigger”?
That is all I found in the documentation of the binding and that is all I can select in PaperUI.

What exactly do you mean by “should read on in the docs to the “Things and channels” MQTT setup.”?

The MQTT binding needs a broker thing (in your case probably the “System Broker”) which acts as a bridge. No channel needed for this thing!
Additionally you need (generic) MQTT Things which connect to the above mentioned bridge. Those things would need the channels.

So I just made some screenshots on what I did:

  1. I installed the MQTT Binding 2.5 and created a broker thing

  2. After that, I’ve added a channel with the type “Publish Trigger”

(this is how it is configured)

Then I added the following line to an items-file:
String test “Test [%s]” { channel = “mqtt:systemBroker:my_broker:cha1”

I also added the following line to a sitemap-file:
Text item=test

This is all I have done so far. I do not where I went wrong because I cannot see any other way in the documentation or here in the forum.

Btw: mosquitto works fine. I can publish and subscribe to any topic and also see when something is posted to a topic.

In other words you installed two brokers (Mosquitto and the System broker).

1 Like

oh I see. but I can see in mosquitto, that OH is registered as a subscriber and that it gets updates.
Do you know how I would use mosquitto as my main broker?

Remove the system broker and its related thing and create a MQTT broker thing which connects to Mosquitto.

And how do I do that?
Sorry for all these questions but I really cannot figure out how…
The things is, I see that mosquitto is listening on port 1883.
The “SystemBroker” is the thing I see when I look at services inside the PaperUI.

The only broker I have in my system atm is the one I created in the services-section in PaperUI and the configuration looks like this:

in the picture you can also see the Cha1 channel and there it also says “systemBroker”.

The docs -


The quote -

Which are clickable links. You’re not using Homie, or Home Assistant, so follow the Things and channels link to -

where it describes setting up “generic” Things for MQTT.

You make a generic Thing to represent your device, and that has channels for the topics in and out of openHAB

You don’t normally try to have channels directly on your broker thing because it is more difficult to manage and less flexible than the generic versions.

You installed it (I never did) guess who should know. Most probably there is a dustbin sign somewhere, unless you installed it via a file ( if that is possible at all). Maybe removing the System Broker thing is enough.

Ok… so I read all these links @rossko57.
That is how I started about 2 days ago.
And that is why I said, that I cannot find a solution in the documentation…

That is correct because I though you need to install the MQTT-Binding to work with MQTT in OH (or am I wrong? ).

Again:
After installing the MQTT-Binding via PaperUI I end up with the following:

This MQTT system broker connection is not something I create and I cannot delete it.

If I click on “Manage” it show me a blank page where I can create a system broker connection:

If I click on the +, a window is opened where I can put in the information for the broker-connection:
(I just filled in the required stuff (no username and no pass since this is not configured in mosquitto)

As soon as I click on save in this video, a new thing appears inside my Inbox which is of type “System MQTT Broker”:

I now click on the check mark to add the thing. In the next dialog-box that opens, I can give this object an name:
5

After all this. I have a thing of type System MQTT Broker which is connected to mosquitto.
Mosquitto also sees OH as subscriber because automatically the MQTT-binding subscribes to “homeassistant/#” and " +/+/$homie".

Now if I click on the thing of type “System MQTT Broker” I can add a channel.
The setup of the channels, I already posted before.

So after all of this, please shine some light on me and tell me at what point I did something wrong.
Also @rossko57, where did I go wrong and did not follow the steps from the documentation?

I also read, that I cannot configure the MQTT-thing just by file, that is why I use PaperUI.

After redoing all of the above, I get the following log-entry when I publish on the subscribed topic:

2020-05-11 18:29:16.536 [WARN ] [.incoming.MqttIncomingPublishService] - No publish flow registered for MqttStatefulPublish{stateless=MqttPublish{topic=test, payload=7byte, qos=AT_MOST_ONCE, retain=false}, packetIdentifier=-1, dup=false, topicAlias=0, subscriptionIdentifiers=[]}.

Where did you read that? Not everything on the internet is true. You can use either method, and people have a preference for one or the other. You choose.

You don’t want that. The System MQTT Broker is about the integrated Moquette broker option, and is part of the integration about controlling the broker e.g. where to put retained topics database etc.

You do want a bridge Thing pointing at your actual broker.

Then, you can create generic Things belonging to that broker Thing.
Each of these generic Things can have several channels configured for topic in and out.
The channels can be linked toopenHAB Items.

Ah ok I see.
Well thanks to your help I was now able to get it to work. Thx