Skip to main content

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 a ConfigFlow 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 from ConfigFlow and defines steps:
config_flow.py

Flow Result Types

From data_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:
Define error messages in strings.json:
strings.json

Progress Steps

Show progress for long-running operations:
Provide multiple options:

Real-World Example: MQTT Config Flow

From homeassistant/components/mqtt/config_flow.py:66:
The MQTT integration has a comprehensive config flow supporting:
  • Manual configuration
  • Hassio discovery
  • Reconfiguration
  • Options flow for discovery settings

Best Practices

Security: Never log passwords or sensitive data during validation.

Validate Input

Use Selectors

From config_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