Entity Basics
What is an Entity?
An entity represents a single piece of functionality from a device or service. Examples:- A temperature sensor
- A light bulb
- A media player
- A switch
- A unique ID for identification
- A state (on/off, temperature value, etc.)
- attributes with additional information
- An entity ID like
sensor.living_room_temperature
Entity Platforms
Home Assistant has different entity platforms for different types of entities:sensor- Read-only measurementsbinary_sensor- On/off sensorsswitch- On/off switcheslight- Lights with brightness, color, etc.climate- Thermostats and climate controlcover- Blinds, garage doors, etc.- And many more…
Creating an Entity Platform
Each entity platform is a separate Python file in your integration directory.Platform Setup Function
Every platform must have anasync_setup_entry function:
sensor.py
Creating an Entity Class
Entity classes inherit from a base entity class specific to their platform.Basic Entity Example
Entity Properties
The Entity base class provides many properties you can override:Essential Properties
Modern Entity Naming
Use the modern naming pattern with device info:State Updates
There are several ways to update entity state:Method 1: async_update (Polling)
Method 2: Push Updates (Recommended)
Method 3: DataUpdateCoordinator (Best Practice)
Platform-Specific Features
Sensor Platform
Switch Platform
Light Platform
Entity Attributes
You can add extra attributes to entities:Entity Categories
Use entity categories to organize entities:EntityCategory.CONFIG- Configuration entitiesEntityCategory.DIAGNOSTIC- Diagnostic informationNone- Primary entities (default)
Entity Registry
When you set a unique_id, entities are automatically registered:- Users can customize entity names and icons
- Users can disable entities they don’t need
- Entity IDs are stable across restarts
- Entities can be tracked across config changes
Dynamic Entity Addition
For devices that support dynamic entities:Entity Availability
Indicate when an entity is unavailable:Best Practices
Always Use Unique IDs
Provide unique IDs for all entities to enable customization:Use Device Info
Group related entities under a single device:Use DataUpdateCoordinator
For polling integrations, useDataUpdateCoordinator to efficiently manage updates.
Disable Polling When Possible
If your API supports push updates, disable polling:Handle Exceptions
Gracefully handle API errors:Use Modern Naming
Set_attr_has_entity_name = True and provide device info for better entity naming.