Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation or migration for changed unique entity id #33

Open
lichtteil opened this issue May 17, 2021 · 1 comment
Open

Documentation or migration for changed unique entity id #33

lichtteil opened this issue May 17, 2021 · 1 comment

Comments

@lichtteil
Copy link
Owner

With e13069a we introduced a new way of building the unique entity id. To prevent errors and confusion when updating component we need to add either a BIG warning and explanation or better a migration function that takes care of old entity IDs. Maybe we can set the new unique ID and at the same time use the existing ID as a customizer option of the entity.

@JoachimEngelmann do you have any idea on how we could do this? I was reading about the Hass entity registry but I'm a bit lost.

@Joe3n
Copy link
Contributor

Joe3n commented May 17, 2021

At the moment i don't know how this can be done automated. Homeassistant saves all registered entitys in "/config/.storage/core.entity_registry". With this change in the unique ID a new entry per sensor will be generated with a different unique_id (HA thinks this will be a new entry, while the old entry is orphaned)

Example for one sensor

e. g. Entry for temperature with old unique_id format (my sensor is called airdata)

{
"entity_id": "sensor.airdata_humidity",
"config_entry_id": null,
"device_id": null,
"area_id": null,
"unique_id": "airdata Humidity",
"platform": "local_luftdaten",
"name": null,
"icon": null,
"disabled_by": null,
"capabilities": null,
"supported_features": 0,
"device_class": "humidity",
"unit_of_measurement": "%",
"original_name": "airdata Humidity",
"original_icon": null
}

After the update the new entry would look like this:

{
"entity_id": "sensor.airdata_humidity_2",
"config_entry_id": null,
"device_id": null,
"area_id": null,
"unique_id": "airdata-BME280_humidity",
"platform": "local_luftdaten",
"name": null,
"icon": null,
"disabled_by": null,
"capabilities": null,
"supported_features": 0,
"device_class": "humidity",
"unit_of_measurement": "%",
"original_name": "airdata Humidity",
"original_icon": null
}

  1. After the update, you can see in HA (Configuration->Entity) two entries:
    grafik
  2. Delete the old entry (the one with the red sign at the end). This will also delete the entry in the core.entity_registry
  3. Open the new Entry
    grafik
  4. Change "Entity-ID" to the value of the deleted sensor
    grafik
  5. So only one entry per sensor remains, the history data will not be lost if you do it like this
    grafik
    grafik
    The gap in the graph was the time i took to work this update procedure out 😁

Not so smart alternative

Alternatively you could edit "/config/.storage/core.entity_registry" but i think this is a bad idea to directly edit a HA file... This i haven't tested and would be a hassle for the most users

@lichtteil lichtteil changed the title Add documentation or migration for changed unique entity id Documentation or migration for changed unique entity id Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants