MQTT homeassistant Things become "Unknown" when broker status changes

Where you able to check the HA configs (not just the topics) in MQTT explorer after an interruption? If they disappear only momentarily it may cause OH unsubscribe them. I did see in your second link that the publishing app needs to use the retain flag when publishing the HA configs.

Retain: The -r switch is added to retain the configuration topic in the broker. Without this, the sensor will not be available after Home Assistant restarts

The generic MQTT channels in OH tie directly to the topics, so would recover. (from earlier post it sounds like the topics are retained).

Also, there was an earlier OH issue with HA configs where they were renamed on restart. Maybe that fix caused this new problem (on the OH side).

In my case, the config topic messages are retained and so always available unless the server goes away. Which - it does in this case, given traefik goes offline briefly. It’s the same as mosquitto stopping and restarting essentially (and probably has the same effect, I haven’t tested).

In short, I don’t think this is an issue with the MQTT messages as they are. It’s the binding and how it handles availability. It doesn’t seem to handle the existence of a new message on a data topic as evidence of availability - instead waiting for a non-existent (in my case) availability topic to show that device is back online.

It’s not wrong per se.. Just fairly strict.

1 Like

My devices all transmit MQTT messages directly to the broker. Any time a device goes down, for example powered off, the availability topic, or last will and testament (LWT), changes.

I have powered down mqtt.homeassistant devices that are in “unknown” state, confirmed with mqtt explorer that the LWT changes state and powered them back on. They remain “unknown”

What might be interesting is to run a MQTT binding scan to see what happens when they are powered, but unknown. My understanding of OH is that discovery and thing handlers are related, but separate. The log above shows the HA config was completely zapped, so the online/offline status of that channel is also gone.

IMO the question is why the HA configs (basically channels) of a “Thing” are getting zapped. With most bindings the “Thing” itself goes offline, and the channels stay there (or become orphans?) and come back when the device goes online.

How would I do that?

From the inbox?

I should add that by “interesting” I’m not sure what will happen. Ideally the unknown “Things” will come online via discovery. The downside is a duplicate device might be created. I was thinking your test on just one device would be enough to find out.

I’m not sure what you mean by “binding scan”?

The Inbox contains all devices discovered by mqtt.homeassistant. They include devices for which I created Things manually as well as Things that were created through mqtt.homeassistant. For the mqtt.homeassistant Things the ones Online as well as Unknown are shown.

Each discovered mqtt.homeassistant device, both currently Online and Unknown, allows me to add it as a Thing, ie create a duplicate Thing for that device. In the case of the Unknown Thing the duplicate is Online. The Unknown one remains Unknown.

A noteworthy item for mqtt.homeassistant Things that are currently Online.

If power to the device is turned Off, the availability topic or LWT goes Offline and the Thing state changes to OFFLINE. When power is turned back on, the availability topic or LWT goes Online and the Thing state changes to ONLINE.

For an Thing in Unknown state, the availability topic (LWT) will also change status, but the Thing remains in Unknown state.

It appears that when a mqtt.homeassistant Thing goes into an Unknown state it somehow loses its connection to the MQTT broker which includes the availability topic (LWT).

There is a difference between the broker starting and stopping and device or client, in your case traefik going offline.

In the case of the availability topic (LWT), it’s the broker’s responsibility to monitor and change the state of the message and send it to all subscribed clients (OH). The broker sends a LWT message if the devices fails to send communication within a Keep Alive period, closes a connection unexpectedly (eg power off event), protocol errors, in other words any time the device and broker are not communicating. Typically LWT messages are configured to be retained by the broker so if a new client subscribes to messages from an Offline field device the broker will inform the new client that the field device is Offline.

If a broker is stopped all communication between devices, clients, OH, etc. is lost. The availability topic for the devices connected to the broker would not change state in this case and not be updated to any device subscribed to the broker.

I incorrectly thought traefik was sending mqtt data to the broker.

