Open-source home automation platform running on Python 3.
npx @tessl/cli install tessl/pypi-homeassistant@2025.9.0Home Assistant is a comprehensive open-source home automation platform that provides local control and privacy-focused smart home management. Built in Python 3, it supports over 1,370 integrations for connecting and controlling various smart devices, sensors, and services. The platform features a modular architecture with components for authentication, configuration management, data flow handling, and extensive helper utilities.
pip install homeassistantimport homeassistantFor core functionality:
from homeassistant.core import HomeAssistant, Event, State, ServiceCall, callback
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity import EntityFor integration development:
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME, STATE_ON, STATE_OFFimport asyncio
from homeassistant.core import HomeAssistant
from homeassistant.helpers.service import async_register_admin_service
# Create Home Assistant instance
hass = HomeAssistant('/path/to/config')
# Register a simple service
async def handle_hello_service(call):
"""Handle the hello service call."""
name = call.data.get('name', 'World')
hass.states.async_set('sensor.hello', f'Hello {name}!')
# Register the service
hass.services.async_register('example', 'hello', handle_hello_service)
# Set up entity state
hass.states.async_set('sensor.temperature', '23.5', {
'unit_of_measurement': '°C',
'friendly_name': 'Temperature'
})
# Listen for state changes
@callback
def state_changed_listener(event):
"""Handle state changed events."""
old_state = event.data.get('old_state')
new_state = event.data.get('new_state')
print(f"State changed: {old_state.state} -> {new_state.state}")
hass.bus.async_listen('state_changed', state_changed_listener)Home Assistant uses a modular, async-first architecture built around several core concepts:
Central Home Assistant runtime providing the foundation for all automation and integration functionality. Includes the main HomeAssistant instance, event system, state management, and service registry.
class HomeAssistant:
def __init__(self, config_dir: str = None): ...
async def async_start(self) -> None: ...
async def async_stop(self, exit_code: int = 0) -> None: ...
async def async_run(self, *, attach_signals: bool = True) -> int: ...
# Core properties
states: StateMachine
services: ServiceRegistry
bus: EventBus
config: ConfigBase classes and utilities for creating entities that represent devices, sensors, switches, and other controllable objects in Home Assistant. Provides standardized interfaces for state management, device information, and platform integration.
class Entity:
def __init__(self): ...
@property
def entity_id(self) -> str: ...
@property
def name(self) -> str: ...
@property
def state(self) -> str: ...
async def async_added_to_hass(self) -> None: ...Configuration loading, validation, and management system supporting both YAML files and UI-driven configuration flows. Handles integration discovery, dependency resolution, and configuration entry lifecycle.
class ConfigEntry:
@property
def entry_id(self) -> str: ...
@property
def domain(self) -> str: ...
@property
def data(self) -> dict: ...
async def async_setup(self, hass: HomeAssistant) -> bool: ...Comprehensive collection of utility functions and classes for common Home Assistant development tasks including validation, templating, event handling, service management, and async operations.
def callback(func: Callable) -> Callable: ...
def split_entity_id(entity_id: str) -> tuple[str, str]: ...
def valid_entity_id(entity_id: str) -> bool: ...
# Validation utilities
import homeassistant.helpers.config_validation as cv
def entity_id(value: Any) -> str: ...
def positive_int(value: Any) -> int: ...System for loading, managing, and configuring integrations that connect Home Assistant to external devices, services, and platforms. Supports dynamic loading, dependency management, and platform-specific setup.
class Integration:
@property
def domain(self) -> str: ...
@property
def name(self) -> str: ...
@property
def requirements(self) -> list[str]: ...
async def async_get_integration(hass: HomeAssistant, domain: str) -> Integration: ...Central registries for managing entities, devices, and areas within Home Assistant. Provides persistent storage, relationship tracking, and metadata management for the entity ecosystem.
class EntityRegistry:
async def async_get_or_create(
self, domain: str, platform: str, unique_id: str, **kwargs
) -> RegistryEntry: ...
class DeviceRegistry:
async def async_get_or_create(
self, *, config_entry_id: str, identifiers: set, **kwargs
) -> DeviceEntry: ...Security framework providing user management, OAuth token handling, multi-factor authentication, and permission-based access control for Home Assistant instances.
class AuthManager:
async def async_create_system_user(self, name: str) -> User: ...
async def async_validate_access_token(self, token: str) -> AccessToken: ...
class User:
@property
def id(self) -> str: ...
@property
def is_owner(self) -> bool: ...Authentication & Authorization
# Platform types
ALARM_CONTROL_PANEL = "alarm_control_panel"
BINARY_SENSOR = "binary_sensor"
BUTTON = "button"
CAMERA = "camera"
CLIMATE = "climate"
COVER = "cover"
DEVICE_TRACKER = "device_tracker"
FAN = "fan"
LIGHT = "light"
LOCK = "lock"
MEDIA_PLAYER = "media_player"
SENSOR = "sensor"
SWITCH = "switch"
VACUUM = "vacuum"
# Configuration keys
CONF_NAME = "name"
CONF_HOST = "host"
CONF_PORT = "port"
CONF_USERNAME = "username"
CONF_PASSWORD = "password"
CONF_API_KEY = "api_key"
# State values
STATE_ON = "on"
STATE_OFF = "off"
STATE_OPEN = "open"
STATE_CLOSED = "closed"
STATE_UNKNOWN = "unknown"
STATE_UNAVAILABLE = "unavailable"
# Service names
SERVICE_TURN_ON = "turn_on"
SERVICE_TURN_OFF = "turn_off"
SERVICE_TOGGLE = "toggle"
SERVICE_RELOAD = "reload"
# Event types
EVENT_HOMEASSISTANT_START = "homeassistant_start"
EVENT_HOMEASSISTANT_STOP = "homeassistant_stop"
EVENT_STATE_CHANGED = "state_changed"
EVENT_SERVICE_REGISTERED = "service_registered"from typing import Any, Callable, Dict, List, Optional, Union
from homeassistant.core import HomeAssistant
# Core types
EventType = str
StateType = Union[None, str, int, float, bool]
ServiceDataType = Dict[str, Any]
ConfigType = Dict[str, Any]
CallbackType = Callable[[], None]
# Entity ID validation
EntityIdValidatorType = Callable[[str], str]
# Template types
TemplateType = Union[str, None]