[SOLVED] MQTT 2.4 setup problem - mix of GUI/textfile configuration problem

I`m struggling with the new MQTT binding for 2 days now.
I have a fresh openhab 2.4. installation and want to use the new MQTT2.4 binding WITH the embedded MQTT broker. I managed to get a Sonoff device working by adding it via the GUI. when I do the same via text file it works until I add devices to the file or do a openhab reboot, then my things change to “uninitialized - Bridge uninitialized”. I guess I mess something up with the things file.
what I did:
1.) install “Embedded MQTT Broker” and “MQTT Binding” from the Add-on panel.
2.) add the MQTT Broker from the Inbox and configure “Configure MQTT Embedded Broker” in Configuration => Services. I just added username and password.
3.) create things file:

Bridge mqtt:systemBroker:embedded-mqtt-broker "my Broker" [ host="127.0.0.1", secure=false, clientID="openhab2" ]
{
    Thing topic Luftbefeuchter  "Luftraumbefeuchter" @ "Lara Zimmer" {   
    Channels:
        Type switch : power "Luftraumbefeuchter" [ stateTopic="stat/Luftbefeuchter/POWER", commandTopic="cmnd/Luftbefeuchter/POWER", on="ON", off="OFF"]
        Type number : temperature "Temperature" [stateTopic="tele/Luftbefeuchter/SENSOR", transformationPattern="JSONPATH:$.AM2301.Temperature"]
        Type number : humidity "Humidity" [stateTopic="tele/Luftbefeuchter/SENSOR", transformationPattern="JSONPATH:$.AM2301.Humidity"]
    }

when saving this things file I get this eventlog entry:

2019-01-13 14:11:48.480 [WARN ] [ore.common.registry.AbstractRegistry] - Cannot add "BridgeImpl" with key "mqtt:systemBroker:embedded-mqtt-broker". It exists already from provider "ManagedThingProvider"! Failed to add a second with the same UID from provider "GenericThingProvider"!
2019-01-13 14:11:48.512 [hingStatusInfoChangedEvent] - 'mqtt:topic:embedded-mqtt-broker:Luftbefeuchter' changed from UNINITIALIZED to INITIALIZING

2019-01-13 14:11:48.543 [hingStatusInfoChangedEvent] - 'mqtt:topic:embedded-mqtt-broker:Luftbefeuchter' changed from INITIALIZING to ONLINE

I don`t want to add a new bridge, I just want to use the embedded one, create via the GUI.
however, I can switch ON/OFF the device and receive Temp and Humidity values. All fine!
BUT, when I continue to add devices into the things file or reboot openhab, then my broker changes to “uninitialized - Bridge uninitialized”
whats wrong with my thing definition file?
thanks

Mixing text based and PaperUI based definitions can easily go wrong, would suggest you try either or.
Maybe easiest to delete your thing in PaperUI

In addition try clearing out the cache:

1 Like

Probably nothing. Old MQTT was text only, but AFAIK new MQTT binding is GUI only. That means it’s ignoring .things and *.cfg files (unless you also run mqtt1 - it would use these but that would be a mess then).

I use all 3 and it works.
What is not working in your case it that your have named your *.things file broker thing the same as the broker thing you defined in the GUI. Use another name and you should be fine.

1 Like

To avoid missunderstandings:
MQTT2 is NOT ignoring .things files!
As @vzorglub stated those files can be used, even if mixed with PaperUI setups, although that can lead to missunderstandings/errors. For example it is impossible to delete a thing created by a .things file with thev button on PaperUI.

totally confused…
next try: I do NOT add a system broker via GUI, instead I use the things file:

