ESPHome entity duplicated after updates

I don’t know if this is a HA problem or a ESPHome problem so spun the wheel and posting here.

Running HassOS on a NUC-like Lenovo PC. Small system. I’ve been upgrading steadily as I see updates via the configuration page.

Changed an automation template to do integer math instead of float math with temperatures. I don’t think this has anything to do with the problem but explains why I was “in there” today.

Everything appeared to be working fine.

Upgraded to ESPHome 2022.1.1 (from the previous version).

I then updated each of my ESPHome devices. A NodeMCU and 4 smart outlets.

Upgraded to Home Assistant Core 2021.12.10 (from the previous version).

On my Lovelace dashboard I notice that “Garage Outdoor Temperature” is “Unavailable”. I restarted ESPHome. No improvement. I restarted server management. No improvement. I rebooted the host. No improvement.

I went to ESPHome and clicked on “Logs” for the device that provides this entity. I watched for a bit and saw that it’s sending a temperature update. Lovelace still says “Unavailable”.

The device is a NodeMCU running ESPHome with a Dallas DS18B20 temperature sensor. The ESPHome sensor configuration follows:

sensor:
  - platform: dallas
    # test at home
    #address: 0xAF0417C1AC55FF28
    # 269 garage
    address: 0xD50417C2038CFF28
    name: "Garage Outdoor Temperature"

Back on HA, I look at the ESPHome integration and expand the NodeMCU device. Says there’s 1 device and 7 entities. I click on the “7 Entities” and notice that there are now two “Garage Outdoor Temperature” entities. One has a “_2” added to the entity ID. That one seems to work. The old, original entity has a red circle arrow on the far right with an exclamation point in the middle, and when I hover over the icon I see the word “Restored”.

This is the only entity that appears to have duplicated itself.

I’m 700 miles away from this HA system and it’s a small configuration. I decide to edit the Lovelace dashboard to use the new “_2” entity ID, and I updated the automations as well. My OCD doesn’t like this and I’m happy it’s a small configuration. The system is working again.

I’m hesitant to do more until I visit the location later this year. I wanted to report this to see if anyone understands what happened. Seems to be a bug somewhere.

1 Like

Yeah I’ve had this happen when editing the esphome config for a device.

You can delete the original sensor (without the _2) in the entities list, restart home assistant, then rename the sensor entity id in the entities list by removing the _2.

You will have to change your Lovelace config back to using the sensor without the _2.

1 Like

Thanks! My OCD thanks you very much!

2 Likes

I had this issue today and I filled a bug report:

@felipecrs Have you not encountered this since? Because I had the exact same thing happen to one of my ESPs during a firmware upgrade quite recently … somewhere between 2023.9.0 and 2023.9.3 … it took a while for me to notice the device was unavailable in HA, so not sure exactly when this happened, but more recent than the apparent ‘fix’ ?

No, this issue didn’t happen to me recently. But if it happened to you, make sure to report it like I did.

Yeah, I get over 30 entities from that single ESP so manually fixing them all will not be fun. Would be nice to be sure this won’t happen again on a future update. I’ll go and het myself a github account then. Thanks!

My issue was closed with a fix linked few days ago:

Maybe this problem is finally gone now.

Had the same problem today, after the last ESP-Home update! It´s not funny with a lot of devices… hopefully this doesn´t happen again

I also had the same problem. Is there a quick fix for the duplicate entities that have added the “_2” on their name ?

This issue just happened to me as well updating device firmware. Super annoying and causing a lot of wasted time having to fix all of the entities. This absolute shouldn’t be happening.

Also happened to me again today after the ESPHome update. Thankfully my installation is small. Besides deleting and renaming, I had 2 automations that seemed to break. Had to go through the UI definition again to get them working.

1 Like

Also had this issue today after updating to 2023.12.0 and 2023.12.1 again
Touched only Climate:Haier devices (4 of them)
While Custom switch was ok both times…

It appears there was a bug in release 2023.12.0 where - were processed as disallowed characters. This was fixed in release 2023.12.1. To correct any affected devices you can restore from a add-on back that was created when upgrading to 2023.12.0 (assuming you have backups enabled when updating) then reinstall the devices firmware. This should get your devices to use the original entities. From there you can upgrade to 2023.12.1.

https://github.com/esphome/esphome/pull/5983

I’ve experienced duplicated entities after updating ESPHome config on one of my devices last night. I’m using release 2023.12.4 of HA, and 2023.12.5 of ESPHome. Curiously, only the Xiaomi BLE sensor devices were duplicated, not the other types of entities that the ESPHome device exposes (e.g. binary_sensor). I note that all the other exposed entities are using template platforms, but I don’t know if that has anything to do with it.

Still a bit annoying though since the temperatures, humidity and battery level sensors are used throughout my installation!

Edit: just to clarify what I mean about “duplicated”. The duplicated sensor entities have the same ID as those already existing in HA, but with a “_2” appended to the end of it. These sensor names have been changed in HA to something more meaningful, and might be a possible clue to the problem, but I’ve also renamed other exposed entities in HA, but they have not been duplicated as I mentioned above.

Ok, can confirm it’s the same disallowed characters issue caused by the latest ESPHome release. I didn’t fancy removing and re-installing the device, so instead, I did the following:

  1. Disabled the device in the ESPHome integration screen.
  2. Now that the device is disabled, remove the extra unwanted entities using the UI.
  3. Using nano in the SSH terminal, edit /config/.storage/core.entity_registry file to change the “unique_id” field of the original entities to that produced by the new version of ESPHome (search for “_2” to find the unwanted entities in the file). I also took the opportunity to delete the unwanted entities from the “deleted_entities” section towards the end of the file.
  4. Save the file, and immediately restart HA. This will ensure that the core.entity_registry file is not overwritten by the version held in memory, and allows the updated version of the registry to be reloaded.
  5. Once it has restarted, go back to the ESPHome integration and enable the device. All being well, the original entities will be back online without the duplicate entities.
1 Like

I can also confirm that it’s disallowed/special characters causing the issues. I did have 3 entities with issues. I did follow @welshcoder instructions to fix my issue.

The issue appeared after updating esphome from 2023.11.6 to 2023.12.3. Not sure if the device itself was on an older fw.

I updated from esphome 2023.10.x to 2023.12.5 - one entity containing an special character (which is already replaced in entity_id) was duplicated.
Will i lose entity history on following @welshcoder instructions?

short time data lost, history retained :slight_smile: