Docker Setup
Run Hassette in a container with Docker Compose.
Prerequisites
- Docker and Docker Compose installed on the host machine.
- A running Home Assistant instance with a long-lived access token. See Creating a Home Assistant Token for how to generate one.
Quick Start
Step 1: Create the project
mkdir project_dir && cd project_dir
mkdir -p config/apps
project_dir is a placeholder — name the directory whatever you like. config/ holds your token and settings. config/apps/ holds your automation code, because Hassette loads apps from apps/ inside the config directory by default.
Step 2: Create docker-compose.yml
services:
hassette:
image: ghcr.io/nodejsmith/hassette:latest-py3.13
container_name: hassette
restart: unless-stopped
stop_grace_period: 60s # Hassette's 45s shutdown plus time for the database snapshot, before Docker force-kills it
volumes:
- ./config:/config
- data:/data
- uv_cache:/uv_cache
ports:
- "8126:8126"
environment:
- HASSETTE__LOGGING__LOG_LEVEL=info
- TZ=America/New_York # Fallback timezone; HASSETTE__TIMEZONE in .env is preferred
healthcheck:
# Keep this pointed at /api/health/live — it stays healthy during HA outages.
# Using /api/health/ready here causes a restart loop whenever HA restarts.
test: ["CMD", "curl", "-sf", "http://127.0.0.1:8126/api/health/live"]
interval: 30s
timeout: 5s
retries: 3
start_period: 60s
volumes:
uv_cache:
data:
The image: line pulls Hassette from GitHub Container Registry (ghcr.io) — Docker downloads it automatically on first run. The volumes break down like this:
./configmounts your local config directory into the container as/config. It holdshassette.toml,.env, and your apps inconfig/apps/.dataanduv_cacheare named volumes for persistent data and the package cache. Docker Compose creates them automatically — no action needed.
Port 8126 exposes the web UI. Hassette requires a credential for it — on first start it generates one and logs it (see Step 4).
Step 3: Create config/.env
# config/.env
HASSETTE__TOKEN=your_long_lived_access_token_here
HASSETTE__BASE_URL=http://homeassistant:8123
HASSETTE__TIMEZONE=America/New_York
Replace your_long_lived_access_token_here with your token. Set HASSETTE__BASE_URL to your Home Assistant's address, like http://192.168.1.100:8123 — when in doubt, use the IP address. The container-name form (http://homeassistant:8123) only works when HA also runs in Docker on the same Docker network.
Set HASSETTE__TIMEZONE to your own timezone so scheduled automations fire at the right times. The container's TZ variable only works as a fallback.
The __ double underscore is how Hassette maps environment variables to nested settings — HASSETTE__TOKEN sets token. Hassette reads /config/.env automatically on startup; you do not need an env_file: directive in the compose file.
Step 4: Start it
docker compose up -d
Check the logs:
docker compose logs hassette -f
You see output like:
INFO hassette ... ─ Generated new web API auth_token, written to /data/.web_api_token. Open http://127.0.0.1:8126 to log in.
INFO hassette ... ─ Hassette is running.
That log line confirms a token was generated and names the file it lives in — it never prints the token itself. Read the value from that file:
docker compose exec hassette cat /data/.web_api_token
Hassette is running, and the web UI is available at http://localhost:8126. Open it, and paste the token from the file into the login screen. If you see an error instead of these lines, head to Troubleshooting.
Upgrading an existing deployment
Hassette requires this token starting with the version that introduced authentication. On the first restart after upgrading, existing deployments generate a token the same way and log it — the dashboard and API return 401 until that token is retrieved and used. This is intentional (auth is now on by default), not a bug. See 401 after upgrading if you land here after an upgrade instead of a fresh install.
Write Your First App
Create config/apps/my_app.py:
from hassette import App, AppConfig
class MyAppConfig(AppConfig):
greeting: str = "Hello from Docker!"
class MyApp(App[MyAppConfig]):
async def on_initialize(self):
self.logger.info(self.app_config.greeting)
App runs your automation logic and gives you access to the bus (subscribes to HA events), the scheduler (runs code on a timer), and the API (calls HA services). AppConfig loads and validates your app's settings from the environment, including config/.env. on_initialize runs once when the app starts.
Two pieces of syntax worth knowing: App[MyAppConfig] pairs your app with its config class — that's how self.app_config knows its type. And lifecycle hooks like on_initialize are async def — Hassette runs the event loop for you, so you can follow the pattern without prior async experience.
Hassette runs only the apps that hassette.toml names. Create config/hassette.toml with a section for your app:
[hassette.apps.my_app]
filename = "my_app.py"
class_name = "MyApp"
config = { instance_name = "my_app" }
my_app is a name you choose for the app. filename is the file's path inside config/apps/, and class_name is the class to run. If you forget this section, startup logs a warning with the section to paste.
Restart the container to pick up the new app:
docker compose restart hassette
Check the logs again. You see Hello from Docker! from your app:
INFO hassette.apps.my_app ... ─ Hello from Docker!
Upgrading from the /apps volume
Earlier images mounted apps at /apps. Move them under config/apps/ — Upgrading has the before and after compose files.
Having trouble?
If Hassette fails to connect, check HASSETTE__BASE_URL and your token in config/.env. If your app doesn't show up in the logs, see Troubleshooting for app-loading and other common issues.
From here, see First Automation to subscribe to Home Assistant events and control devices.
Next Steps
- First Automation: subscribe to events, control devices
- Managing Dependencies: add Python packages to your setup
- Image Tags: pick a stable tag for production
- Troubleshooting: diagnose connection and startup problems