Entity Platforms
Entity platforms are the core building blocks that represent controllable or observable elements in Home Assistant. This guide covers implementing different entity types for your integration.Platform Architecture
Platforms are separate Python modules within your integration, one for each entity type you support:Available Platforms
Fromhomeassistant.const.Platform:
- light - Lights
- switch - Switches
- sensor - Sensors
- binary_sensor - Binary sensors
- climate - Climate devices (thermostats)
- cover - Covers (blinds, garage doors)
- fan - Fans
- lock - Locks
- media_player - Media players
- camera - Cameras
- vacuum - Vacuum cleaners
- water_heater - Water heaters
- And many more…
Basic Platform Structure
Every platform follows the same pattern:Entity Base Class
All entities inherit fromEntity (from homeassistant/helpers/entity.py):
Using
_attr_* attributes is the modern approach. They’re automatically exposed as properties.Light Platform
Basic Light Implementation
light.py
Color Support
For RGB/RGBW lights:homeassistant/components/demo/light.py:94):
Sensor Platform
Basic Sensor
sensor.py
Device Class: Indicates the type of sensor (temperature, humidity, etc.)State Class: For statistics and long-term data (
measurement, total, total_increasing)Native Value: The sensor’s value in its native unitStatistics and Units
- Unit conversion
- Statistics collection
- Long-term storage
- Graphing
Switch Platform
switch.py
Binary Sensor Platform
binary_sensor.py
Climate Platform
climate.py
Entity Features
Unique ID
Every entity should have a unique ID:Device Info
Group entities under devices:Availability
Indicate when entities are unavailable:Entity Category
Categorize entities:CONFIG- Configuration entitiesDIAGNOSTIC- Diagnostic informationNone- Regular entities (default)
State Updates
Platform Setup Methods
Fromhomeassistant/helpers/entity_platform.py:96:
Use
async_setup_entry for modern config-entry-based integrations.Use async_setup_platform only for legacy YAML-based platforms.Best Practices
Use Async Methods
Batch Entity Creation
Handle Missing Data
Next Steps
Integration Overview
Understand the full integration architecture
Config Flow
Add UI configuration to your integration