Duplicate entries with _2

duplicate entries with _2…


After the update Homeassistant to the newest version I had the following ID’s twice.
They are all:

  • timer
  • input_select
  • input_number
  • input_datetime
  • counter
  • automation
  • sensor based on template

After rollback to version Home Assistant 0.104.3 they are still there. The original IDs all have the attributes:

restored: true
supported_features: 0

Deleting the core.restore_state file and restarting it didn’t change anything.
All of my automations and sensor templates no longer work with the double entries.
How can I delete the duplicate entries with _2 so that the original entries are used again?

Example sensor template:

    ## ####################################
    ## checks the heating periode 
    ## ####################################
      friendly_name: Heizungszeit
      entity_id: sensor.time
      value_template: >- 
         {% set mapper = {'Jänner':1,'Februar':2,'März':3,'April':4,'Mai':5,'Juni':6,'Juli':7,'August':8,'September':9,'Oktober':10,'November':11,'Dezember':12} %}
         {% set start  = mapper[states.input_select.heating_startmonth.state]|int %}
         {% set end    = mapper[states.input_select.heating_endmonth.state]|int %}
         {% if (utcnow().month>=start) or (utcnow().month<=end) %}on{% else %}off{% endif %}
        current: "{{utcnow().month}}"
        start:   "{{states.input_select.heating_startmonth.state}}"
        end:     "{{states.input_select.heating_endmonth.state}}"
        date:    "{{now().strftime('%Y-%m-%d')}}"

How can I solve this problem ?

You dont mention if you are using Home Assistant or Home Assistant Core, but assuming the former, try restoring from a snapshot from before the upgrade.

Thank you for the feedback.

I’m not sure, but I don’t think I have a snapshot or backup. Would deleting the database (mysql) help? I then lose all the historical data, but if it works then that’s a reasonable solution.

Home Assistant 0.104.3
Pfad zu configuration.yaml: /home/homeassistant/.homeassistant 

arch 	x86_64
dev 	false
docker 	false
hassio 	false
os_name 	Linux
python_version 	3.7.5
timezone 	Europe/Vaduz
version 	0.104.3
virtualenv 	true
mode 	yaml
resources 	20
views 	9

Nope deleting the database will make no difference.

Backup. Backup. Backup. Especially before upgrading.

Had the same problem at one point in time, don’t know why that happened but was not related to a upgrade. I suspect is has something to do with the editor in Lovelace for automations.
Have a look in the core.entity_registry file stored in .storage, there you probably will find the duplicates.
If I remember correctly i stopped HASS, removed all duplicates in the file and then restarted HASS.
Be careful (a backup is a good suggestion before doing this) and good luck!

Thank, negativ i can’nt find any duplicates (*._2) in the core.entity_registry file, only
in the core.restore_state file.

core.restore_state file

            "last_seen": "2020-03-25T12:37:24.004449+00:00",
            "state": {
                "attributes": {
                    "friendly_name": "Min. Temperatur",
                    "icon": "mdi:target",
                    "initial": 15.0,
                    "max": 30.0,
                    "min": 1.0,
                    "mode": "slider",
                    "step": 0.5,
                    "unit_of_measurement": "\u00b0C"
                "context": {
                    "id": "287f14197cbf4ad5b2d4506889d10791",
                    "parent_id": null,
                    "user_id": null
                "entity_id": "input_number.heating_min_temp_2",
                "last_changed": "2020-03-25T10:36:00.580241+00:00",
                "last_updated": "2020-03-25T10:36:00.580241+00:00",
                "state": "15.0"

core.entity_registry file

                "capabilities": {},
                "config_entry_id": null,
                "device_class": null,
                "device_id": null,
                "disabled_by": null,
                "entity_id": "input_number.heating_min_temp",
                "name": null,
                "platform": "input_number",
                "supported_features": 0,
                "unique_id": "heating_min_temp",
                "unit_of_measurement": "\u00b0C"

This means that the two files (core.entity_registry file, core.restore_state file ) are not syncron and therefore the original entries are referenced. If I delete the core.restore_state file, it will be rebuilt exactly the same way.

I want to find out where this data comes from so that the incorrect entries are not created.

click on the unavailable one… delete it. Rename the other.

I can remove the unavailable (orphan) one, but this is used in all my automations and scripts.
Rename the duplicate entry “*_2” is not possible, so all automations and scripts do not work.

You may need to restart after deleting the unavailable one before you can rename the _2 one

I’ve never had to do that. Whenever this happens I simply remove the ‘bad one’, rename the good entity_id. In that order. Home assistant doesn’t care that it’s being used in automations.

It only happened with deconz for me, but if definately makes a difference in my case

I vaguely remember having to restart before being able to rename my Lifx (or maybe ESPHome) duplicates.

Delete all unavailable (orphan) items and restart Homeassistant.
Now all is working as before

1 Like

Where can we rename entity IDs?

there’s a number of ways to get to it. Typically, if you click on an entity of a device a popup will appear. In the upper right corner there’s a cog for that popup. If you can adjust the entity_id, that page will be filled with a form that allows you to do so. Otherwise there will be some cryptic error about ‘unique id’… which basically means “you can’t change the entity_id”.

Thanks, @petro. Indeed, I get the message:

I thought that ‘unique ID’ and ‘entity ID’ were two different fields, but based on your response it seems to be one and the same field.

In my YAML config file, I created mqtt binary sensors. As I wanted these sensors to have a stable ID, independent of their name, I specified unique IDs. This however generated duplicates of that entity.
I removed the unique IDs from my configuration.yaml, and then removed the duplicate entities.
The remaining entities had a “_2” at the dnd of theor ID, and I saw no way of changing that.

However, after a full restart, the _2 have disappeared from the ID.

Is there another way of having a stable entity ID, which does not depend of its label? Could I specify a label using ‘alias’?

Apparently this has never been fixed, as I’m also having issues with this. I have some devices which use MQTT discovery to register their sensors with HA. I made sure every sensor registers and uses a unique_id in the hopes of getting a stable ID to use in automations.

However, when the devices restart or re-establish wifi connection, I sometimes get duplicate sensors with the same label but a different ID. This prevents automations from triggering, even though everything looks fine on the dashboard.

If it comes through discovery, that means your unique_id is not persistent. You can look in the entity_registry to confirm that. Look for your entity with out the _2 and with the _2 and you’ll see what the registered unique_id is.

@petro - how to make the id persistent, because I do have exactly the same problem. I have sonoffs dual r3 and whenever they do restart (i.e. due to me doing some changes) I do see duplicate ids with _2 being active and the previous ones that are used in dashboards and everywhere being inactive and thus not working. This is quite annoying.

That depends on how you integrated the switches and what you did when you made changes.