Home Assistant Core
Home Assistant Core is the open-source home automation platform's Python foundation, providing a robust, event-driven framework for observing states, controlling devices, and automating tasks. It is actively developed with monthly releases, currently at version 2026.4.2.
Warnings
- breaking Home Assistant undergoes monthly releases, often including breaking changes. Users must diligently review release notes and the 'Backward-incompatible changes' section before updating to avoid unexpected issues.
- gotcha YAML configuration is crucial for Home Assistant, and incorrect indentation is a leading cause of errors. This can lead to configurations or automations failing silently or behaving unexpectedly.
- gotcha Running Home Assistant on an SD card (e.g., on a Raspberry Pi) for extended periods can lead to SD card wear and failure due to frequent write operations (logs, state changes). This can result in data loss or system instability.
- gotcha Custom components are community-maintained and, unlike official integrations, may not receive immediate updates for breaking changes in Home Assistant Core. They can cause instability or break functionality after a core update.
- gotcha The `python_script` integration is a sandboxed environment and does not allow arbitrary Python imports. Developers accustomed to full Python scripting often find this limitation restrictive.
Install
-
pip install homeassistant
Imports
- HomeAssistant
from homeassistant.core import HomeAssistant
- ConfigEntry
from homeassistant.config_entries import ConfigEntry
- DOMAIN
from homeassistant.const import DOMAIN
- Platform
from homeassistant.const import Platform
- async_setup_entry
from homeassistant.config_entries import ConfigEntry async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Quickstart
import asyncio
from homeassistant.core import HomeAssistant, CoreState
async def run_hass_instance():
hass = HomeAssistant(".homeassistant") # Use a temporary config directory
await hass.async_start()
print(f"Home Assistant started. State: {hass.state}")
# Example: Set a state (e.g., for a custom sensor)
hass.states.async_set("test.hello_world", "Hello from Python!")
print(f"State of test.hello_world: {hass.states.get('test.hello_world').state}")
# Keep running for a short period or until manually stopped
await asyncio.sleep(5)
await hass.async_stop()
print("Home Assistant stopped.")
if __name__ == "__main__":
# Note: Running Home Assistant Core programmatically like this is mostly for testing or specific advanced scenarios.
# For typical development, you would create a custom component and run HA via its standard entrypoint.
try:
asyncio.run(run_hass_instance())
except KeyboardInterrupt:
print("Operation interrupted by user.")