Unfortunately I don’t have experience on this. But may what says Gemini could help. Does it makes sense ti you? Here it is:
To allow a user to use this function for the entities of your integration, you need to ensure two main things are implemented in your code:
1. Assign a Unique ID
This is the most crucial element. Every entity your integration creates must have a unique and persistent identifier. Home Assistant uses this ID to save the entity in the entity registry (entity_registry) and allow it to be modified in the UI (like manually changing the ID or using the “Recreate entity IDs” function).
- Implementation: In your entity class (which inherits from the base entity class, e.g.,
homeassistant.components.sensor.SensorEntity), you must define the_attr_unique_idattribute.`Python# Example for a Sensor entity
from homeassistant.components.sensor import SensorEntity
class MyEntity(SensorEntity):
def __init__(self, ...):
# ... (other initializations)
# The unique ID must be a stable string,
# specific to the physical or logical entity/device.
self._attr_unique_id = f"{self.device_id}_my_unique_sensor"
# self.device_id would be the unique ID of the device
# Alternatively, you can use the `Entity.async_set_unique_id` method
# when adding the entity, but setting the attribute is common.`
Important Note: The unique ID must not change over time or between Home Assistant restarts.
2. Link Entities to a Device
For the “Recreate entity IDs” function to appear on the device page, all entities must be correctly linked to a Device in the Home Assistant device registry (device_registry).
- Implementation: Define the
_attr_device_infoattribute of your entity. This tells Home Assistant which Device (represented by aDeviceEntry) this entity belongs to.`Pythonfrom homeassistant.helpers.entity import DeviceInfo
# In your entity class
self._attr_device_info = DeviceInfo(
# The unique identifier of the device
identifiers={(DOMAIN, self.device_id)},
name="My Device Name",
# Optional: manufacturer, model, sw_version, etc.
)`The `DeviceEntry` should be created (if necessary) during your integration's setup (often via a `ConfigEntry`).
In Summary:
The “Recreate entity IDs” function is a built-in feature of Home Assistant. You don’t need to add specific code to “activate” the button itself. You only need to follow best integration development practices by providing a unique_id for every entity and linking them to a device via device_info.

