Config Flow
Config Flows enable users to configure integrations through the Home Assistant UI instead of manually editing YAML files. This guide covers implementing config flows for your integration.Overview
Config flows are defined by implementing aConfigFlow class in your integration’s config_flow.py file. The system manages the multi-step configuration process, validation, and storage.
Config flows are the recommended way to configure integrations. They provide a better user experience and enable features like discovery and reconfiguration.
Basic Structure
A config flow inherits fromConfigFlow and defines steps:
config_flow.py
Flow Result Types
Fromdata_entry_flow.py:28, flows return different result types:
Common Flow Steps
Creating Entries
async_create_entry
Creates a config entry and completes the flow:- title: Displayed name in the UI
- data: Immutable configuration data
- options: User-configurable options (can be changed via options flow)
Aborting Flows
async_abort
Stops the flow with a reason:Unique IDs
Prevent duplicate configurations:Multi-Step Flows
Complex configuration can span multiple steps:Options Flow
Allow users to modify options after configuration:Discovery Sources
Different discovery methods have specific steps:Error Handling
Display errors to users:strings.json:
strings.json
Progress Steps
Show progress for long-running operations:Menu Steps
Provide multiple options:Real-World Example: MQTT Config Flow
Fromhomeassistant/components/mqtt/config_flow.py:66:
- Manual configuration
- Hassio discovery
- Reconfiguration
- Options flow for discovery settings
Best Practices
Validate Input
Use Selectors
Fromconfig_flow.py:121, use modern selectors:
Handle Reauth Properly
Next Steps
Entity Platforms
Implement entity platforms for your integration
Creating Components
Return to component creation guide