MQTT " the new one " WHAT / HOW?

Can someone please help me understand the “new” mqtt fully :

please tell me what is right and wrong and i will correct it ,so i guess it will help others too.

1 : This makes the broker . ( XXXXX.things file ) Right ?

2. And its called “myUnsecureBroker” ?

broker.things

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

3. What does the first line reference too/do ?

mqtt.things

Bridge mqtt:broker:myUnsecureBroker [ host="10.0.1.15", secure=false ]  {
    Thing mqtt:topic:mything {
    Channels:
        Type switch : lamp "Kitchen Lamp" [ stateTopic="lamp/enabled", commandTopic="lamp/enabled/set" ]
        Type switch : fancylamp "Fancy Lamp" [ stateTopic="fancy/lamp/state", commandTopic="fancy/lamp/command", on="i-am-on", off="i-am-off" ]
        Type string : alarmpanel "Alarm system" [ stateTopic="alarm/panel/state", commandTopic="alarm/panel/set", allowedStates="ARMED_HOME,ARMED_AWAY,UNARMED" ]
        Type color : lampcolor "Kitchen Lamp color" [ stateTopic="lamp/color", commandTopic="lamp/color/set", rgb=true ]
        Type dimmer : blind "Blind" [ stateTopic="blind/state", commandTopic="blind/set", min=0, max=5, step=1 ]
    }
}

items:

Switch Kitchen_Light "Kitchen Light" {channel="mqtt:mybroker:topic:mything:lamp" }
Rollershutter shutter "Blind" {channel="mqtt:mybroker:topic:mything:blind" }

rules:

rule "Send startup message"
when
  System started
then
  val actions = getActions("mqtt","mqtt:broker:myUnsecureBroker")
  actions.publishMQTT("system/started","true")    
end

.
.
.

And another way to show the the “new” mqtt :
.
.
.
please comment the picture (reference by number ) and then i will correct it with the changes.

.

Bonus question :slight_smile:

1 . When i want to make another mqtt Things file what does the bridge line look like because when
i try to make another bridge it messes up the other ??? very frustrating . :face_with_symbols_over_mouth: and nothing works anymore.

  1. my goal is to be able to have bought my old mqtt and new running at the same time but, mabye it i too hard ? to figurer out .

ps: the files in this are taken from other mqtt questions in the forum ,hope its ok ,this i just to understand the new mqtt fully .
.

.

My setup :
Im on windows 10 , openhab 2.5.3 Build#66
I have mosquitto running and working
I have mqtt1 and mqtt v2 binding installed

Assuming this is what it looks like for everyone else I doubt anyone will be able to answer your questions. But if I assume this is a screenshot from PaperUI than:

  1. No, nothing you do in PaperUI gets saved to .things files, .items files, etc. They get saved to a JSON DB file in $OH_USERDATA/jsondb. To create a Broker Thing click on the Inbox, click the + icon and select MQTT Binding and then select “Add Manually.” Then select MQTT Broker from the list and enter in the required connection information.

  2. This is a .things file. I don’t recommend .things files for MQTT. You can’t mess up the syntax and it is obviously apparent what options are available and how to fill them out when you use PaperUI. I spent far too much time helping people get the syntax right for doing .things files so I don’t support them any more. Others might help with that.

  3. In general, you have a Bridge Thing which in this case would be the MQTT Broker Thing. A Bridge Thing generally represents a connection to a service. For OpenWeatherMap, for example, the Bridge represents your OpenWeatherMap account. For MQTT it represents the Broker. A Bridge has one or more sub-Things. A Thing in general represents a single device. In the MQTT case, you would create a Generic MQTT Thing (assuming you are not using devices that follow the Homie or Home Assistant MQTT topic standards and are therefore automatically discovered). Each topic that the device subscribes to or publishes to is represented by one or more Channels which you also manually configure on the Generic MQTT Thing.

  4. There is only one Bridge Thing per connection to an MQTT Broker. You should only have the one Bridge Thing.

  5. So far you’ve said nothing that indicates why you wouldn’t be able to run them both at the same time. You would create a Generic MQTT Thing to replicate an existing mqtt binding config on an Item and the replace that binding config with a link to the Channel. See https://community.openhab.org/search?q=Migrate%20MQTT%202.4 for tons of posts with examples and similar questions answered.

“There is only one Bridge Thing per connection to an MQTT Broker. You should only have the one Bridge Thing”

I have this Thing file and at the top :

Bridge espmilighthub:esp8266Bridge:001 "ESP Milight Bridge" @ "espmilighthub" [ADDR="tcp://10.0.0.53:1883"]

And i have this Thing file and at the top :

Bridge mqtt:broker:mqttBroker "broker    : mqtt broker" [ host="10.0.0.53", secure=false]

