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.