ha-entity-lifecycle
Installation
SKILL.md
Home Assistant — Entity Lifecycle and Registries
Entity Lifecycle
- Platform discovery:
async_setup_entrycalled on platform - Entity creation: Entities instantiated, passed to
async_add_entities - Registration: HA assigns
entity_id, registers in entity registry - First update:
async_added_to_hasscalled, initial state written - Updates: Coordinator triggers
_handle_coordinator_update - Removal:
async_will_remove_from_hassfor cleanup
class MyEntity(CoordinatorEntity):
async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
# Restore previous state
if (last_state := await self.async_get_last_state()) is not None:
self._attr_native_value = last_state.state
Related skills