Moving (finally) from MQTT1 - with issues

I’m finally trying to migrate from MQTTV1 and looking to do it in a controlled manner as some of my MQTT configurations have messy transformations. I need to do this to continue the journey to OH3
I’ve installed the MQTT Binding (v2.5.12) alongside MQTT Binding (1.x).
I created an initial Things file (called mqtt.things) as per below.

Bridge mqtt:broker:mosquitto "MQTT-2 Broker" [ host="127.0.0.1", secure=false ]
{
    Thing topic StudyLightThing "Study Light 1" {
        Channels:
            Type switch :  state "OnOff" [stateTopic="stat/STUDY_T1SON_85/POWER",commandTopic="cmnd/STUDY_T1SON_85/POWER"]
    }
}

And then commented out the V1 Item entry (in lights.items file )and replaced it with the V2 like this:

/*Switch StudyLight "Study Light" <light> (LR,AllLights) ["Lighting"]
        {mqtt=">[mosquitto:cmnd/STUDY_T1SON_85/POWER:command:*:default],
                <[mosquitto:stat/STUDY_T1SON_85/POWER:state:default],
                <[mosquitto:tele/STUDY_T1SON_85/STATE:state:JSONPATH($.POWER)]"}
*/
Switch StudyLight "Study Light" <light> (LR,AllLights) ["Lighting"] {channel="mqtt:topic:mosquitto:StudyLightThing:state"}

And after a quick

sudo systemctl stop openhab2.service
sudo systemctl start openhab2.service

It worked without errors in logs etc.
However as soon as a I made any sort of change to my mqtt.things file it stops working.
I can see the StudyLight item changing state in the event logs but it’s just not sending or receiving the MQTT msgs (I can see this by using mosquitto_sub and looking at the Tasmota console for the device).
I can see the both the MQTT-2 Broker and StudyLightThing are Online from the paper UI in Configuration->Things

A restart of Openhab resolves the problem until I touch the config file again.

This is what the events log looks like (comments entered after the fact)

// Successful turning on and off of light connected to Tasmota device via MQTTV2
2021-08-30 14:40:02.120 [vent.ItemStateChangedEvent] - StudyLight changed from NULL to ON
2021-08-30 14:40:05.535 [ome.event.ItemCommandEvent] - Item 'StudyLight' received command OFF
2021-08-30 14:40:05.552 [nt.ItemStatePredictedEvent] - StudyLight predicted to become OFF
2021-08-30 14:40:05.576 [vent.ItemStateChangedEvent] - StudyLight changed from ON to OFF
// Made small non functional change to mqtt.things and saved and got the following event output
2021-08-30 14:40:19.002 [hingStatusInfoChangedEvent] - 'mqtt:broker:mosquitto' changed from ONLINE to OFFLINE
2021-08-30 14:40:19.013 [hingStatusInfoChangedEvent] - 'mqtt:topic:mosquitto:StudyLightThing' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2021-08-30 14:40:19.024 [hingStatusInfoChangedEvent] - 'mqtt:topic:mosquitto:StudyLightThing' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2021-08-30 14:40:19.026 [hingStatusInfoChangedEvent] - 'mqtt:broker:mosquitto' changed from ONLINE to OFFLINE
2021-08-30 14:40:19.027 [hingStatusInfoChangedEvent] - 'mqtt:topic:mosquitto:StudyLightThing' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2021-08-30 14:40:19.036 [me.event.ThingUpdatedEvent] - Thing 'mqtt:broker:mosquitto' has been updated.
2021-08-30 14:40:19.090 [hingStatusInfoChangedEvent] - 'mqtt:broker:mosquitto' changed from OFFLINE to ONLINE
2021-08-30 14:40:19.092 [me.event.ThingUpdatedEvent] - Thing 'mqtt:broker:mosquitto' has been updated.
2021-08-30 14:40:19.093 [hingStatusInfoChangedEvent] - 'mqtt:topic:mosquitto:StudyLightThing' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
// Tried again to turn the light on and off and it doesn't work but get the following in the event log
2021-08-30 14:40:22.369 [ome.event.ItemCommandEvent] - Item 'StudyLight' received command ON
2021-08-30 14:40:22.392 [nt.ItemStatePredictedEvent] - StudyLight predicted to become ON
2021-08-30 14:40:22.410 [vent.ItemStateChangedEvent] - StudyLight changed from OFF to ON
2021-08-30 14:40:23.988 [ome.event.ItemCommandEvent] - Item 'StudyLight' received command OFF
2021-08-30 14:40:24.014 [nt.ItemStatePredictedEvent] - StudyLight predicted to become OFF
2021-08-30 14:40:24.037 [vent.ItemStateChangedEvent] - StudyLight changed from ON to OFF

