Skip to main content
This guide will walk you through creating a new integration for Home Assistant. We’ll cover the essential files, structure, and best practices for building a high-quality integration.

Prerequisites

Before you begin, ensure you have:
  • A working Home Assistant development environment
  • Python 3.12 or later installed
  • Familiarity with async/await patterns in Python
  • Understanding of the device or service you want to integrate

Integration Structure

A basic integration consists of several key files:

Step 1: Create the Manifest

The manifest.json file defines your integration’s metadata. This is required for Home Assistant to recognize your integration.
manifest.json

Key Manifest Fields

  • domain: Unique identifier for your integration (lowercase, no spaces)
  • name: Human-readable name displayed in the UI
  • config_flow: Set to true if your integration uses the UI configuration flow
  • iot_class: How the integration communicates (see IoT class documentation)
  • requirements: Python packages required by your integration
  • codeowners: GitHub usernames responsible for maintaining this integration

Step 2: Define Constants

Create a const.py file to store configuration keys and constants:
const.py

Step 3: Implement the Main Integration

The __init__.py file contains the core integration setup logic:
__init__.py

Key Functions

async_setup_entry

This is the main entry point for modern integrations. It:
  1. Initializes API clients or data coordinators
  2. Stores shared data in hass.data[DOMAIN]
  3. Forwards setup to entity platforms
  4. Returns True on success or raises ConfigEntryNotReady on failure

async_unload_entry

Cleans up when the integration is removed:
  1. Unloads all entity platforms
  2. Cleans up stored data
  3. Closes API connections if needed

Step 4: Create a Config Flow

The config flow handles user configuration through the UI. See the Config Entries guide for detailed information.
config_flow.py

Step 5: Create Entity Platforms

Entity platforms provide the actual functionality. For example, a sensor platform:
sensor.py
See the Entity Component guide for more details on creating entities.

Step 6: Add Translations

Create a strings.json file for UI translations:
strings.json

Testing Your Integration

Before submitting your integration:
  1. Run tests: Ensure your integration has comprehensive test coverage
  2. Check code quality: Run pylint and mypy on your code
  3. Test manually: Install your integration in a development Home Assistant instance
  4. Review the checklist: Follow the integration quality scale requirements

Best Practices

Use DataUpdateCoordinator

For integrations that poll data, use DataUpdateCoordinator to efficiently manage updates:

Handle Connection Errors

Always handle connection errors gracefully:
  • Raise ConfigEntryNotReady during setup if the device is temporarily unavailable
  • Raise ConfigEntryAuthFailed if authentication fails
  • Set entity available property based on connection status

Use Unique IDs

Always provide unique IDs for entities to enable customization:

Follow the Quality Scale

Aim for at least Silver quality scale:
  • Use config flow (no YAML configuration)
  • Implement proper entity naming
  • Handle errors gracefully
  • Provide translations
  • Include tests

Next Steps

Common Patterns

Single Config Entry Integrations

For services that should only have one configuration:
manifest.json

Virtual Integrations

For integrations that re-use another integration’s code:
manifest.json

Resources