Migrating MQTT1 items to MQTT2.4 items

As @vzorglub already suggested ONE DEVICE=ONE THING!

Great, Thanks -> Yes, this was it! Solved!!

works now, for others maybe interesting when using a TH03 with a SI7021 sensor

Items:
Switch TH03 {channel=“mqtt:topic:5f4a663f:TH03”}
Number TH03TEMP {channel=“mqtt:topic:5f4a663f:TH03Temp”}
Number TH03HUM {channel=“mqtt:topic:5f4a663f:TH03Hum”}

Sitemap for the sensors:
Text item=TH03TEMP label=“TH03Temp [%.1f °C]” icon=“temperature”
Text item=TH03HUM label=“TH03Hum [%.1f %% ]” icon=“humidity”

and this is the example for the humidity channel:
image

1 Like

Hi guys,

i have read all this thread and i can not really understand which advantage has all this to mqtt1 if everything already configured in items and works?
Only UI with which i can easily add new devices or i can get some other plus points from it?

Because eventually v1 binding support will go the way of the dodo. So getting used to a v2 binding now, whilst the two can still work together, is best practice.

Vincent, am supporter of configuring things and items throught files and not UI. If something happend, i put the files to their places and everything works again in minutes. But with GUI as somthning happens you will have lot of problems.
I have really NO one problem from the time i installed mqtt1! It looks like that it is the stabiliest part of my intallation:slightly_smiling_face:
So why migrate to mqtt2? :smiley:

Because one day you will HAVE to and will will curse that day for not having prepared for it

1 Like

That is the problem ((( that we have to leave the real stable things.

MQTTv2 is stable
A lot, and I mean a lot of work and testing went into it.
MQTTv2 actually has more options than MQTTv1 like nested transformations, payload validation etc…

1 Like

MQTT2 supports:

  • automatic discovery of Things that follow the Homie or Home Assistant standard
  • chained transformations (e.g. perform a JSONPATH followed by a REGEX without needing Rules)
  • use of the retained flag in a more MQTT standard and expected way
  • is receiving updates and will continue to receive updates going forward, development has completely stopped with MQTT 1 and the MQTT 1 Action
  • MQTT 1 will no longer be supported at some point, perhaps as soon as OH 3 sometime next year
  • supports Profiles
  • will eventually support Units of Measure
  • works better with REST API creates/managed Items (you cannot manage OH 1 binding Items any way except through .items files
  • you are guaranteed to get the syntax right every time and you don’t have to look anything up when creating the Thing.
  • The UIs as you see them in PaperUI is not how the UIs will exist in OH 3. They are undergoing a complete rewrite and from what I’ve see so far it’s going the be really good.
  • Already the number of people who can provide support on the MQTT 1 binding on this forum has grown small.
  • Simple transforms like mapping 1 to ON and 0 to OFF can be done right on the Thing without the need to create and use a transform.

I’m sure there are more but those are off the top of my head.

No, and in fact when you manage your stuff through the UI/REST API you are in an even better situation that with .items files.

  • If you are creating backups, you are already (or should already) be backing up the “mysterious” database where stuff created through the UI/REST API because you had better be backing up /var/lib/openhab2 too. If you are using òpenhab-cli backup` you are also backing up that folder as well.

  • The JSONDB (that “mysterious” database) is automatically backed up for you on every change and periodically. So if something goes wrong, you have an automatically created backup you can restore from. Unless you create a backup every time you save a .items file you can’t have that with text configs.

  • The JSONDB is not really that mysterious. It’s a text file, JSON formatted, and it has one entry for each element and it is pretty easy to read and, if necessary, edit by hand.

To reiterate Vincent’s posts, it’s a lot better and easier to migrate when you want to rather than when you have to. And there are benefits as mentioned above.

If you are of the "don’t touch it you’'ll break it"sort, than you won’t be making any updates or upgrades to your system anyway, so why ask the question in the first place? You’ll be staying on OH 2.3 or what every older version of OH you are currently running and just let it run. But if you need or want to update OH to get bug fixes or new features as OH continues to evolve, at some point you will not be able to continue to run the MQTT 1 binding any more.

In my experience, at least for the parts of the binding I’ve used, the MQTT 2 binding is now every bit as stable as the MQTT 1 binding. Only it works a lot more like it should now in how it treats the retained flag. And I have a lot more capability than I ever had in the MQTT 1 binding.

2 Likes

Rich, perfect explanation! Thanks a lot.
After that i will think about it carefully.

Thanks Vincent.
Will learn more about mqtt2.

Hello Rich,

could you please tell if it still possible in MQTT2 to define things, channels and items over the files.
I can not find any information till now about it. I have found в little about things definition, but now complete, but about channels and items nothing.
Couild you make soime example or guide?

Thanks a lot!

It’s possible. The ability and syntax is a core feature of OH and not implemented by individual bindings. There are examples all over the forum.

But I personally recommend using PaperUI to create at least your initial Things and then if you have a lot of copy/paste/edit, use the REST API. People are always getting the syntax wrong and very rarely do users reasons for insisting on using .things files have merit in my opinion. When you use the UI the syntax is guaranteed to be right and it’s clear and intuitive what options there are and how to use them.

I do not define anything in .things files and I recommend against their use so I won’t be the one to create a guide or tutorial.

2 Likes

Thanks!
I have installed mqtt2 yesterday. It worked till restart.
Now i get

2019-11-23 13:58:44.656 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.mqtt.handler.BrokerHandler@9d4645': null

java.lang.NullPointerException: null

	at org.eclipse.paho.client.mqttv3.internal.MqttPersistentData.<init>(MqttPersistentData.java:63) ~[?:?]

	at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.get(MqttDefaultFilePersistence.java:219) ~[?:?]

	at org.eclipse.paho.client.mqttv3.internal.ClientState.restoreState(ClientState.java:342) ~[?:?]

	at org.eclipse.paho.client.mqttv3.internal.ClientState.<init>(ClientState.java:172) ~[?:?]

	at org.eclipse.paho.client.mqttv3.internal.ClientComms.<init>(ClientComms.java:108) ~[?:?]

	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:470) ~[?:?]

	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:320) ~[?:?]

	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:315) ~[?:?]

	at org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection.createClient(MqttBrokerConnection.java:752) ~[?:?]

	at org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection.start(MqttBrokerConnection.java:706) ~[?:?]

	at org.openhab.binding.mqtt.handler.AbstractBrokerHandler.initialize(AbstractBrokerHandler.java:108) ~[?:?]

	at org.openhab.binding.mqtt.handler.BrokerHandler.initialize(BrokerHandler.java:232) ~[?:?]

	at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source) ~[?:?]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]

	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [133:org.openhab.core:2.5.0.M4]

	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52) [133:org.openhab.core:2.5.0.M4]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

	at java.lang.Thread.run(Thread.java:748) [?:?]

2019-11-23 13:58:44.708 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'mqtt:broker:max': null

java.lang.NullPointerException: null

	at org.eclipse.paho.client.mqttv3.internal.MqttPersistentData.<init>(MqttPersistentData.java:63) ~[?:?]

	at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.get(MqttDefaultFilePersistence.java:219) ~[?:?]

	at org.eclipse.paho.client.mqttv3.internal.ClientState.restoreState(ClientState.java:342) ~[?:?]

	at org.eclipse.paho.client.mqttv3.internal.ClientState.<init>(ClientState.java:172) ~[?:?]

	at org.eclipse.paho.client.mqttv3.internal.ClientComms.<init>(ClientComms.java:108) ~[?:?]

	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:470) ~[?:?]

	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:320) ~[?:?]

	at org.eclipse.paho.client.mqttv3.MqttAsyncClient.<init>(MqttAsyncClient.java:315) ~[?:?]

	at org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection.createClient(MqttBrokerConnection.java:752) ~[?:?]

	at org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection.start(MqttBrokerConnection.java:706) ~[?:?]

	at org.openhab.binding.mqtt.handler.AbstractBrokerHandler.initialize(AbstractBrokerHandler.java:108) ~[?:?]

	at org.openhab.binding.mqtt.handler.BrokerHandler.initialize(BrokerHandler.java:232) ~[?:?]

	at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source) ~[?:?]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]

	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [133:org.openhab.core:2.5.0.M4]

	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52) [133:org.openhab.core:2.5.0.M4]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

	at java.lang.Thread.run(Thread.java:748) [?:?]

And seems not to work at all. All things are offline.
Pi4 and OH 2.5M4

I have googled a little, and seen the same problem in 2018, it was written, that they must be fixed, but how can it be, till now not fixed or have i made smth wrong?

Thanks a lot!

Use 2.5 M5. That version dropped the Paho library for the HiveMQ library because Paho isn’t being speed very well.

It is still possible. I use thing and item files for all my devices. It’s easier if you own multiple instances of the same devices.

1 Like

Thanks Rich,
I have just installed 2.5M5 form M4.
After installation and restart i got messages that persistant service with ID Influx not found (maybe other i have not mentioned)
And after reboot dashboard and logs and all uis never came back. OH died :crazy_face:

After 2 reboots it is again here with me :rofl:

Rich, I read that you if you wish to use the Alexa skill you’ll need to tag items or things which is not available in paper ui. I presume you not using the Alexa skill.

Items need to be tagged. Rich mentions that at least things should be configured in PaperUI since otherwise it is likely that you get the syntax wrong an this always is a pain to find and support