Migrating unique ids

I have a custom component which allows multiple entities per device. Currently it has a limitation of one entity of each type, and is using the same unique id for all entities tied to a device, with the entity type being the differentiating factor.

Now I want to expand it to allow multiple ids of the same type on a device, and to do this I have to add some extra identifying info to the device id.

I can do this as a breaking change, where the users will have to remove and re-add their devices, but if possible Iā€™d like to handle the entity registry changes in async_migrate_entry.

Is this possible? Are there any examples of other components that have done this?

yes, I am not an expert on this, but this looks relevant for a starting point. link

1 Like

Thanks. The key seems to be calling async_migrate_entries from homeassistant.helpers.entity_registry for doing the entity registry migration, with a callback that sets "new_unique_id" in the returned Dict.

The example in the link above also updates the unique_id of the config entry itself, but in my case the device is keeping the same unique_id, only some of the entities under it need to change.