The openhab.log shows no errors and just this for the MQTT restart:
2021-08-30 14:40:19.014 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '127.0.0.1' with clientid 4d9fb1d1-bc45-4d78-aaaf-fb3796dc61aa

Any suggestions on what to do next would be appreciated.

When managing Thing configs from file, it’s pretty routine for some bindings to mess up adopting edited configs in-flight. Likely subscribe/unsubscribe here. As you’ll be doing a bit of this, it’s worth finding out how to restart binding package from karaf console.

I’m not entirely certain that still works any more. It worked for a time but I think one of the 2.5 point releases broke the ability to have both installed at the same time. You might try uninstalling the 1.x binding while working on the 2.x binding and see if that makes a difference.

When using .things files, often one needs to restart the binding to pick up the changes. I don’t know if that’s the case here because I think the changes are just ignored, not generating errors when that happens.

Indeed. The V2 docs suggest to remove the v1 binding before installing the V2 binding.

This binding is not supposed to run in parallel to the old mqtt1-binding. Please uninstall the old binding before installing this binding.

Indeed. The V2 docs suggest to remove the v1 binding before installing the V2 binding.

Ok - but does that mean there is no longer a way to incrementally migrate devices?

Not really. But you can:

  • leave your MQTT 1.x Items as they are with the 1.x config
  • uninstall the 1.x binding
  • install the 2.x binding
  • incrementally create your Things and link them to your Items
  • when done for the day remove the 2.x binding and reinstall the 1.x binding

I believe the old 1.x config and the channel links can exist on the same Item without error. The mqtt config will turn into Item metadata when the 1.x binding is uninstalled and so essentially ignored. There might be errors about attempting to create a Link to a non-existing Channel when the 2.x binding is not installed but that shouldn’t stop the Item from being loaded and the 1.x mqtt config from being used. But I think there won’t even be logs to worry about.

I’d give that a try at least.

I’ve done a bundle restart as per Rossko’s suggestion and that got me back into a working state (after an edit) and otherwise everything seems stable with both 1.x and 2.x bindings installed. I’ll try to progress a little more but will switch to Rich’s approach if I get any more issues.

Thanks all.

Mmm yeah, I overlooked that. If it’s going to work you need to take care that v1 and v2 bindings present different IDs to the broker. Else it can’t tell who is subscribed to what, which does sound like your issue.

Not really. But you can:

  • leave your MQTT 1.x Items as they are with the 1.x config
  • uninstall the 1.x binding
  • install the 2.x binding
  • incrementally create your Things and link them to your Items
  • when done for the day remove the 2.x binding and reinstall the 1.x binding

I believe the old 1.x config and the channel links can exist on the same Item without error. The mqtt config will turn into Item metadata when the 1.x binding is uninstalled and so essentially ignored. There might be errors about attempting to create a Link to a non-existing Channel when the 2.x binding is not installed but that shouldn’t stop the Item from being loaded and the 1.x mqtt config from being used. But I think there won’t even be logs to worry about.

I’d give that a try at least.