Remove autodiscovered MQTT Device - Hassio

Hi all,
I am running Home Assistant on a Raspberry Pi 3, Hassio.
I have the addon Zigbee2mqtt and use the Mosquitto broker. All works perfectly fine and I have now several devices to track and control

When starting, I flashed a cc2531 to test with a router software to play around and I no longer use them due to the limited range. It does however show up on the zigbee2mqtt networkmap:


link to the zigbee2mqtt map:

Is there a way I can remove this device from wherever it is stored?
I tried to find the solution in several places, but have not succeeded (from uninstalling, rebooting and re-installing the mosquitto broker, using MQTT.fx, ).
also tried with mosquitto_pub -h 192.168.1.52 -p 1883 -u myuser -P mypassword -t "zigbee2mqtt/0x00124b00014d2777" -r -n but this doesnĀ“t do anything.

Really have no clue anymoreā€¦ My main first doubt: am I using the right topic?
thanks for any insight!

Iā€™m pretty sure that the info for the map comes from the zigbee2mqtt database. So to get rid of that device you need to remove it from the database. To do that you have to issue a remove command in MQTT:

from that page:

zigbee2mqtt/bridge/config/remove

Allows you to remove devices from the network. Payload should be the friendly_name , e.g. 0x00158d0001b79111 . On successful remove a device_removed message is send.

1 Like

Thanks finity! you gave me the right direction!!!
I donĀ“t know how I can have missed the most basic documentationā€¦

I got it removed as you suggested using SSH CLI command :
mosquitto_pub -h 192.168.1.52 -u myuser -P mypassword -t zigbee2mqtt/bridge/config/remove -m 0x00124b00014d2777 and the confirmation is seen in the zigbee2mqtt log:

zigbee2mqtt:warn 2019-2-23 10:32:59 Failed to remove '0x00124b00014d2777', trying force remove...
zigbee2mqtt:info 2019-2-23 10:32:59 Successfully removed 0x00124b00014d2777
zigbee2mqtt:info 2019-2-23 10:32:59 MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"type":"device_removed","message":"0x00124b00014d2777"}'

Always have done this, but my issue is that the devices remains in home-assistant.

Do i need to remove those retained messages from the mqtt broker myself or is this supposed/ can be to be deleted automagically by a script?

Itā€™s really a lot more work then pairing a device.

I had the same issue today, since the topic was retained on my broker. However thereā€™s a very useful tool called MQTT Explorer which lets you easily remove retained messages.

2 Likes

Thanks for pointing out to MQTT Explorer. I will have it a spin.
It will stil be nice to have devices being ā€œauto-deletedā€ like we have with mqtt ā€œauto-discoveryā€. Maybe this will come in the futurešŸ¤·

Iā€™m having this issue with a sonoff tasmota device which I added by following the tasmota wiki:

# Example automations.yaml entry
- alias: "Enable MQTT discovery for all devices"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "cmnd/sonoffs/SetOption19"
        payload: "1"

I had to change the topic to sonoff/cmnd/SetOption19 for it to auto-discover.
However this is a bit misleading as it created a device in HA which is called switch.sonoff and if Iā€™m understanding this correctly If I connected 5 sonoffs and left their topic default it wouldnā€™t be able to distinguish them so Iā€™m not sure how much use this is? To differentiate I would have to enter a different topic for each one and then edit the configuration.yaml to have this for each? Defeats the object of auto discover but anyway I digressā€¦

Iā€™m trying to change the name of this sonoff away from the generic switch.sonoff to the one I have set under Client and Topic in the tasmota GUI. However it still appears as switch.sonoff in HA after deleting and removing every instance I can find. I would rename manually but it has multiple sensors and itā€™s not the point, why doesnā€™t HA pick up the new client name and topic name?? Iā€™ve tried this to stop it from remembering this name but no luck:

-Removed MQTT from integrations.
-Stopped HASS and removed from core.restore_state. core.entity_registry and core.device_registry doesnā€™t feature it as it was removed from integrations already.
-Restarted Mosquitto and checked the topic wasnā€™t kept with MQTT explorer.

After getting error Failed to remove I managed to remove it by using zigbee2mqtt/bridge/config/force_remove for instance:
mqtt_sh

So for anyone coming here when itā€™s seems all attempts to remove device from HA has failed: tried remove and force_remove by sending command, tried to remove mqtt integration from HA and restart it, tried to restart/reinstall zigbee2mqtt addon but finally - reinstalled mqtt addon which removed all persistent autodiscovery messages and removed devices are really gone :partying_face: