homeassistant.helpers.entity module provides the Entity base class and related utilities for creating entities in Home Assistant.
Entity Class
TheEntity class is an abstract base class that all Home Assistant entities must inherit from.
Key Properties
str
Unique identifier for the entity (format:
domain.object_id)str | UndefinedType | None
Name of the entity
StateType
Current state of the entity
bool
default:"True"
Whether the entity is available
str | None
Unique identifier for the entity across restarts
DeviceInfo | None
Information about the device this entity belongs to
str | None
Icon to use in the frontend (format:
mdi:icon-name)str | None
URL of picture to use in the frontend
bool
default:"False"
True if unable to access real state of the entity
bool
default:"True"
True if entity has to be polled for state, False if entity pushes its state
int | None
Flag of features supported by the entity
str | None
Device class of the entity from component DEVICE_CLASSES
str | None
Unit of measurement for the entity’s value
EntityCategory | None
Category of the entity (config, diagnostic)
Key Methods
async_write_ha_state
Write the state to the state machine.async_update_ha_state
Update Home Assistant with current state of entity.bool
default:"False"
If True, update entity before setting state
async_schedule_update_ha_state
Schedule an update ha state change task.bool
default:"False"
If True, force entity refresh
async_on_remove
Add a function to call when entity is removed or not added.CALLBACK_TYPE
required
Callback function to call on removal
Helper Functions
generate_entity_id
Generate a unique entity ID based on given entity IDs or used IDs.str
required
Format string for entity ID (e.g.,
"light.{}")str | None
required
Name to use for generating the entity ID
list[str] | None
default:"None"
List of currently used entity IDs
HomeAssistant | None
default:"None"
Home Assistant instance (required if current_ids is None)
str
Generated unique entity ID
get_capability
Get a capability attribute of an entity.HomeAssistant
required
Home Assistant instance
str
required
Entity ID to get capability from
str
required
Name of capability to retrieve
Any | None
Capability value or None if not found
get_device_class
Get device class of an entity.HomeAssistant
required
Home Assistant instance
str
required
Entity ID
str | None
Device class or None
get_supported_features
Get supported features for an entity.HomeAssistant
required
Home Assistant instance
str
required
Entity ID
int
Bitfield of supported features (0 if none)
get_unit_of_measurement
Get unit of measurement of an entity.HomeAssistant
required
Home Assistant instance
str
required
Entity ID
str | None
Unit of measurement or None
EntityDescription
Dataclass that describes Home Assistant entities.str
required
Key identifier for this entity
str | None
default:"None"
Device class
EntityCategory | None
default:"None"
Category of entity
bool
default:"True"
Whether entity should be enabled when first added
bool
default:"True"
Whether entity should be visible when first added
bool
default:"False"
Force state update even if value hasn’t changed
str | None
default:"None"
Icon for the entity
bool
default:"False"
Whether the name describes only the entity itself
str | UndefinedType | None
default:"UNDEFINED"
Name of the entity
str | None
default:"None"
Translation key for the entity name
str | None
default:"None"
Unit of measurement
Constants
SLOW_UPDATE_WARNING = 10- Seconds before warning about slow updatesFLOAT_PRECISION- Precision for float state representationCAPABILITIES_UPDATE_LIMIT = 100- Max capability updates per hour before warning