Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Protect adopts Keystone in **UniFi Protect → UniFi Devices** as a virtual AI K

**Works with both UniFi and third-party cameras.** UniFi cameras with smart detections (G4 and newer) get plain-English search and event descriptions, and G4/G5 cameras also get face and license plate recognition. Third-party ONVIF cameras (Reolink, Amcrest, or Nest through Scrypted) and older UniFi cameras without smart detections pair with the optional virtual AI Port to get all of that plus Protect's smart detections.

> Unofficial community project; not affiliated with or endorsed by Ubiquiti Inc. No vendor firmware, proprietary binaries, or vendor model weights are included. Tested on **UniFi Protect 7.3.74 and 7.4.112**.
> Unofficial community project; not affiliated with or endorsed by Ubiquiti Inc. No vendor firmware, proprietary binaries, or vendor model weights are included. Tested on **UniFi Protect 7.3.74, 7.4.112, and 7.4.114**.
![UniFi Protect showing Keystone adopted as a virtual AI Key and AI Port](docs/images/protect-devices.png)

Expand Down Expand Up @@ -204,9 +204,9 @@ The **Home Assistant OS app** starts with Speech-to-Text, License Plate Recognit

| Feature | Default | Turn on in `config.yaml` | Turn on in UniFi Protect |
| --- | --- | --- | --- |
| **Find Anything search** | **On** | Already enabled (`embeddings.enabled: true`) | **Settings → Intelligence → Basic Object Recognition**, plus Smart Detections on each camera |
| **Event descriptions** | **Needs vision model** *(off if URL left blank)* | Set `vision.provider`, `vision.base_url`, and `vision.model` | **Settings → Intelligence → AI Summary** |
| **Speech-to-Text** *(event transcripts)* | Off | `stt.enabled: true` | **Settings → Intelligence → Speech-to-Text**, plus Speech audio detection on cameras with a mic |
| **Find Anything search** | **On** | Already enabled (`embeddings.enabled: true`) | **Settings → Intelligence → Basic Understanding** *(7.3: Basic Object Recognition)*, plus Smart Detections on each camera |
| **Event descriptions** | **Needs vision model** *(off if URL left blank)* | Set `vision.provider`, `vision.base_url`, and `vision.model` | **Settings → Intelligence → Basic Understanding** *(7.3: AI Summary; see Protect 7.4 note below)* |
| **Speech-to-Text** *(event transcripts)* | Off | `stt.enabled: true` | **Settings → Intelligence → Basic Understanding** *(7.3: Speech-to-Text; see Protect 7.4 note below)*, plus Speech audio detection on cameras with a mic |
| **Face recognition** | Off | `faces.enabled: true` | G4/G5 cameras: **Legacy Camera Enhancement → Face Recognition**<br>Paired ONVIF cameras: **Face** smart detection |
| **License plates** | Off | `lpr.enabled: true` | G4/G5 cameras: **Legacy Camera Enhancement → License Plate Recognition**<br>Paired ONVIF cameras: **License Plate** smart detection |
| **Enhance Face** | Off | `enhance.enabled: true` | **Enhance** button on face crops in Protect |
Expand All @@ -215,7 +215,9 @@ The **Home Assistant OS app** starts with Speech-to-Text, License Plate Recognit

After editing `config.yaml`, restart Keystone (`docker compose restart`, `systemctl restart keystone`, `sudo launchctl kickstart -k system/com.seearms.keystone` for a macOS system LaunchDaemon, `brew services restart keystone` for a Homebrew user service, or restart the Unraid container). For system LaunchDaemons, rerun `install-daemons` with your original flags if AI Port settings changed. Protect picks up newly enabled features automatically — no re-adoption needed.

> **Tip:** Not seeing descriptions or transcripts? Open the Keystone dashboard (`:8088`). Every service card shows whether it's **Ready**, **Off / Disabled** (with the config key to turn it on), or reporting an error. Note also that **Speech-to-Text** transcribes spoken audio from camera microphones into text — Keystone does not generate spoken audio narration of descriptions.
> **Protect 7.4+ (`Basic Understanding`):** UniFi Protect 7.4 combined **Object Indexing**, **AI Summary**, and **Speech to Text** into a single **Settings → Intelligence → Basic Understanding** (*"Basic Object Recognition"*) card — there are no separate AI Summary or Speech-to-Text toggles. On a fresh adoption, **Basic Understanding** can appear **On (All)** even though **AI Summary** and **Speech to Text** are still off underneath (Protect will not send `speechToText` jobs until Speech to Text is enabled). To turn all three on for all supported cameras, toggle **Basic Understanding** **Off**, then back **On**, and click **Apply Changes** — or switch it to **Selected Only** to reveal and toggle the individual **Object Indexing**, **Speech to Text**, and **AI Summary** icons per camera.
>
> **Tip:** Not seeing descriptions or transcripts? Open the Keystone dashboard (`:8088`). Every service card shows whether it's **Ready**, **Off / Disabled** (with the config key to turn it on), **Off in Protect** (when Protect itself has Speech-to-Text turned off), or reporting an error. In Protect's event player, click the **NeXT AI Summary** sparkle icon in the player toolbar to open saved event descriptions (it starts collapsed until clicked once). Note also that **Speech-to-Text** transcribes spoken audio from camera microphones into text — Keystone does not generate spoken audio narration of descriptions.
<details>
<summary>Resetting adoption ("Connected to another console" / "Reassign this device")</summary>
Expand Down Expand Up @@ -249,7 +251,7 @@ Pass `--target aikey` or `--target aiport` to reset only one virtual device, or

