| name | homeassistant |
| description | Expert HomeAssistant development skill for creating custom sensors (template, REST, command line, Python components), building Lovelace dashboards with custom cards and layouts, and developing custom integrations with config flows, coordinators, and multiple platforms. Use this skill when working with HomeAssistant YAML configuration, Python integration development, or dashboard customization. |
HomeAssistant Development
Overview
This skill provides comprehensive guidance for HomeAssistant development across three core areas: custom sensors, dashboards (Lovelace UI), and custom integrations. Use this skill when creating or modifying HomeAssistant configurations, developing custom Python components, or building user interfaces.
When to Use This Skill
Activate this skill when:
- Creating or modifying sensors (template, REST, command line, or Python-based)
- Building or customizing Lovelace dashboards and cards
- Developing custom integrations with Python
- Working with HomeAssistant YAML configuration files
- Implementing automations that require custom sensors or components
- Setting up device integrations or API connections
Core Capabilities
1. Custom Sensors
Template Sensors
Use template sensors for calculations, unit conversions, or combining multiple sensor values. Templates use Jinja2 syntax and are defined in YAML configuration.
When to use:
- Converting units (e.g., Celsius to Fahrenheit)
- Combining multiple sensor values (e.g., total power consumption)
- Creating derived values (e.g., "feels like" temperature)
- Status indicators based on other entity states
Implementation approach:
- Determine the source entities needed
- Write the Jinja2 template with proper fallback values using
| float(0)or| default() - Set appropriate
device_class,state_class, andunit_of_measurement - Add
unique_idfor UI customization capability - Test the template in Developer Tools → Template
Reference: See references/sensors.md for comprehensive template sensor examples and patterns.
RESTful Sensors
Use REST sensors to pull data from external APIs or web services.
When to use:
- Fetching data from external APIs
- Integrating web services without custom components
- Polling HTTP endpoints for status updates
Implementation approach:
- Identify the API endpoint and authentication method
- Configure the REST sensor with proper headers and authentication
- Use
value_templateto extract the desired value from JSON responses - Use
json_attributesorjson_attributes_pathfor additional data - Set appropriate
scan_intervalto balance freshness and API limits
Reference: See references/sensors.md for REST sensor configuration patterns.
Command Line Sensors
Use command line sensors to execute shell commands and use their output as sensor values.
When to use:
- Reading system information not available through standard integrations
- Executing custom scripts or binaries
- Processing file contents or system resources
Reference: See references/sensors.md for command line sensor examples.
Python Custom Component Sensors
Use custom Python components when sensor logic is too complex for templates or requires external libraries.
When to use:
- Complex calculations or data processing
- Integration with Python libraries
- Stateful sensors that need to maintain data between updates
- Performance-critical operations
Implementation approach:
- Create directory structure:
custom_components/<domain>/ - Start with the integration template in
assets/integration_template/ - Implement
sensor.pywith proper entity classes - Use
DataUpdateCoordinatorfor efficient data fetching - Implement proper error handling and logging
Reference: See references/sensors.md for Python sensor implementation details.
2. Lovelace Dashboards
Create intuitive, responsive user interfaces using Lovelace cards and custom layouts.
Planning a Dashboard
Approach:
- Identify the entities to display (lights, sensors, switches, etc.)
- Group related entities by room or function
- Choose appropriate card types for each entity type
- Consider mobile vs desktop layout
- Plan views (tabs) for different areas or purposes
Core Card Types
Entities Card - List multiple entities with controls:
- Best for control panels and grouped controls
- Supports sections, dividers, and custom icons
- Can show secondary information (last-changed, entity-id)
Button Card - Single entity with large tap target:
- Best for frequently-used controls
- Customizable icons and colors
- Supports tap, hold, and double-tap actions
Gauge Card - Visual representation of numeric values:
- Best for monitoring metrics (CPU, temperature, battery)
- Configure min/max and severity thresholds
- Visual feedback at a glance
Picture Elements Card - Interactive image with overlays:
- Best for floor plans or device diagrams
- Position controls and labels on images
- Create custom visual interfaces
Conditional Card - Show/hide based on conditions:
- Display cards only when relevant
- Reduce clutter by hiding inactive elements
- Stack multiple conditions for complex logic
Layout Strategies
Grid Layout - Responsive grid of cards:
- Automatically adjusts columns based on screen width
- Consistent sizing with
square: falsefor flexible heights - Best for collections of similar items
Vertical/Horizontal Stack - Group cards together:
- Stack cards to create logical groupings
- Combine with conditional cards for dynamic layouts
- Control card order and spacing
Custom Cards (HACS)
Install custom cards via HACS for enhanced functionality:
- Mini Graph Card - Compact sensor history graphs
- Button Card (Custom) - Advanced button customization
- Mushroom Cards - Modern, minimalist card designs
- ApexCharts Card - Powerful charting and graphing
Installation steps:
- Install HACS if not already installed
- Go to HACS → Frontend
- Search for the desired card
- Install and add resource reference
- Use in dashboard with
type: custom:<card-name>
Reference: See references/dashboards.md for comprehensive card examples, custom card configurations, and layout patterns.
3. Custom Integrations
Develop full-featured integrations with Python for complex device or service integrations.
When to Create a Custom Integration
- Integrating a device or service not supported by existing integrations
- Complex logic that can't be handled by REST sensors or templates
- Multiple related entities (sensors, switches, lights) from one source
- Need for device registry integration
- Requiring coordinator-based efficient data fetching
Integration Structure
Required files:
manifest.json- Integration metadata, dependencies, and requirements__init__.py- Integration setup and platform loadingconfig_flow.py- UI-based configuration (recommended)- Platform files (
sensor.py,switch.py, etc.) - Entity implementations
Optional but recommended:
coordinator.py- Centralized data fetchingconst.py- Constants and configuration keysstrings.json- UI text and translations
Development Workflow
Step 1: Plan the Integration
- Identify the device/service API or protocol
- List the entity types needed (sensors, switches, lights, etc.)
- Determine authentication and connection requirements
- Plan data update strategy (polling vs push)
Step 2: Start with Template
Copy the integration template from assets/integration_template/ to custom_components/<your_domain>/:
cp -r assets/integration_template custom_components/my_device
Step 3: Customize Manifest
Update manifest.json:
- Set unique
domain(lowercase, underscores) - Update
name,documentation,codeowners - Add Python package dependencies to
requirements - Set appropriate
iot_class(local_polling, cloud_polling, etc.)
Step 4: Implement Config Flow
In config_flow.py:
- Define configuration schema (host, port, API key, etc.)
- Implement connection validation in
_test_connection - Handle errors appropriately (cannot_connect, invalid_auth, etc.)
- Support discovery if applicable (SSDP, Zeroconf)
Step 5: Implement Coordinator
In coordinator.py:
- Create API client or device communication class
- Implement
_async_update_datato fetch device data - Handle errors and raise
UpdateFailedon failures - Set appropriate
update_interval
Step 6: Implement Platforms For each platform (sensor.py, switch.py, etc.):
- Create entity classes inheriting from
CoordinatorEntityand platform base - Set proper device classes, state classes, and units
- Implement
native_valueproperty to return current state - Add
DeviceInfoto group entities under one device - Set
unique_idfor each entity
Step 7: Test and Iterate
- Copy to HomeAssistant's
custom_components/directory - Restart HomeAssistant
- Add integration via UI (Settings → Devices & Services)
- Monitor logs for errors
- Test all entity states and controls
- Verify device registry entry
Best Practices
Data Fetching:
- Always use
DataUpdateCoordinatorto centralize API calls - This prevents multiple entities from making duplicate requests
- Coordinator automatically handles retries and error states
Error Handling:
- Use try/except blocks around all I/O operations
- Log errors with appropriate severity levels
- Raise
UpdateFailedin coordinator when data fetch fails - Return
Noneor fallback values for unavailable data
Entity Design:
- Always set
unique_idto enable UI customization - Use appropriate
device_classfor proper icon and unit handling - Set
state_classfor sensors that should appear in statistics - Group related entities using
DeviceInfo
Code Quality:
- Use type hints throughout (
-> bool,: str, etc.) - Follow HomeAssistant code style (use pylint)
- Use async/await for all I/O operations
- Import only necessary modules
Configuration:
- Prefer
config_flow.pyover YAML configuration - Validate user input before accepting
- Provide clear error messages
- Support reloading configuration when possible
Reference: See references/integrations.md for complete integration development guide with detailed code examples.
Resources
references/
Detailed documentation loaded into context as needed:
sensors.md- Comprehensive sensor implementation guide covering all sensor types, device classes, state classes, and best practicesdashboards.md- Complete Lovelace dashboard reference with card types, custom cards, layouts, and design patternsintegrations.md- In-depth custom integration development guide with file structure, coordinator patterns, and platform implementation
When to read references:
- Read
sensors.mdwhen implementing any type of sensor - Read
dashboards.mdwhen building or modifying dashboards - Read
integrations.mdwhen developing custom Python integrations
assets/
Template files used in development output:
integration_template/- Complete, working integration boilerplate with:manifest.json- Integration metadata template__init__.py- Integration setup with coordinatorconfig_flow.py- UI configuration flowcoordinator.py- Data update coordinatorsensor.py- Example sensor platform with multiple sensorsconst.py- Constants filestrings.json- UI translationsREADME.md- Customization guide
When to use assets:
- Copy
integration_template/as starting point for new integrations - Customize the template by replacing "my_integration" with actual domain
- Follow the README.md for step-by-step customization instructions
Development Tips
Testing Templates
Use Developer Tools → Template in HomeAssistant to test Jinja2 templates before adding to configuration.
Checking Configuration
Run Configuration → Check Configuration before restarting HomeAssistant to catch YAML errors.
Viewing Logs
Monitor logs at Settings → System → Logs or via command line:
tail -f /config/home-assistant.log
Reloading Without Restart
Many components support reload without full restart:
- Developer Tools → YAML → Reload Template Entities
- Developer Tools → YAML → Reload Automations
- Developer Tools → YAML → Reload Scripts
Debugging Custom Integrations
Add debug logging to configuration.yaml:
logger:
default: info
logs:
custom_components.my_integration: debug
Version Compatibility
Always check HomeAssistant version compatibility:
- Template syntax may change between versions
- Entity platform APIs evolve with releases
- Test integrations on target HomeAssistant version
- Review breaking changes in release notes