Prevent automatic id creation for esphome devices

Hi, I use esphome for many of my devices and I keep seeing devices being created appended with _1 , _2 _3 in Homeassistant. While this would not have been a problem, it is becoming so as sometimes when HA restarts the old entity is disabled and a new one defined. This breaks all my flows on nodered and lovelace configuraitons. Every now and then I see new entities created and I have go to and fix it in all places.
Can somebody explain to me as to why such entities are created and how can I prevent this?
Thank you.

When you use :api it automatically creates entities, also whenyou use :mqtt if you use both you get double the entities :slight_smile:

If you use :mqtt there is also a way of cleaning old entries: https://esphome.io/components/mqtt.html?highlight=mqtt#using-with-home-assistant

1 Like

Oh yes thanks for reminding me about that. But then even if I have both the :api and :mqtt defined the entities should remain valid. For some devices I have seen the entity working fine for months and then suddenly a _2 jumps out and the original entity is disabled breaking my configurations.
Can I go back and change these entities to what I want - I dont want _1 , _2 defined. I have cleaned up the unused ones but stuck with these as I dont know where are these being defined by HA.

You should use one or the other not both api and mqtt. Also a static ip might help. Though I would have thought the unique id would be the MAC address (which does not change).

Hi @tom_l , I have cleaned up my entities now so dont know if it is related to using both the api & mqtt integrations on the same device but will keep a watch on this the next time it happens.
Do you know how can I manually edit this information, like at present for a switch I am using _3 entity while the base , _1 & _2 are disabled (in fact I have cleaned them off). I want to go back to using the base entity, how do I do that?

The cog icon on the entity card should allow you to edit the entity id. I vaguely remember having trouble with this. I think I had to restart after deleting the other duplicates before I could remove the appended number.

I tried that but couldnt. eg I have an entity named “switch.dining_fan_2” when I rename it to “switch.dining_fan” using the Entity view , it gives me an error “Entity is already registered” although none exist. I deleted off the entity named “switch.dining_fan” and don’t see that in the entity view anymore.
Tried restarting etc too…

Yeah that was the issue I had. I thought a restart fixed it.

In the entities list make sure you have the “show disabled entities” filter enabled (top right of the window). Make sure they have been deleted and not just disabled.

Yep, tried all what you suggested. Still the same. There must be a way to edit this manually in the files, will try to find it on the internet somewhere.

Yeah there is. In config/.storage (hidden folder).

Make a backup of the file before editing it.

Try very hard to maintain the json structure inside the file.

core.entity_registry is the file you want.

great, thanks will try this out.

Looked through all my entities and it was because of the same entity being created via MQTT & ESPHome platforms.
I also figured out why was it not allowing me to delete the MQTT entities even after restarting HA. That was because the MQTT topics still existed. If the MQTT topics exist the symbol for the entity is a bold red icon (on the integration page) while once you delete the topics , the icon changes to a light red icon , that’s when you can delete it off.
Thanks everybody for help!