### Event descriptions (Ollama, LM Studio, oMLX, OpenAI, Anthropic)

To turn on event descriptions, point `vision` in `config.yaml` at a vision-capable model, then turn on **AI Summary** under **Protect → Settings → Intelligence**.
To turn on event descriptions, point `vision` in `config.yaml` at a vision-capable model, then enable **Basic Understanding** (toggle **Off → On** and **Apply Changes**, or enable the **AI Summary** icon under **Selected Only**; on Protect 7.3, enable **AI Summary**) under **Protect → Settings → Intelligence**. To read saved descriptions in Protect, open an event and click the **NeXT AI Summary** sparkle button in the player toolbar (Protect remembers it open afterward).

- **Ollama (default provider):** keep `vision.provider: ollama` and set `vision.base_url` (for example `http://192.0.2.20:11434`) and `vision.model` (default `qwen3.5:9b`, or `qwen3.5:4b` for smaller GPUs).
- **LM Studio, oMLX, llama.cpp, or vLLM:** set `provider: openai-compatible`, use the server's `/v1` base URL, and set `model` to the exact model ID it serves:
Expand Down Expand Up @@ -315,7 +317,7 @@ stt:
model: whisper-base # whisper-tiny | whisper-base | whisper-small
```

Restart Keystone, then enable **Speech-to-Text** under **Protect → Settings → Intelligence** (and Speech audio detection on audio-capable cameras). Runs locally on CPU with no extra packages; cameras without a microphone return an empty transcript instead of stalling.
Restart Keystone, then enable Speech-to-Text under **Protect → Settings → Intelligence** (on Protect 7.4+, toggle **Basic Understanding** **Off → On** and click **Apply Changes**, or switch to **Selected Only** and toggle the **Speech to Text** icon per camera; on Protect 7.3, enable **Speech-to-Text**) plus **Speech** audio detection on audio-capable cameras. Runs locally on CPU with no extra packages; cameras without a microphone return an empty transcript instead of stalling.

### License plate recognition

Expand Down Expand Up @@ -561,7 +563,7 @@ By default Keystone starts with the caption budget. If reasoning exhausts it bef

### Architecture & protocol compatibility

- **AI Key (`UP-AI-KEY`, `0xa5f0`)**: Advertises via Ubiquiti UDP `10001` discovery, serves `/api/info`, `/api/adopt`, and `/api/readopt` over HTTPS (`:8080`), authenticates to Protect via mTLS with pinned controller SHA-256 certificates, handles UCP4 control commands (`:7442`), and syncs rotated passwords to PostgreSQL (`unifi-protect` role) for Protect 7.3+ `isSearchHost` vector search.
- **AI Key (`UP-AI-KEY`, `0xa5f0`)**: Advertises via Ubiquiti UDP `10001` discovery, serves `/api/info`, `/api/adopt`, and `/api/readopt` over HTTPS (`:8080`), authenticates to Protect via mTLS with pinned controller SHA-256 certificates, handles UCP4 control commands (`:7442`), and syncs rotated passwords to PostgreSQL (`unifi-protect` role) for Protect 7.3+ `isSearchHost` vector search. Keystone intentionally stays in **Basic Understanding** (`supportDeepMode: false`, `supportVlm: false`, `aiMode: "basic"`, legacy dispatch without `aiSched`): Protect 7.4+'s **Deep Understanding** mode is restricted to internal Ubiquiti accounts and replaces `recognizeKeyFrames`/CLIP search with a separate session-describe pipeline.
- **Vision pipeline**: Samples 3 chronological frames (`±1.0s` around each event's `keyMoment`, widened to `±2.0s` on clips `≥ 15s`, at `960px`) for motion-aware VLM captions and maps outputs plus class-filtered attributes onto Protect's 5,375-tag `ramTags` vocabulary. Optionally injects per-camera spatial hints (`cameras:` in `config.yaml`) and multi-view, episode-chained chronological cross-camera sightings (`vision.cross_camera_context_seconds`, default `90s`, strong similarity `0.62`, cross-view floor `0.35`, up to `3` sightings) so distant, rear, indoor, or IR angles benefit from earlier clearer cameras across vehicles, people, animals, and deliveries. Interactive on-demand summaries (`RequestAI` → `:7968/on_demand_inference`) narrow long exports to a 4-second window and run a fast 1-frame `640px` pass to stay inside Protect's UI timeout.
- **Find Anything (`:7443`)**: Runs local **CLIP ViT-L/14** (768-dim ONNX) for object crop indexing, `NL_PARSE` text queries (with relative time-window parsing), `IMAGE_SEARCH`, and optional CLIP reverification. Protect 7.4's release notes say detection confidence verification has been removed, so expect reverification jobs only from Protect 7.3.
- **Speech-to-Text (`speechToText`, featureFlags `supportTts` & `supportStt`)**: Fetches Protect's audio-only MP4 export (`skipVideo=true`, retrying transient `404`s), decodes 16 kHz mono audio with FFmpeg, transcribes with Whisper (log-mel + timestamp-constrained greedy decoding on onnxruntime, with no-speech and leading-silence gating), and POSTs `{camera, event, stt: [{startMs, endMs, text}]}` to `/internal/aiprocessors/speech-to-text`. Segment timestamps use Unix epoch milliseconds for synchronized event playback; queued/active jobs are reported to Protect as `UI_AUTO_STT`.
Expand Down
2 changes: 1 addition & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ enhance:
jpeg_quality: 92
idle_unload_seconds: 300 # Free the model's RAM after 5 idle minutes (0 = keep resident)

# Native Protect Speech-to-Text (event transcripts; Protect featureFlag "supportTts").
# Native Protect Speech-to-Text (event transcripts; Protect featureFlags "supportTts" & "supportStt").
# Off by default. The onnx backend runs OpenAI Whisper locally on CPU with the existing
# onnxruntime/numpy/tokenizers deps; weights are pinned + SHA-256 verified on first use.
stt:
Expand Down
8 changes: 4 additions & 4 deletions home-assistant/keystone/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
1. In Home Assistant, go to **Settings → Apps → Install app → ⋮ → Repositories** and add `https://github.com/seeARMS/keystone`.
2. Select **Keystone → Install**. Open **Configuration**, enter the Protect console's IPv4 address, and review the [feature switches](#feature-switches) before starting. Keep the vision URL blank with the default Ollama provider to skip event descriptions. Save your changes.
3. Start Keystone from **Info** and watch the **Log** tab for startup and model downloads. In **UniFi Protect → UniFi Devices**, find the **AI Key** at your Home Assistant OS host's IP and select **Adopt**. Initial credentials are `ubnt` / `ubnt` if prompted. Protect rotates them during adoption.
4. In Protect, enable **Settings → Intelligence → Basic Object Recognition** and Smart Detections on the camera you want to search. Trigger a new smart detection, then search for it with **Find Anything**. The first query may take longer while the text model loads. Older events are outside this initial test because historical indexing is off by default.
4. In Protect, enable **Settings → Intelligence → Basic Understanding** *(Protect 7.3: Basic Object Recognition)* and Smart Detections on the camera you want to search. On Protect 7.4+, **Basic Understanding** bundles Object Indexing, AI Summary, and Speech to Text in one card and can appear **On (All)** right after adoption while AI Summary and Speech to Text are still off underneath — toggle **Basic Understanding** **Off**, then back **On**, and click **Apply Changes** (or switch to **Selected Only** to pick features per camera). Trigger a new smart detection, then search for it with **Find Anything**. The first query may take longer while the text model loads. Older events are outside this initial test because historical indexing is off by default.

