Skip to main content
Entities are the fundamental building blocks of Home Assistant. They represent devices, services, and other stateful objects in your smart home.

What is an Entity?

An entity is an abstract representation of a function in Home Assistant. Each entity represents a specific capability or feature, such as a light, switch, sensor, or any other controllable or observable element in your home automation system.
Entities are uniquely identified by their domain, platform, and a unique ID provided by the integration.

Entity Structure

Every entity in Home Assistant has several key components:

Entity ID

Entity IDs follow the format domain.object_id, for example:
  • light.living_room
  • sensor.temperature
  • switch.bedroom_fan

Unique ID

Each entity has a unique identifier that persists across restarts and allows the entity to be tracked in the entity registry.

State

The current state of the entity (e.g., “on”, “off”, “23.5”).

Attributes

Additional information about the entity, such as:
  • friendly_name: Human-readable name
  • device_class: Classification of the entity
  • unit_of_measurement: Unit for numeric states
  • supported_features: Bitmask of supported features
  • icon: Icon to display in the UI

Entity Base Class

The Entity class in homeassistant/helpers/entity.py is the foundation for all entities in Home Assistant.

Key Properties

Entity Lifecycle

Entities go through several states during their lifecycle:
  1. NOT_ADDED: Entity not yet added to a platform
  2. ADDING: Preparing for addition to a platform
  3. ADDED: Entity added and active
  4. REMOVED: Entity removed from platform

State Management

Entities update their state using methods provided by the base class:

Writing State

Always use async_write_ha_state() for simple state updates. Only use async_update_ha_state(force_refresh=True) when you need to fetch new data before writing the state.

Entity Categories

Entities can be categorized to indicate their purpose:
  • CONFIG: Configuration parameters
  • DIAGNOSTIC: Diagnostic information
  • None: Primary functionality (default)

Entity Description

The EntityDescription class provides metadata for entities:

Entity Registry

The entity registry keeps track of all entities in Home Assistant. It provides:
  • Persistent storage of entity configuration
  • Entity ID generation
  • Tracking of disabled/hidden entities
  • Association with devices and config entries

Registry Entry

Each entity has a registry entry containing:

Creating Custom Entities

To create a custom entity, subclass the Entity base class or a domain-specific entity class:

Best Practices

Performance

Use _attr_ properties instead of @property methods when possible for better performance.

State Updates

Call async_write_ha_state() to update the state machine whenever the entity’s state changes.

Polling

Set should_poll = False for entities that push updates, rather than being polled.

Device Association

Provide device_info to associate entities with devices for better organization.

Devices

Learn about device management and association

State Machine

Understand how entity states are managed