How do we remove retired MQTT entities?

Hi there,

I have a number of MQTT devices that were originally setup without a unique ID so they are not editable in the GUI. Many have since been retired or renamed and I’m getting a flurry of error logs pertaining to entities that do not exist. I found three topics on this in the forums and all remain unanswered so if anyone has a trick, that would be appreciated.

mqtt:
  sensor:
    - name: "FKB Tablet Battery Level"
      state_topic: "fully/deviceInfo/galaxytab10"
      unit_of_measurement: "%"
      device_class: battery
      value_template: "{{ value_json.batteryLevel }}"  

This was renamed from Battery FKB Tablet to FKB Tablet Battery Level and as you’ll see below, I now have two entities. I cannot edit or delete the top one which is no longer valid.

image

1 Like

Is there a retained message from that entity in your MQTT broker?

if so then you need to delete that retained topic then hopefully it should get removed.

1 Like

Ooh, good point. Let me try that and report back.

No retain set so nothing to remove. I found a workaround and that is to re-add the device adding a unique_id: as shown below.

  binary_sensor:
    - name: "FKB Tablet Charging Status"
      unique_id: fkb_tablet_charging_status_retired
      state_topic: "fully/deviceInfo/galaxytab10"
      payload_on: true
      payload_off: false    
      qos: 0
      device_class: battery_charging
      value_template: "{{ value_json.isPlugged }}"

After doing that, restart, then remove the yaml altogether and restart again. After that, the entity can now be removed using the GUI.

2 Likes

Hi, I realise that you have already found a solution but I thought I would mention I have used MQTT Explorer in the past to delete topics on the MQTT Broker in situations where old entities could not be deleted in HA.

Yes, me too. That’s how I normally do it but in a few cases like the one I mentioned, there’s no topic to delete.

Ah OK, thanks for letting me know.

I can’t find a way to remove mqtt selects that were once defined manually via the yaml configurations, but are later deleted or renamed. They are shown in the GUI, exist too, but without connection to mqtt.

And there is no way to delete them via the GUI (or however). In the list of entities they are shown as “read only”, so you can’t select them and you can’t delete them.

I have also deleted the topics from the MQTT broker via the MQTT Explorer. But all this does not help.

This unfortunately clutters up the entities for me, especially when they might just be renamed. And it makes it difficult to keep track of them.

If I do a full text search in the config directory, then some are found in a markdown map used for debug.

it was my fault. I renamed a file containing the definitions into xxx.yaml_ to disable the content, but somehow it was renamed into xxx.yaml_.yml and therefore it was not disabled.

i have the same problem in mqtt i can’t remove entities that are no longer there…
I’m referring to schelly who from mqtt or moved to cloud.

Could someone explain to me how to do it?