[MQTT] Openhab binding-mqtt 2.4.0 config file syntax confusion

I tried to get the new mqtt binding to work yesterday and after some time i got it running.
This was my config for the file based configuration.

Bridge mqtt:broker:myUnsecureBroker [ host="192.168.0.42", secure=false ]
{
    Thing topic mything { 
    Channels:
        Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set" ]
    }
}
// Items
Switch MQTT_Lamp "MyLamp" {channel="mqtt:topic:mything:lamp"}

Edit: It seems that the channel ID for the Things is depending on how you instanciate the broker and the thing. And previous channel ID was just wrong 1. this is seems valid. (I don’t know why it was working.)

Switch MQTT_Lamp "MyLamp" {channel="mqtt:topic:myUnsecureBroker:mything:lamp"}

So the best thing is to instantiate the broker and the a thing with channel and then go to Paper UI and look how the channel is.
End Edit

But then i did a “sudo apt-get update && sudo apt-get upgrade” but everything was still working fine.

Today i tried to add new channels and hit the wall, after a lot of try and error this was the configuration which got it running again.

Bridge mqtt:broker:myUnsecureBroker [ host="192.168.0.42", secure=false ]
{
    Thing mqtt:topic:mything { 
    Channels:
        Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set" ]
    }
}
// Items
Switch MQTT_Lamp "MyLamp" {channel="mqtt:topic:mything:lamp"}

This is meant for the people which like to do a file based configuration.
Mind the syntax which changed in different versions of the binding, imho.

No, that’s definitely not correct. Either use the thing as a child of the bridge:

Bridge mqtt:broker:myUnsecureBroker "My Broker" [
    host="192.168.0.42",
    secure=false
    ] {
        Thing topic mything "My Thing" { 
        Channels:                        // this line is optional
            Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set" ]
        }
    }

or define the thing independently from the bridge:

Bridge mqtt:broker:myUnsecureBroker "My Broker" [
    host="192.168.0.42",
    secure=false
    ] 

Thing mqtt:topic:myUnsecureBroker:mything "My Thing" (mqtt:broker:myUnsecureBroker) { 
    Channels:                        // this line is optional
        Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set" ]
    }

Hello @Udo_Hartmann,

Thank you for the clarification.

So as i found out for the 1. configurations with the thing as a child of the bridge the channel ID i used was wrong. And this works correctly for me now.

My second configuration works but seems to be not corret, ok for me but was shown here. I think changing the thing name to include myUnsecureBroker would result in the same channel ID.

Bridge mqtt:broker:myUnsecureBroker [ host="192.168.0.42", secure=false ]
{
    Thing mqtt:topic:myUnsecureBroker:mything { 
    Channels:
        Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set" ]
    }
}

The configuration with the Thing independently from the bridge does not work for me.

'mqtt:topic:myUnsecureBroker:mything' changed from INITIALIZING to OFFLINE (COMMUNICATION_ERROR): java.lang.Exception: No MQTT client

But the client is online. I would suggest everyone to just proceed with the 1. configuration.
As i have read file based configuration seems to be a hot political issue.
But i think the independent solution is a nice feature as it reduces the confusion with where did i open the { and where is it closed when the Things get more and more.

The blog post was written by me, but I have no clue about thing syntax and no intention to learn it or use it. I’m just happening to be the guy that wrote the mqtt binding, but I don’t feel responsible to know OH legacy stuff :slight_smile:

@David_Graeff thank you for the great work writting the MQTT binding. Beside some confusion with getting it up and running i think it works pretty well.

Sorry to disagree, but file configuration is not legacy (of course it will be, but for now it’s not).

Even the notation of things files is not legacy as there is no openHAB version other than oh1.x which isn’t capable to interpret these files.

Your notation is still completely wrong.
This is correct:

Bridge mqtt:broker:myUnsecureBroker [ host="192.168.0.42", secure=false ]
{
    Thing topic mything { 
    Channels:
        Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set" ]
    }
}

Of course you have to start a mqtt broker like mosquitto or the embedded mqtt broker.

The item for the channel will be something like this:

Switch mySwitch "My switch [%s]" { channel="mqtt:topic:myUnsecureBroker:myThing:lamp" }

@Udo_Hartmann i did some test again and this are the working solutions as you posted above.

Bridge mqtt:broker:myUnsecureBroker [ host="localhost", secure=false, username="openhabian", password="habopen"]
{
    Thing topic mything { 
    Channels:
        Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set" ]
    }
}

// Items
Switch MQTT_Lamp "MyLamp" {channel="mqtt:topic:myUnsecureBroker:mything:lamp"}

And also the independent configuration does work.

Bridge mqtt:broker:myUnsecureBroker [ host="localhost", secure=false]

Thing mqtt:topic:myUnsecureBroker:mything (mqtt:broker:myUnsecureBroker) { 
    Channels:
        Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set" ]
}
// Items
Switch MQTT_Lamp "MyLamp" {channel="mqtt:topic:myUnsecureBroker:mything:lamp"}

Somehow the not valid configuration does not work anymore? Yesterday it did. But Today i restarted the system after every change. Maybe there was something not properly reconfigured.