Delete Entity

I have a bunch of Xioami Temperature/Humidity Sensors and have a question about them.
I have over a dozen scattered throughout my house. About every 6 months I have to change the battery.
Once the new battery is installed HA creates a new entity for it
IE: sensorbattery_a4c138370444, sensorbattery_a4c138370444_2, sensorbattery_a4c138370444_3 and so on. With _3 being the one that was created today.

This also happens on a few other devices as well.

I know I can delete the first and second sensor in config/.storage/core.entity_registry but can I delete all of them, do a restart and have them be recognized again.

Trying to save some work to edit a lot of lovelace and automations.
Thanks

Which type of sensors do you have? I have many of the Xioami Aqara Zigbee Temperature/Humidity sensors and they certainily do not behave like this.

I don’t think you should be editing anything within /.storage as you risk causing a corruption.

Worst case you should be able to delete the _1 and _2 entities from the Integration page and then rename the new _3 entity as _1 eliminating the need to change any of your Lovelace config.

This means little. Xiaomi makes many similar devices which connect in different ways.

They are the Xiaomi Mijia Thermometer 2 Bluetooth-compatible Smart Remote Control Temperature Humidity Sensor with LCD Screen (LYWSD03MMC)

I have 3 ESP32 “ble trackers” that they sync to.

I have no problem with the devices fairly accurate, but as I say every time I change the battery it creates a new entity.

Thanks

I guess it depends how the ESP32 creates the unique_id of the sensor, if it does.

If it stays the same, you wouldn’t have duplicate.

If it doesn’t, or does not create one, you’ll get duplicates, but the old ones should appear as “orphans” (red “unavailable” icon). In my experience, if you delete the old ones and restart, the last one should roll back to having no suffix.

Are you using esphome?

Yes the esp8266 is using esp home.

What esp8266? You spoke about 3 esp32 “piloting” your BLE devices… :crazy_face:

Aha. I use openmqttgateway on my esp32 for LYWSD03MMC’s, and I never have new entities when I change batteries.

I use an esp32 and when I change batteries no new entities are created.

But if they were, I would delete the esp32 device in ha config|integrations and reload it.

@francisp I have never used openmqttgateway can you explain how you set it up.
Thanks to everyone.