Openhab-addons: [mqtt] Textual configuration results in flaky connection status

Created on 17 Dec 2018  路  10Comments  路  Source: openhab/openhab-addons

Expected Behavior

Changing a thing configuration file should not break the some things.

Current Behavior

Changing a thing configuration file, where items are already linked to channels (possibly not the root cause for the issue), results in errors, there the configured things are not able use the MQTT client.

2018-12-16 12:14:11.446 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mqtt.things'

==> mosquitto/mosquitto.log <==
1544958851: Client paho439851773078352 disconnected.

==> openhab2/openhab.log <==
2018-12-16 12:14:11.529 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'x.x.x.x' with clientid paho481440911850144 and file store '/var/lib/openhab2/mqtt/x.x.x.x'

==> openhab2/events.log <==
2018-12-16 12:14:11.541 [hingStatusInfoChangedEvent] - 'mqtt:broker:MosquittoMqttBroker' changed from ONLINE to OFFLINE
2018-12-16 12:14:11.542 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs01' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2018-12-16 12:14:11.542 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs03' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2018-12-16 12:14:11.543 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs04' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2018-12-16 12:14:11.543 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs06' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
2018-12-16 12:14:11.544 [hingStatusInfoChangedEvent] - 'mqtt:broker:MosquittoMqttBroker' changed from ONLINE to OFFLINE
2018-12-16 12:14:11.544 [me.event.ThingUpdatedEvent] - Thing 'mqtt:broker:MosquittoMqttBroker' has been updated.
2018-12-16 12:14:11.556 [hingStatusInfoChangedEvent] - 'mqtt:broker:MosquittoMqttBroker' changed from OFFLINE to ONLINE
2018-12-16 12:14:11.558 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs04' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2018-12-16 12:14:11.559 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs01' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2018-12-16 12:14:11.562 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs06' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2018-12-16 12:14:11.562 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs03' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2018-12-16 12:14:11.564 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs02' changed from UNINITIALIZED to INITIALIZING
2018-12-16 12:14:11.566 [me.event.ThingUpdatedEvent] - Thing 'mqtt:broker:MosquittoMqttBroker' has been updated.
2018-12-16 12:14:11.568 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs02' changed from INITIALIZING to OFFLINE (COMMUNICATION_ERROR): java.lang.Exception: No MQTT client
2018-12-16 12:14:11.575 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs05' changed from UNINITIALIZED to INITIALIZING
2018-12-16 12:14:11.578 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs05' changed from INITIALIZING to OFFLINE (COMMUNICATION_ERROR): java.lang.Exception: No MQTT client
2018-12-16 12:14:11.583 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs07' changed from UNINITIALIZED to INITIALIZING
2018-12-16 12:14:11.585 [hingStatusInfoChangedEvent] - 'mqtt:topic:SonoffPs07' changed from INITIALIZING to OFFLINE (COMMUNICATION_ERROR): java.lang.Exception: No MQTT client

Full configuration example for this is at https://community.openhab.org/t/using-sonoff-power-switches-with-tasmota-firmware-and-openhab2-mqtt2-binding/.

Possible Solution

Based on a discussion on https://community.openhab.org/t/reliability-of-binding-mqtt/59646/26 the issue seems to be related to a timing problem while reloading the configuration. At the time, where the things are loaded and assigned to the bridge, the bridge is not fully connected or in ONLINE state.

Steps to Reproduce (for Bugs)

Not 100% sure. Please check the configuration on https://community.openhab.org/t/using-sonoff-power-switches-with-tasmota-firmware-and-openhab2-mqtt2-binding/](Using Sonoff Power Switches with Tasmota firmware and openHAB2 MQTT2 binding). I don't know, if this is reproducable for now.

Your Environment

  • Ubuntu 18.04 Virtual Machine (VMware ESX), with openHAB unstable repository.
  • openhab2 (2.4.0~S1461-1)
  • bundle:list | grep "Eclipse SmartHome MQTT"
    229 | Active | 80 | 0.10.0.201812141650 | Eclipse SmartHome MQTT Binding
    230 | Active | 80 | 0.10.0.201812141650 | Eclipse SmartHome MQTT Thing Binding
    238 | Active | 80 | 0.10.0.201812141650 | Eclipse SmartHome MQTT Transport Bundle
ohc bug

All 10 comments

Please note that the correct issue tracker would be https://github.com/eclipse/smarthome/issues.
@davidgraeff fyi.

Should be fixed now

I think we can close this here once the next ESH stable is available.

I've upgraded from OpenHAB 2.1 towards 2.4 and changed my complete config, but still struggling with this issue. Is there a way to bypass the issue or to apply a quick fix?

Workaround: Move the line that defines your MQTT broker into a separate file and don't touch that file while openHAB is running.
Alternative: Define your Broker Thing in the UI and use it from your text configuration files.

Thanks, this helped but I eventually gave up on the JSON transformations. I'll retry once there is a more stable and better version (2.5?).

JSON transformations

You mean the JSONPATH transformation? Works perfectly and is automatically tested and documented as well.

Workaround: Move the line that defines your MQTT broker into a separate file and don't touch that file while openHAB is running.
Alternative: Define your Broker Thing in the UI and use it from your text configuration files.

@davidgraeff - Can you provide a simple example? It is unclear to me how to do that since I define my thing inside of the Bridge which defines the broker?

For example, my config looks like this:

Bridge mqtt:broker:mosquitto [ host="mosquitto.aocboc", secure=false, clientID="openhab", username="user", password="pass" ]
{
    Thing topic brultech {
    Channels:
        Type number : volts "Current Voltage" [ stateTopic="/house/energy/249808_volts" ]
    }
}

If I define the broker in a broker.thing file how do I avoid redefining it in the mqtt.thing file? In the blog post they are broken out, but the mqtt.thing defines parameters for the broker again.

Don't ask me for how to define Thing files, I am the biggest opposer of .thing files as you probably know. But maybe someone else can help.

The latest ESH stable with the MQTT bugfixes is integrated. So let's close this issue here.
Please use the ESH issue tracker for future MQTT Binding related issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

openPhiL picture openPhiL  路  5Comments

d3rh3ld picture d3rh3ld  路  4Comments

Nikos78 picture Nikos78  路  5Comments

pfink picture pfink  路  4Comments

J-N-K picture J-N-K  路  6Comments