Bridge mqtt:broker:mybroker "my Broker" [ host="127.0.0.1", secure=false, clientID="openhab2" ]
{

eventlog:

2019-01-14 09:03:24.389 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mqtt.things'

==> /var/log/openhab2/events.log <==

2019-01-14 09:03:24.463 [hingStatusInfoChangedEvent] - 'mqtt:broker:mybroker' changed from UNINITIALIZED to INITIALIZING

2019-01-14 09:03:24.491 [hingStatusInfoChangedEvent] - 'mqtt:broker:mybroker' changed from INITIALIZING to OFFLINE

==> /var/log/openhab2/openhab.log <==

2019-01-14 09:03:24.495 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '127.0.0.1' with clientid openhab2 and file store '/var/lib/openhab2/mqtt/127.0.0.1'

==> /var/log/openhab2/events.log <==

2019-01-14 09:03:24.511 [hingStatusInfoChangedEvent] - 'mqtt:broker:mybroker' changed from OFFLINE to ONLINE

2019-01-14 09:03:24.553 [hingStatusInfoChangedEvent] - 'mqtt:topic:mybroker:Luftbefeuchter' changed from UNINITIALIZED to INITIALIZING

2019-01-14 09:03:24.579 [hingStatusInfoChangedEvent] - 'mqtt:topic:mybroker:Luftbefeuchter' changed from INITIALIZING to ONLINE

==> /var/log/openhab2/openhab.log <==

2019-01-14 09:03:24.695 [INFO ] [ansport.mqtt.internal.ClientCallback] - MQTT connection to '127.0.0.1' was lost

another try: I add the system broker in the GUI and try to define my things in the textfile without the bridge line:

    Thing mqtt:topic:Luftbefeuchter   "Luftraumbefeuchter" @ "Lara Zimmer" {   
    Channels:
        Type switch : power "Luftraumbefeuchter" [ stateTopic="stat/Luftbefeuchter/POWER", commandTopic="cmnd/Luftbefeuchter/POWER", on="ON", off="OFF"]
        Type number : temperature "Temperature" [stateTopic="tele/Luftbefeuchter/SENSOR", transformationPattern="JSONPATH:$.AM2301.Temperature"]
        Type number : humidity "Humidity" [stateTopic="tele/Luftbefeuchter/SENSOR", transformationPattern="JSONPATH:$.AM2301.Humidity"]
    }
2019-01-14 09:10:58.506 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mqtt.things'

==> /var/log/openhab2/events.log <==

2019-01-14 09:10:58.515 [hingStatusInfoChangedEvent] - 'mqtt:topic:Luftbefeuchter' changed from UNINITIALIZED to INITIALIZING

2019-01-14 09:10:58.520 [hingStatusInfoChangedEvent] - 'mqtt:topic:Luftbefeuchter' changed from INITIALIZING to OFFLINE (BRIDGE_OFFLINE)

In the GUI I see that the thing is not assigned to a bridge. how do I have to change my thing file so the things are assigned to the broker?
thanks

Try the other way around.
Remove the GUI bridge and put the text one back.

Addiotionally, when you did the test with the file config only Setup, did you restart openhab? The last connection lost COULD be due to bug (which is resoved in the snapshot version) when changing something on the broker config.

THANKS opus! that was the reason for my confusion, I need a reboot after every thing file change.
for others having also troubles with the understanding of the binding:
one needs to install the embedded MQTT broker BUT not needed to add it as a thing.
the thing file config then needs the bridge defined. my sonoff file now looks like this:

Bridge mqtt:broker:myBroker [ host="192.168.1.183", username="openhabian", password="mybroker", secure=false ]
{
    Thing topic Luftbefeuchter  "Luftraumbefeuchter" @ "Lara Zimmer" {   
    Channels:
        Type switch : power "Luftraumbefeuchter" [ stateTopic="stat/Luftbefeuchter/POWER", commandTopic="cmnd/Luftbefeuchter/POWER", on="ON", off="OFF"]
        Type number : temperature "Temperature" [stateTopic="tele/Luftbefeuchter/SENSOR", transformationPattern="JSONPATH:$.AM2301.Temperature"]
        Type number : humidity "Humidity" [stateTopic="tele/Luftbefeuchter/SENSOR", transformationPattern="JSONPATH:$.AM2301.Humidity"]
    }
    Thing topic Subwoofer  "Subwoofer" @ "Wohnzimmer" {  
    Channels:
        Type switch : power "Subwoofer" [ stateTopic="stat/Subwoofer/POWER", commandTopic="cmnd/Subwoofer/POWER", on="ON", off="OFF"]    
    }
    Thing topic Aquarium  "Aquarium" @ "Office" {  
    Channels:
        Type switch : power1 "Aquarium Tageslicht" [ stateTopic="stat/sonoff_4ch_1/POWER1", commandTopic="cmnd/sonoff_4ch_1/POWER1", on="ON", off="OFF"]
        Type switch : power2 "Aquarium Pumpe" [ stateTopic="stat/sonoff_4ch_1/POWER2", commandTopic="cmnd/sonoff_4ch_1/POWER2", on="ON", off="OFF"]
        Type switch : power3 "Aquarium Heizstab" [ stateTopic="stat/sonoff_4ch_1/POWER3", commandTopic="cmnd/sonoff_4ch_1/POWER3", on="ON", off="OFF"]
        Type switch : power4 "Aquarium Futterautomat" [ stateTopic="stat/sonoff_4ch_1/POWER4", commandTopic="cmnd/sonoff_4ch_1/POWER4", on="ON", off="OFF"]
        Type number : temp_wasser "Temperatur Wasser" [stateTopic="tele/sonoff_4ch_1/SENSOR", transformationPattern="JSONPATH:$.DS18B20.Temperature"]
        Type number : temp_office "Temperatur Office" [stateTopic="tele/sonoff_4ch_1/SENSOR", transformationPattern="JSONPATH:$.AM2301.Temperature"]
        Type number : humidity "Luftfeuchtigkeit" [stateTopic="tele/sonoff_4ch_1/SENSOR", transformationPattern="JSONPATH:$.AM2301.Humidity"]
    } ... and so on....

after a reboot my things change to OFFLINE (BRIDGE_OFFLINE), BUT it takes some time and recovers by itself…

The embedded broker is one possible way, one could use the mosquitto broker as well (for all the ones that had it already running).

A restart of openhab should be ok, can you edit your first post and state that the solution were found in post 8?

A small rewrite of your text, that should be added to the binding documentation:
When one choose to have Things file for the configuration a few steps are needed:
One needs to install the embedded MQTT broker(available in >2.4) with the paper UI, BUT don’t add it as a thing in Paper UI…
The thing file config then needs the bridge definition. Example thing file look like this: …