1 : Is this 2 connections or 2 brokers ?
( I have it all working but don`t realy know how ,and i wood like to know if there is a fault )

2 : My biggest problem is that i cant and haven't gotten the syntax in the "new" or "old" mqtt and im not a coder at all ,so my “old” mqtt connection looks like this :

mqtt.cfg :

broker.url=tcp://10.0.0.53:1883

pid:org.openhab.mqtt

sonoff.items :

Switch back_door  "back_door" <back_door> (BA)  ["Switchable"] 
  { mqtt=">[broker:cmnd/back_door/power:command:*:default],
          <[broker:stat/back_door/POWER:state:default]" ,autoUpdate="false"  }

And i have no ideer how my new Bridge Things file line shot look like so the “new” and “old”
broker is the same and not conflicting, that’s why i made the picture above ,just to understand what is what.

Bridge mqtt:broker:mqttBroker "broker    : mqtt broker" [ host="10.0.0.53", secure=false]

If you have the new version of mqtt installed you need a thing for the broker and then things for everything you want to connect to. I have two things files, one for broker as below:

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" @ "Treasurebox x.x.x.20" [ 
  host="192.168.1.20",
  secure="AUTO",
  port=1883,
  qos=0,
  username="openhabian",
  password="mypassword"
]

Then I have a things file for my connections:

Thing mqtt:topic:entrylight "Shelly1 Entry" (mqtt:broker:MosquittoMqttBroker) @ "MQTT OpenHAB" {
	Channels:
        Type string : reachable  "Entry Reachable"          	[ stateTopic="tele/shelly/entry/LWT" ]
        Type switch : power      "Entry Power"              	[ stateTopic="stat/shelly/entry/POWER", commandTopic="cmnd/shelly/entry/POWER" ]
        //Type number : rssi       "Entry RSSI" 		[ stateTopic="tele/shelly/entry/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }

Make sure to restart after modifying the mqtt things files. I am not saying its necessary, but it eliminates the question of if you have to.

Prepare these two files to match your setup and then restart. After everything is up and running watch the logs you should see the connection get made to the broker.

Lastly the first and most important step is to make sure mosquitto is installed and working prior to even connecting openhab. You can verify with many tools, I have been using mqttfx simply because I installed it years ago and it has been working.

I have both mqtt1 and mqtt installed but after i have installed the new mqtt all my old mqtt dont work anymore and I cant figure out why ,no clue at all ,i know i just can make all the old ones to channels ,but i am curious why and trying to learn by the proces.
my guess is that the Things file has the answer

That one has nothing to do with MQTT.
Lots of bindings have Bridges, just as lots of bindings have Things.
If you have one MQTT broker outside of openAB, you need only one MQTT Bridge for your binding.

pacho mqtt i think right ? i think the hub has it`s own broker ,but it runs on port 1883 to maby i shot change or i it ok

This 3 what is nr .2 and 3 ? define them cannal id or ??
1 : mqtt
2. broker
3. mqttBroker
mqtt:broker:mqttBroker

Bridge mqtt:broker:mqttBroker "broker    : mqtt broker" [ host="10.0.0.53", secure=false] {

if i change nr. 3 to broker it will not work ,and i think this is what my old broker was cald

mqtt.cfg :

broker.url=tcp://10.0.0.53:1883

pid:org.openhab.mqtt

sonoff.items :

Switch back_door  "back_door" <back_door> (BA)  ["Switchable"] 
  { mqtt=">[broker:cmnd/back_door/power:command:*:default],
          <[broker:stat/back_door/POWER:state:default]" ,autoUpdate="false"  }

Why? The MQTT binding is not using it, you have some other binding using it and presumably working. Just leave it alone as it is nothing to do with the MQTT binding.

It’s the UID for your Bridge thing.
First part identifies the binding it belongs to - you have many things belonging to different bindings.
Second part describes what kind of thing we are labelling. This one’s a broker, not a thermostat or weather service.
Third part is some name you choose to give it so that it is unique.

If you change that name then you’d have to change all the things and channels that belong to it as well, otherwise they’ll no longer link together.

Curious now - you’ve clearly used this same form of Things and channels and UIDs for other bindings, why is this one difficult?

it is because i have at lot of old mqtt stuf that dont work anymore after installation of the new mqtt binding and since im no coder i will not be able to just make it all work again ,therefore it will be nice just to have both bindings working side by side ,i gues my Mosquitto broker i running both bindings ,but some things messes it up ?

The problem were that i had more then one “Bridge Thing” line , so now everything is working agin after all of Things are in one things file now under the Bridge Thing line, so now all is good

The espmilighthub binding does not use the mqtt 1 or 2 bindings. It can talk directly to your mosquito broker and you can uninstall all other bindings and it will still work as it talks directly to your mosquito broker. The binding does not have its own broker you still need mosquito or any other mqtt broker that you prefer to use.

1 Like