lichtteil / local_luftdaten

Custom component for Home Assistant that integrates your (own) local Luftdaten sensor (air quality/particle sensor) without using the cloud.
MIT License
46 stars 19 forks source link

Documentation or migration for changed unique entity id #33

Open lichtteil opened 3 years ago

lichtteil commented 3 years ago

With e13069a84eb7d6778a8bae674e450736285b8c2c 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 commented 3 years ago

At the moment i don't know how this can be done automated. Homeassistant saves all registered entitys in _"/config/.storage/core.entityregistry". 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.entityregistry
  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 :grin:

Not so smart alternative

Alternatively you could edit _"/config/.storage/core.entityregistry" 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