I’m experiencing an issue with the HomeAssistant MQTT Discovery binding and would like to know whether this is a known problem or if anyone has experienced something similar.
Environment
openHAB 5.2.0
Mosquitto MQTT broker
Devices are integrated using HomeAssistant MQTT Discovery
Most of the affected devices are provided by Marstek via hm2mqtt
Problem
Occasionally, channels of automatically discovered Things disappear completely/partly. As a result, existing Item links become orphan links.
The observed effects are:
Items lose their channel links.
Values are no longer updated.
Orphan links appear in the UI.
Rediscovering or recreating the affected Things restores functionality temporarily, but the problem eventually reoccurs.
The issue does not affect all discovered Things, onlythe four marstek things
Question
Is this a known issue with the HomeAssistant MQTT Discovery binding in openHAB 5.2.0?
If so:
Is there a recommended workaround?
Are there any debug logs I should enable to help identify the root cause?
Is it recommended to use manually configured MQTT Generic Things instead of HomeAssistant Discovery for better long-term stability?
Any advice or pointers would be greatly appreciated.
No, it’s not one I’m seeing nor one I’ve seen reported. I’m using Home Assistant with Theengs Gateway, Zigbee2MQTT, and NetAlertX.
Look at the JSON posted to the config topics before and after the Channels disappear. You can find the list of config topics under the Thing Configuration with the MQTT Base Prefix prepended. For example the MQTT Base Prefix is “homeassistant” and one of the config topics is “binary_sensor/0x282c02bfffe7c35a/battery_low” the config topic will be “homeassistant/binary_sensor/0x282c02bfffe7c35a/battery_low”.
Are those topics disappearing that configure the missing Channels? Is the JSON posted there valid? An example:
A very strange behavior today.
When i had to leave the house I had a lot (30+) health issues in OH.
Some minutes ago I checked the requested yaml thing and there were only 2 orphan link issues
All of the above. If what ever is populating that configuration posts an empty message, invalid JSON, or otherwise corrupted configuration I would expect the Home Assistant binding to remove that Channel.
But you need to see what’s actually published to the MQTT topic. You can’t use OH for this. By then it’s too late. You need to use mosquitto_sub or MQTT Explorer or something to watch the MQTT traffic.
But I do not understand where on this way openhab is deleting existing channel code?
Is it possible, as a work around, to copy the code into a things file in config/things folder?
Or ist it a different syntax?
You need to find the corresponding discovery topics for the device under the “homeassistant” topic. That’s where the binding gets all the information to create the Thing.
The most likely cause of the problem is this discovery information is changing and leaving out “channels”. If the discovery JSON published there, the OH Thing will change so if a “channel” is removed there, the channel is removed from the Things.
There will be multiple topics for each device under homeassistant for each device.
There are two different syntaxes, DSL or YAML. You can choose use either in a file. But if the device is changing the discovery and topic stuff on the fly, you’ll likely just change the error or the Channels will just silently stop reporting anything.
You can also create a Generic MQTT Thing and define all the channels. Again, if the device changes what it publishes OH will just silently fail to update.
But the retained sign is not there and the error message is also very present.
For my understanding.
The Things definition via homeassistant MQTT message is there.
If I copy the original complete code into the existing thing everything is fine.
After a undefined time the thing channel definition ist partly gone. some are still existing
EDIT:
in OH GUI Things config I can see under MQTT Config Topic
all switches/sensors etc.
But some channels are not existing. Maybe this will help?
EDIT 2:
I recognized recently that the thing is for a short time marked as offline in OH.
Should there be in the homeassitant mqtt definition under each sensor/button/etc config a kind of retained=true setting?
First, click on the actual message (the config line). That is where you should see the retained flag.
The retained flag is set by the publisher of the message. There is nothing you can do from the OH side to enable it.
But this confirms what I suspected. Whatever is publishing the config message is changing it. OH is going to change the Thing’s configuration based on what ever it finds there.
I suspect the retained flag is there, but you are reporting that the message is changing. This config message should not change. So the root of the problem is what ever is publishing this message and is nothing that can be addressed from the openHAB side. OH is doing exactly what it’s told to do.
The only ways to address this is to fix it in what ever is publishing these messages, or use the Generic MQTT Thing manually configured to subscribe, publish and transform the messages as necessary.
However, beware of the latter approach as it will mask the root problem, not solve it. Your orphaned links will go away, but when those Channels go away in the config message I suspect whatever is publishing the config messages will stop publishing to those missing topics when they are removed from the config message.
I investigated the logs for the period 13:54–15:47.
In this time frame the error happend again.
openHAB findings:
At 14:19:55:
Dispatching event to subscriber
'org.openhab.core.config.discovery.internal.AutomaticInboxProcessor'
takes more than 5000ms.
At 14:21:51:
[ERROR] [core.thing.internal.ThingManagerImpl]
Exception occurred during notification about bridge status change
on thing 'mqtt:homeassistant:mymosquitto:hame_5Fenergy_5F1480cc': null
AutomaticInboxProcessor ... takes more than 5000ms
There are further AutomaticInboxProcessor delays later (15:42, 16:32).
hm2mqtt side:
I also compared the Home Assistant MQTT Discovery payloads. hm2mqtt republishes the discovery information, but I could not find any content changes: the discovery objects remain identical (same number and contents of the 348 discovery objects). I therefore currently have no evidence that hm2mqtt is publishing an incomplete or changed discovery configuration.
My current suspicion:
The problem may be on the openHAB side, around MQTT bridge status handling / Home Assistant MQTT Discovery processing. The timing of the bridgeStatusChanged exception and the long-running AutomaticInboxProcessor events is suspicious and may be related to the disappearing channels.
I am now checking events.log around 14:19–14:23 to determine whether any Things or Channels were actually removed or modified at that exact time.
I’m also starting to look at hm2mqtt for some new Marstek devices I’ll be installing.
t looks to me like you have several Marstek B2500 v2 storage batteries. Do they all have the same firmware version, and have you meticulously followed the detailed instructions given on the repo’s page about setting up multiple B2500 v2 batteries?
EDIT: OK, I see you have also already opened an issue for the repo
All are on the same firmware. And yes, I followed the instruction.
The only way I am doing different is that I do not use Toms “fake energy meter”
I am adjust the output level with a handwritten OK rule.
And as I wrote, it worked for approx a year without issues. And then they started the described issue.
I hope you eventually find what is causing this issue, and somehow think it likely has to do with the republishing of the homeassistant discovery messages – something you could look up in the history of these discovery messages, to also see if and how the republishing differs from the previously published discovery message.
I haven’t looked into hm2mqtt closely enough yet, to see if its is possible to turn off the homeassistant discovery at all, because once the discovery messages are retained in your MQTT broker there should be no need to republish them at all; very similar to what I’ll be doing by defining everything manually in textual config files, as I do with all my other numerous MQTT devices/
I think turning off the discovery message publishing is definitely something to look into for your issue … obviously once everything has been correctly discovered once
And are you restarting hm2mqtt every now and then by any chance?