Skip to main content
Robust error handling is critical for reliable integrations. Home Assistant provides a comprehensive exception hierarchy and patterns for handling errors gracefully.

Exception Hierarchy

Home Assistant defines specialized exceptions in homeassistant/exceptions.py:

Base Exception

All Home Assistant exceptions inherit from HomeAssistantError.

Integration Exceptions

ConfigEntryNotReady

Raise when setup fails due to temporary conditions:
When to use: Network issues, device offline, service unavailable Behavior: Home Assistant retries setup automatically with exponential backoff

ConfigEntryAuthFailed

Raise when authentication fails:
When to use: Invalid credentials, expired tokens, unauthorized access Behavior: Triggers reauthentication flow for user to fix credentials

ConfigEntryError

Raise for permanent configuration errors:
When to use: Invalid configuration, incompatible device, permanent failures Behavior: Config entry fails permanently, user must reconfigure

Service Exceptions

ServiceValidationError

Raise when service call parameters are invalid:

Translation Support

Exceptions can include translations for better user experience:
Corresponding strings.json:

Error Handling Patterns

Setup Error Handling

Handle errors during integration setup:

Coordinator Error Handling

Handle errors in data update coordinators:

Entity Error Handling

Handle errors in entity methods:

API Client Error Handling

Handle errors in API clients:

Logging Best Practices

Use appropriate log levels:

Testing Error Handling

Test error scenarios:

Common Patterns

Retry Logic

Graceful Degradation

Context Managers

Resources