If you use Home Assistant Container, run Keystone separately using [Docker Compose](https://github.com/seeARMS/keystone#docker-compose).

Expand All @@ -26,15 +26,15 @@ If you use Home Assistant Container, run Keystone separately using [Docker Compo
| `vision_model` | A vision-capable model served by the endpoint. Ollama defaults to `qwen3.5:9b`. Enter the exact model ID for other providers when enabling descriptions. |
| `vision_api_key` | Required for OpenAI and Anthropic. For an authenticated local endpoint, choose `openai-compatible` and enter its bearer token. |

Run or host the vision model separately and ensure its endpoint is reachable from Home Assistant OS. After saving a vision configuration and restarting Keystone, enable **AI Summary** in **Protect → Settings → Intelligence**. Search remains local regardless of which vision provider you choose. Event descriptions send selected frames to the configured vision endpoint.
Run or host the vision model separately and ensure its endpoint is reachable from Home Assistant OS. After saving a vision configuration and restarting Keystone, enable **AI Summary** in **Protect → Settings → Intelligence** (on Protect 7.4+, toggle **Basic Understanding** **Off → On** and click **Apply Changes**, or turn on the **AI Summary** icon under **Selected Only**). Open an event and click the **NeXT AI Summary** icon in the player toolbar to view saved descriptions. Search remains local regardless of which vision provider you choose. Event descriptions send selected frames to the configured vision endpoint.

### Feature switches

All five switches start on. Change them on Keystone's **Configuration** tab, select **Save**, and restart the app to apply your changes. The switches make the features available to Protect. Turning on **AI Port** starts a second discoverable device. Adopt it separately in Protect and choose which cameras to pair with it.

| Switch | Protect setup |
| --- | --- |
| **Speech-to-Text** (`speech_to_text`) | Enable **Settings → Intelligence → Speech-to-Text** and turn on **Speech** audio detection for cameras with microphones. |
| **Speech-to-Text** (`speech_to_text`) | Enable **Settings → Intelligence → Basic Understanding** *(7.4+: toggle Off → On and Apply Changes, or enable the **Speech to Text** icon under **Selected Only**; 7.3: Speech-to-Text)* and turn on **Speech** audio detection for cameras with microphones. |
| **License Plate Recognition** (`license_plate_recognition`) | On G4/G5 cameras, enable **Legacy Camera Enhancement → License Plate Recognition**. For cameras paired to the AI Port, enable **License Plate** smart detection. |
| **Enhance Face** (`enhance_face`) | Select **Enhance** on a face crop in Protect. |
| **Face Recognition** (`face_recognition`) | On G4/G5 cameras, enable **Legacy Camera Enhancement → Face Recognition**. For cameras paired to the AI Port, enable **Face** smart detection. |
Expand All @@ -61,7 +61,7 @@ Home Assistant's usual web port is `8123/TCP`. If a reverse proxy or another ser

- **The app fails to start:** Open its **Log** tab and check the configuration error or the specific port that failed to bind. A PostgreSQL app listening on `5432/TCP` or a reverse proxy on `8080/TCP` can prevent startup.
- **Protect cannot discover Keystone:** Confirm both hosts share a broadcast domain and UDP `10001` is available. For a routed setup, use Protect's IP adoption with the Home Assistant OS host's IP and allow the connections above. Preserve the Protect console's real source IP for PostgreSQL access.
- **Protect adopts Keystone but Find Anything returns no results:** Check the app log for model download or search connection errors. Confirm the console can reach `5432/TCP`, Basic Object Recognition is enabled, and the camera has generated a new smart detection since adoption.
- **Protect adopts Keystone but Find Anything returns no results:** Check the app log for model download or search connection errors. Confirm the console can reach `5432/TCP`, Basic Understanding (Basic Object Recognition) is enabled, and the camera has generated a new smart detection since adoption.

## Update, back up and verify persistence

Expand Down
7 changes: 7 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,13 @@ if c.aiport.enabled:
step = 2
if intel:
print(f" {step}. Open Settings → Intelligence and enable: {', '.join(intel)}.")
if vision_on or c.stt.enabled:
print(
" (On Protect 7.4+, these live inside Basic Understanding — toggle it Off then On "
"and click Apply Changes, or switch to Selected Only to pick features per camera.)"
)
else:
print(" (On Protect 7.4+, this lives inside Basic Understanding → Object Indexing.)")
if not vision_on:
print(f" (Event descriptions are disabled until you configure vision.* in {config_path} and enable AI Summary.)")
step += 1
Expand Down
7 changes: 7 additions & 0 deletions scripts/setup-compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,13 @@ def print_summary(
if features.get("aiport"):
print(" Also adopt the AI Port and pair your ONVIF / legacy UniFi cameras to it.")
print(f" 3. In Protect → Settings → Intelligence, enable: {', '.join(intel)}.")
if vision_on or features.get("stt"):
print(
" (On Protect 7.4+, these live inside Basic Understanding — toggle it Off then On "
"and click Apply Changes, or switch to Selected Only to pick features per camera.)"
)
else:
print(" (On Protect 7.4+, this lives inside Basic Understanding → Object Indexing.)")
if not vision_on:
print(
" (Event descriptions are disabled until you configure vision.* in config.yaml and enable AI Summary.)"
Expand Down
Loading
Loading