2025-10-07 12:18:34.272 [DEBUG] [ab.binding.mqtt.generic.ChannelState] - Unsubscribed channel mqtt:homeassistant:4d0a5b9184:123b6a1b85ef:car_last_seen from topic: blegateway/state/123b6a1b85ef
etc
    private void internalStop() {
        logger.debug("Unsubscribed channel {} from topic: {}", this.channelUID, config.stateTopic);
        this.connection = null;
        this.channelStateUpdateListener = null;
        hasSubscribed = false;
        cachedValue.resetState();
    }

The developer will need to provide the final word, but when traefik goes offline briefly, the HA Thing has its channels (HA configs) unsubscribed (not just losing a connection -it’s gone). IMO This is supported by the Scan (if I understand that post correctly) when a duplicate HA thing is discovered. The duplicate Thing to me means there is no knowledge in OH of the previous HA Thing. Although the config is gone internally in OH, out of curiosity what does the UI code tab look like on an unknown Thing? Specifically, are the HA configs still there? The listener has been removed, so it doesn’t really matter.

I have a vague memory of something similar, but I’ll need to search the forum.

Also I don’t think this happens with all apps that generate HA things, but would need to test on my production system (with ZUI) and I’m not in a position to do that right now.

I’m not sure what you mean by that comment. I’m able to duplicate both Online and Unknown devices / Things through the Inbox with mqtt.homeassistant.

Unknown Thing UI Code tab:

UID: mqtt:homeassistant_b8060d8d30b8:Mosquitto:Treatlife_ss01_06
label: Treatlife_ss01_06
thingTypeUID: mqtt:homeassistant_b8060d8d30b8
configuration:
  topics:
    - sensor/treatlife_ss01_06/chipset
    - sensor/treatlife_ss01_06/ip_address
    - sensor/treatlife_ss01_06/libretiny_version
    - sensor/treatlife_ss01_06/make
    - sensor/treatlife_ss01_06/model
    - sensor/treatlife_ss01_06/uptime
    - sensor/treatlife_ss01_06/wifi_signal
    - switch/treatlife_ss01_06/switch
  basetopic: homeassistant
bridgeUID: mqtt:broker:Mosquitto
channels:
  - id: chipset
    channelTypeUID: mqtt:ha-string
    label: Chipset
    configuration:
      component: sensor
      config:
        - '{"name":"Chipset","ic":"mdi:tag","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/chipset/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPsensorchipset","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - chipset
  - id: ip_address
    channelTypeUID: mqtt:ha-string
    label: IP Address
    configuration:
      component: sensor
      config:
        - '{"name":"IP
          Address","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/ip_address/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"b8060d8d30b8-wifiinfo-ip","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - ip_address
  - id: libretiny_version
    channelTypeUID: mqtt:ha-string
    label: LibreTiny Version
    configuration:
      component: sensor
      config:
        - '{"name":"LibreTiny
          Version","ic":"mdi:cellphone-arrow-down","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/libretiny_version/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPsensorlibretiny_version","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - libretiny_version
  - id: make
    channelTypeUID: mqtt:ha-string
    label: Make
    configuration:
      component: sensor
      config:
        - '{"name":"Make","ic":"mdi:watermark","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/make/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPsensormake","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - make
  - id: model
    channelTypeUID: mqtt:ha-string
    label: Model
    configuration:
      component: sensor
      config:
        - '{"name":"Model","ic":"mdi:tag","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/model/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPsensormodel","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - model
  - id: switch
    channelTypeUID: mqtt:ha-switch
    label: Switch
    configuration:
      component: switch
      config:
        - '{"name":"Switch","stat_t":"treatlife_ss01_06/switch/switch/state","cmd_t":"treatlife_ss01_06/switch/switch/command","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPswitchswitch","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - switch
  - id: uptime
    channelTypeUID: mqtt:ha-number
    label: Uptime
    configuration:
      component: sensor
      config:
        - '{"dev_cla":"duration","unit_of_meas":"s","stat_cla":"total_increasing","name":"Uptime","ic":"mdi:timer-outline","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/uptime/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"b8060d8d30b8-uptime","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - uptime
  - id: wifi_signal
    channelTypeUID: mqtt:ha-number
    label: WiFi Signal
    configuration:
      component: sensor
      config:
        - '{"dev_cla":"signal_strength","unit_of_meas":"dBm","stat_cla":"measurement","name":"WiFi
          Signal","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/wifi_signal/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"b8060d8d30b8-wifisignal","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - wifi_signal

