Hassette
Hassette is a Python framework for writing Home Assistant automations as typed, testable code. It connects to Home Assistant, runs your apps, and shows you what each one is doing.
from hassette import App, AppConfig
class MotionLightsConfig(AppConfig):
motion_sensor: str = "binary_sensor.hallway_motion"
light: str = "light.hallway"
class MotionLights(App[MotionLightsConfig]):
async def on_initialize(self):
sensor = self.app_config.motion_sensor
await self.bus.on_state_change(
sensor,
changed_to="on",
handler=self.lights_on,
name="motion_on",
)
await self.bus.on_state_change(
sensor,
changed_to="off",
duration=120,
handler=self.lights_off,
name="motion_off",
)
async def lights_on(self):
await self.api.turn_on(self.app_config.light, brightness=200)
async def lights_off(self):
await self.api.turn_off(self.app_config.light)
The light turns on when motion starts. It turns off once the sensor has stayed clear for 120 seconds: duration fires the handler only if the new state holds that long, so motion coming back cancels the turn-off.
Each automation is an app, a Python class Hassette loads and runs. on_initialize runs once when the app starts. self.bus subscribes handlers to things that happen in Home Assistant, self.api calls services, and name labels each subscription in the web UI and CLI. Handlers receive only the parameters they declare, so these two take none. A handler that wants the new state adds a parameter for it; see Dependency Injection.
App methods are async def, and calls to self.bus, self.api and self.scheduler take await. That's all the async you need to get started. Not ready for async? AppSync runs plain synchronous code, with .sync versions of the bus, scheduler and API.
MotionLightsConfig holds the app's settings as typed fields. Override them in hassette.toml, once per room if you like:
# "motion_lights" is the app key: your name for it in the CLI and UI
[hassette.apps.motion_lights]
filename = "motion_lights.py"
class_name = "MotionLights"
# Each [[...config]] block runs one instance of the app
[[hassette.apps.motion_lights.config]]
instance_name = "hallway" # uses the defaults from MotionLightsConfig
[[hassette.apps.motion_lights.config]]
instance_name = "garage"
motion_sensor = "binary_sensor.garage_motion"
light = "light.garage"
Why Hassette?
- Typed state. Most built-in entity domains have a generated model, so
self.states.lighthands you lights whosebrightnessandcolor_temp_kelvinautocomplete in your editor. Reads come from a local cache, not a round trip to Home Assistant. - Filtering built into subscriptions. Glob patterns (
sensor.*_temperature), value conditions (C.Increased()), debounce and throttle (at most one call per N seconds) are arguments toon_state_changeand the other subscription methods, so handlers don't start with a block ofifchecks. See Filtering. - Handlers declare their inputs. Ask for the new state, the old one, or the entity ID in the handler's signature and Hassette passes it in, in the style of FastAPI's dependencies. See Dependency Injection.
- Scheduler. Run a function after a delay, every N minutes, daily at a set time, or on a cron schedule. A job set for 07:00 still runs at 07:00 after the clocks change. See Scheduler.
- Test harness.
AppTestHarnessruns an app without a live Home Assistant: seed states, simulate events, move time forward, and assert which services it called. See Write Your First Test. - Per-app cache. Keep data across restarts, with expiry, for things like remembering when you last sent a notification. See Cache.
- Built to keep running. Hassette reconnects to Home Assistant on its own, reloads apps when you edit them in dev mode, and flags synchronous code that would freeze every other app, naming the app responsible.
See It in Action
Autocomplete for entities and services
Typed models give your editor autocomplete and inline docs for Home Assistant entities, services, and their attributes.
Filtered events, typed handlers
Filters decide which events reach a handler, and the handler's parameters say what data it gets.
Web UI
The web UI runs by default at http://<host>:8126/. It shows each app's status and health, the history of every handler and scheduled job down to single executions, live logs, and the resolved configuration. You can start, stop and reload apps and trigger jobs from it. It's protected by a token Hassette generates on first start; the Web UI docs show where to find it.
See the Web UI docs for a full tour, or the CLI docs for the same information in the terminal.
Control apps from Home Assistant
The optional Hassette integration, installed through HACS (the Home Assistant Community Store), creates a Home Assistant device for each app. Each device has a switch that starts and stops the app, a reload button, and a status sensor, for your dashboards and automations. It needs Hassette 0.56.0 or newer and Home Assistant 2026.9 or newer.
Get Started
You need Python 3.11+ and uv.
uv tool install hassette
The Quickstart takes you from an empty directory to a running app, including creating the Home Assistant token. To run Hassette in a container, see Docker Setup. On Home Assistant OS or Supervised, the Hassette add-on runs it next to Home Assistant. Not sure Hassette fits? Read Is Hassette Right for You?
Coming from AppDaemon?
Most of what you know carries over: listen_state becomes self.bus.on_state_change, call_service becomes self.api.call_service, run_in and run_daily keep their names on self.scheduler, and self.args becomes a typed AppConfig. What you gain: settings that are checked at startup instead of when a handler fires, a test harness that needs no mocking, and handlers that receive typed data instead of parsing payloads.
Hassette and AppDaemon can run against the same Home Assistant at once, so you can port one app at a time. The Migration Guide walks through each piece, including async basics and a checklist for porting an app.
Next Steps
- Local setup: Quickstart
- Production: Docker Setup
- How the pieces fit: Architecture
- Every setting: Configuration
- Common automations: Recipes
- Migrating from AppDaemon: Migration Guide
How It's Built
Hassette is written by AI coding agents. I make every design decision and own every line, and every change passes type checking and the test suite, including tests against a real Home Assistant, before it merges. I also run my own house on Hassette's main branch. See How Hassette Is Built.
