HomeSec is a self-hosted, extensible video pipeline for home security cameras. You can connect cameras directly via RTSP, receive clips over FTP, or watch a local folder. The pipeline uploads clips, detects objects, optionally runs VLM analysis, and sends policy-driven notifications. Configuration determines which local or cloud services receive footage and alerts.
The behavior reference links the maintained public specifications, operator guides, and known limitations.
- Operator-controlled destinations: Choose local or Dropbox storage and configure the analyzer endpoint and notification backends. The supplied example selects Dropbox and OpenAI; review those choices before running it.
- Modular Architecture: All major components (sources, filters, analyzers, notifiers) are decoupled plugins defined by strict interfaces. If you want to use a different AI model or storage backend, you can swap it out with a few lines of Python.
- Resilience: Recording and uploads can continue when Postgres is unavailable. Reconnect and stage retries have explicit limits; see the known limitations before relying on recovery behavior.
graph TD
%% Layout Wrapper for horizontal alignment
subgraph Wrapper [" "]
direction LR
style Wrapper fill:none,stroke:none
S[Clip Source]
subgraph Pipeline [Media Processing Pipeline]
direction TB
C(Clip File) --> U([Upload to Storage])
C --> F([Detect objects: YOLO])
F -->|Filter succeeds| AI{VLM run mode and trigger classes}
AI -->|Analyze| V([VLM Analysis])
AI -->|Skip| P{Alert Policy}
V --> P
U --> P
P -->|Notify| N[Notifiers]
end
S -->|New Clip File| Pipeline
PG[(Postgres)]
Pipeline -.->|State & Events| PG
end
- Parallel Processing: Upload and filter run in parallel.
- Resilience: Upload failures do not block alerts; filter failures stop expensive VLM calls.
- State: Postgres stores current clip snapshots and best-effort lifecycle history (
clip_states+clip_events). These writes are separate; a stored snapshot does not prove complete event history or recovery after a process restart.
- Highlights
- Pipeline at a glance
- Quickstart
- Configuration
- Plugins
- Observability
- Development
- Documentation
- Contributing
- License
- Multiple pluggable video clip sources: RTSP motion detection, FTP uploads, or a watched folder
- Parallel upload + filter (YOLO) with frame sampling and early exit
- OpenAI-compatible VLM analysis with structured output
- Policy-driven alerts with per-camera overrides
- Fan-out notifiers (MQTT for Home Assistant, SendGrid email)
- Postgres-backed state + events with graceful degradation
- Health endpoint plus optional Postgres telemetry logging
- Push-to-talk for RTSP cameras with ONVIF audio backchannel support and a local TP-Link Tapo talkback backend path
From a repository checkout, use the included docker-compose.yml for HomeSec and Postgres:
cp config/example.yaml config/config.yaml
cp .env.example .env
# Edit both files for your cameras, storage, analyzer, and credentials.
# Comment out the local-development DB_DSN line in .env for Compose.
docker compose up -dCompose mounts config/config.yaml at /config/config.yaml and .env at /config/.env; its application image is leva/homesec:latest. It publishes HTTP on port 8081 and WebRTC UDP on 8189–8199. For preview reachability, helper requirements, and persistent media paths, follow the deployment guide.
Compose supplies a database DSN using its postgres service hostname. The entrypoint sources the mounted .env afterward, so the example's active DB_DSN pointing at localhost would override that value inside the container. Comment out that line for Compose, or deliberately set a container-reachable database DSN.
For standard production usage without Docker Compose:
-
Prerequisites:
- Python 3.10+
- PostgreSQL (running and accessible, with HomeSec's migrations applied)
- The native helper for RTSP camera and preview execution. Native setup
-
Install
pip install homesec
-
Configure
# Download example config & env curl -O https://raw.githubusercontent.com/lan17/homesec/main/config/example.yaml mv example.yaml config.yaml curl -O https://raw.githubusercontent.com/lan17/homesec/main/.env.example mv .env.example .env # Setup environment (DB_DSN is required) # Edit .env to set your secrets! export DB_DSN="postgresql+asyncpg://user:pass@localhost:5432/homesec"
-
Prepare the schema and validate Run the Alembic migrations from a matching release's repository checkout with the same exported
DB_DSN:python -m alembic -c alembic.ini upgrade head homesec validate --config config.yaml
The CLI run command does not apply migrations. Configuration validation does not prove camera, provider, or database connectivity.
-
Run
homesec run --config config.yaml
If you are contributing or running from source:
-
Install tools and build dependencies Follow the developer prerequisites, then run:
make dev-setup
This installs locked Python/UI dependencies and builds the native helper and UI. It does not start Postgres or HomeSec.
-
Configure and start infrastructure Copy and edit
config/example.yamlasconfig/config.yamland.env.exampleas.env. Keep the local-developmentDB_DSNfor this host-run setup, then:make db # Starts just Postgres in Docker -
Run
make run
make runapplies database migrations before starting; migration failure stops this command. The Docker entrypoint instead warns and continues after a failed migration, so check container logs and schema readiness during upgrades.
Configuration is YAML-based and validated against core and plugin models. Reference secrets through environment-variable names (*_env) rather than putting credentials in YAML. The examples below are fragments to merge into a complete configuration.
Configure connection timeouts and an unlimited retry budget for a camera that can become temporarily unavailable.
cameras:
- name: driveway
source:
backend: rtsp
config:
rtsp_url_env: DRIVEWAY_RTSP_URL
output_dir: "./recordings"
stream:
connect_timeout_s: 2.0
io_timeout_s: 2.0
reconnect:
backoff_s: 5
max_attempts: 0 # Retry indefinitely
filter:
backend: yolo
config:
classes: ["person", "dog"]
min_confidence: 0.6In your .env:
DRIVEWAY_RTSP_URL="rtsp://user:pass@192.168.1.100:554/stream"Selects Dropbox storage and an email notifier. Analyzer behavior is configured separately under vlm.
storage:
backend: dropbox
config:
token_env: DROPBOX_TOKEN
root: "/SecurityCam"
notifiers:
- backend: sendgrid_email
config:
api_key_env: SENDGRID_API_KEY
from_email: "alerts@example.com"
to_emails: ["me@example.com"]In your .env:
DROPBOX_TOKEN="sl.Al..."
SENDGRID_API_KEY="SG.xyz..."See config/example.yaml for a starting configuration. The core models and each plugin's configuration model define supported settings and defaults.
- Secrets: Never put secrets in YAML. Use env vars (
*_env) and set them in your shell or.env. - Notifiers: Notifiers are optional. With no enabled notifiers, alert decisions are still evaluated and recorded, but no external notifications are sent.
- YOLO classes: The current filter allowlist is
person,bird,cat,dog,horse,sheep,cow,elephant,bear,zebra, andgiraffe. Other names are ignored when building target class IDs; an all-unsupported list fails detection. A name appearing in the model's COCO labels does not make it supported by this filter. - Live preview: Rust WebRTC is the default backend and shares one preview input per camera to deliver H.264/Opus directly to viewers. Preview remains disabled until enabled in config; set
preview.config.advertised_ipto the HomeSec server's client-reachable LAN/VPN IP before enabling it. Seedocs/webrtc-preview.mdfor native helper installation and UDP reachability. Existing HLS configurations remain supported; selectpreview.backend: hlsand keep its scratch storage on tmpfs separate from recordings and durable storage. Preview defaults torecording_policy: stop_on_recording;allow_during_recordingis best-effort and may consume an extra RTSP session. Seedocs/preview-deployment.md. - Push-to-talk: Browser microphone to camera speaker support is auto-probed for RTSP cameras by default. HomeSec tries standards-based backends first; the bundled ONVIF backend supports
PCMU/8000andPCMA/8000, and the bundledtapo_localbackend implements a local TP-Link Tapo talkback path without TP-Link cloud calls at runtime. Auto mode keeps ONVIF ahead of Tapo, then can identify Tapo from persisted ONVIF identity metadata or passive local endpoint discovery for manual RTSP cameras. Usecameras[].talk.backend: onvif_rtsp_backchannelorcameras[].talk.backend: tapo_localfor explicit selection. Tapo local talk defaults to usernameadmin, can derive host and password material from the RTSP URL, and can use explicit backend env vars when credentials differ. Opt out cameras withcameras[].talk.mode: disabledwhen needed. Physical Tapo C120 compatibility still needs per-firmware validation. Seedocs/push-to-talk.md.
After installation, the homesec command is available:
homesec --helpRun the pipeline:
homesec run --config config.yamlValidate config:
homesec validate --config config.yamlCleanup old clips (reanalyze and optionally delete empty clips):
homesec cleanup --config config.yaml --older_than_days 7Cleanup defaults to a dry run. Inspect its output before explicitly applying with --dry_run=False. It rechecks eligible clips using the YOLO-shaped cleanup configuration, deletes storage objects before marking records deleted, and can also remove a separate local recording. It is distinct from automatic retention and API deletion; review the cleanup limitations.
Use homesec <command> --help for detailed options on each command.
We designed HomeSec to be modular. Each major capability is an interface (ClipSource, StorageBackend, ObjectFilter, VLMAnalyzer, AlertPolicy, Notifier) defined in src/homesec/interfaces.py. This means you can swap out components (like replacing YOLO with a different detector) without changing the core pipeline.
Built-in plugins are registered by decorators when their modules are imported. External packages can participate through the homesec.plugins entry-point group.
| Type | Plugins |
|---|---|
| Sources | rtsp, ftp, local_folder |
| Filters | yolo |
| Storage | dropbox, local |
| VLM analyzers | openai |
| Notifiers | mqtt, sendgrid_email |
| Alert policies | default, noop |
All interfaces are defined in src/homesec/interfaces.py.
| Type | Interface | PluginType for @plugin |
|---|---|---|
| Sources | ClipSource |
SOURCE |
| Filters | ObjectFilter |
FILTER |
| Storage | StorageBackend |
STORAGE |
| VLM analyzers | VLMAnalyzer |
ANALYZER |
| Notifiers | Notifier |
NOTIFIER |
| Alert policies | AlertPolicy |
ALERT_POLICY |
Extending HomeSec is designed to be easy. You can write custom sources, filters, storage backends, and more.
👉 See PLUGIN_DEVELOPMENT.md for a complete guide.
- Public health:
GET /healthand/api/v1/health, served onserver.host/server.port. A running pipeline with unavailable Postgres reportsdegradedwith HTTP 200; stopped/stale runtime health reports HTTP 503. Bootstrap mode reportssetup_requiredwith HTTP 200. - Telemetry:
DB_DSNenables the separate Postgres log handler. It classifies a truthyevent_typeorkind="event"as event telemetry; ordinary logs useDB_LOG_LEVEL, with warnings/errors also admitted. The bounded background queue and failed batch writes can lose records. Telemetry is best-effort and does not replaceClipRepositorystate/history. - Log hygiene: the handler serializes messages, extras, and exception text; it is not a universal secret scrubber. Keep credentials, tokens, raw media, and full DSNs out of log calls and troubleshooting captures. See logging guidance.
- Clone the repository
- Install uv for dependency management
make dev-setupto install locked dependencies and build the UI/native helper- Copy and edit
config/config.yamland.envas described in Developer Setup make dbto start Postgres locally
- Run tests:
make test - Run type checking (strict):
make typecheck - Run the full Rust/Python/UI gate:
make check - Check Python lint/types and lockfile without running application tests:
make lint typecheck lock-check - Run the pipeline:
make run
- Tests must include Given/When/Then comments
- Architecture and guide navigation: documentation index
- Test setup and database isolation: TESTING.md; CI lanes: CI.md
Contributions are welcome! Here's how to get started:
- Fork and clone the repository
- Create a branch for your feature or fix:
git checkout -b my-feature - Install dependencies:
uv sync - Make your changes and ensure tests pass:
make check - Submit a pull request with a clear description of your changes
- All code must pass CI checks:
make check - Tests should include Given/When/Then comments explaining the test scenario
- New plugins should follow the existing patterns in
src/homesec/plugins/ - Keep PRs focused on a single change for easier review
Found a bug or have a feature request? Please open an issue with:
- A clear description of the problem or suggestion
- Steps to reproduce (for bugs)
- Your environment (OS, Python version, HomeSec version)
Apache 2.0. See LICENSE.