Duplicate Online Thing UI Code tab:

UID: mqtt:homeassistant:Mosquitto:treatlife_ss01_06_2
label: treatlife_ss01_06
thingTypeUID: mqtt:homeassistant_b8060d8d30b8
configuration:
  topics:
    - sensor/treatlife_ss01_06/chipset
    - sensor/treatlife_ss01_06/ip_address
    - sensor/treatlife_ss01_06/libretiny_version
    - sensor/treatlife_ss01_06/make
    - sensor/treatlife_ss01_06/model
    - sensor/treatlife_ss01_06/uptime
    - sensor/treatlife_ss01_06/wifi_signal
    - switch/treatlife_ss01_06/switch
  basetopic: homeassistant
bridgeUID: mqtt:broker:Mosquitto
channels:
  - id: chipset
    channelTypeUID: mqtt:ha-string
    label: Chipset
    configuration:
      component: sensor
      config:
        - '{"name":"Chipset","ic":"mdi:tag","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/chipset/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPsensorchipset","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - chipset
  - id: ip_address
    channelTypeUID: mqtt:ha-string
    label: IP Address
    configuration:
      component: sensor
      config:
        - '{"name":"IP
          Address","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/ip_address/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"b8060d8d30b8-wifiinfo-ip","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - ip_address
  - id: libretiny_version
    channelTypeUID: mqtt:ha-string
    label: LibreTiny Version
    configuration:
      component: sensor
      config:
        - '{"name":"LibreTiny
          Version","ic":"mdi:cellphone-arrow-down","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/libretiny_version/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPsensorlibretiny_version","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - libretiny_version
  - id: make
    channelTypeUID: mqtt:ha-string
    label: Make
    configuration:
      component: sensor
      config:
        - '{"name":"Make","ic":"mdi:watermark","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/make/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPsensormake","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - make
  - id: model
    channelTypeUID: mqtt:ha-string
    label: Model
    configuration:
      component: sensor
      config:
        - '{"name":"Model","ic":"mdi:tag","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/model/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPsensormodel","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - model
  - id: switch
    channelTypeUID: mqtt:ha-switch
    label: Switch
    configuration:
      component: switch
      config:
        - '{"name":"Switch","stat_t":"treatlife_ss01_06/switch/switch/state","cmd_t":"treatlife_ss01_06/switch/switch/command","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"ESPswitchswitch","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - switch
  - id: uptime
    channelTypeUID: mqtt:ha-number
    label: Uptime
    configuration:
      component: sensor
      config:
        - '{"dev_cla":"duration","unit_of_meas":"s","stat_cla":"total_increasing","name":"Uptime","ic":"mdi:timer-outline","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/uptime/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"b8060d8d30b8-uptime","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - uptime
  - id: wifi_signal
    channelTypeUID: mqtt:ha-number
    label: WiFi Signal
    configuration:
      component: sensor
      config:
        - '{"dev_cla":"signal_strength","unit_of_meas":"dBm","stat_cla":"measurement","name":"WiFi
          Signal","ent_cat":"diagnostic","stat_t":"treatlife_ss01_06/sensor/wifi_signal/state","avty_t":"treatlife_ss01_06/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"b8060d8d30b8-wifisignal","dev":{"ids":"b8060d8d30b8","name":"treatlife_ss01_06","sw":"2024.12.1
          (Mar 23 2025,
          19:07:07)","mdl":"generic-bk7231n-qfn32-tuya","mf":"Beken","cns":[["mac","b8060d8d30b8"]]}}'
      nodeid: treatlife_ss01_06
      objectid:
        - wifi_signal

Not a solution, but a data point that this is not an issue with ZUI (Zwave-js-UI).

Test: Activated on HA Thing. Config from MQTT. One difference is that there are three availability options.

{
  "payload_off": false,
  "payload_on": true,
  "value_template": "{{ value_json.value }}",
  "command_topic": "zwave1/Lights_-_5/switch_binary/endpoint_0/targetValue/set",
  "state_topic": "zwave1/Lights_-_5/switch_binary/endpoint_0/currentValue",
  "availability": [
    {
      "payload_available": "true",
      "payload_not_available": "false",
      "topic": "zwave1/Lights_-_5/status",
      "value_template": "{{'true' if value_json.value else 'false'}}"
    },
    {
      "topic": "zwave1/_CLIENTS/ZWAVE_GATEWAY-zwave-js-ui/status",
      "value_template": "{{'online' if value_json.value else 'offline'}}"
    },
    {
      "payload_available": "true",
      "payload_not_available": "false",
      "topic": "zwave1/driver/status"
    }
  ],
  "availability_mode": "all",
  "device": {
    "identifiers": [
      "zwavejs2mqtt_0xf1c43721_node5"
    ],
    "manufacturer": "Zooz",
    "model": "Z-Wave Plus On/Off Toggle Switch (ZEN23)",
    "name": "Lights - 5",
    "sw_version": "3.3.1"
  },
  "name": "Lights - 5",
  "unique_id": "zwavejs2mqtt_0xf1c43721_5-37-0-currentValue"
}

In MQTT Explorer online

Then I shutdown the application

When Shutdown the Thing was offline in OH (Not unknown)

offline2025-10-09 090526

Interestingly only the driver was false. The other availability topics were retained from before the shutdown (note the timestamps were the same).

And was back online after the restart

After 2025-10-09 094531

The question still remains what is triggering the OH binding to purge the channel in traefik rather than simply mark offline (it has to related to the LWT as that is the only availability parameter) and what can be done in OH (or in the app sending the config), however, it is not a universal problem IMO (from this test).

Hey everyone, just wanted to report that after no changes from my end, I started having severe mqtt issues to the point that I changed my broker, and in the middle of the troubleshooting I’ve recognized this behavior of staying “unknown” after the broker goes offline. I had never recognized it before.

Restarting the home assistant bundle was not sufficient, the manual “save” got them back online. The issue is that I have over 20 zigbee devices so this is a bit painful. Hope I don’t encounter this behavior very often.

Hi @Pedro_Liberal , would you also please post something in the GitHub issue [mqtt.homeassistant] Things Created with MQTT Homeassistant suddenly go to UNKNOWN state · Issue #19431 · openhab/openhab-addons · GitHub

Hopefully it generates some input from one of the maintainers to either troubleshoot and/or resolve this issue. Thanks

1 Like

Done!

Hi @jimtng, apologies for the direct message. I’m wondering if you have any idea how to get a bit of help from a maintainer to troubleshoot this issue? Thanks

The maintainer is @ccutrer

1 Like

Hello @ccutrer , Apologies for the direct message. We have an issue with the mqtthomeassistant binding. Is there anything that we can do to help troubleshoot this issue and get it resolved? Thanks.

Only 20? Doesn’t sound that painful to me :wink:. I currently have 219 zigbee devices, with 43 waiting to be installed. Plus a few other Home Assistant devices (I used to have quite a few more – to the tune of ~200 – but I’ve migrated to dedicated bindings for ZWave-JS and ESPHome). But yes, quite painful when it happens - I usually just restart openHAB because it’s easier. BUT… I very very rarely see this happen when I’m not messing with things. I run Mosquitto and openHAB on the same server, neither in Docker. So openHAB loses its MQTT connection only once in a blue moon.

Yes, I’m aware of the issue. The easiest reproduction is to just disable and re-enable your broker thing. I want to get around to fixing it sometime, but I have relatively limited time for my openHAB contributions, so I tend to prioritize around fixing basic functionality issues, or contributing to newer features I need for a project that makes my wife happier (or less annoyed at my hobby, depending on perspective!). I do want to get around to this sometime, but unfortunately since I rarely experience the issue myself has meant it’s a lower priority for me. BUT… the more people that chime in (on the GitHub issue please, I don’t follow the forums as much), the more likely I am to prioritize it over other things when I have time for stuff that’s more in the community’s interest than my own.