perf(homekit): optimize motion detector with frame-based timing

Replace time.Now() calls in hot path with frame-based timing:
- Pre-compute triggerLevel (integer comparison instead of float division)
- Calibrate hold/cooldown budgets from FPS (default 30fps)
- Periodic FPS recalibration every 150 frames for accuracy
- Active motion path: 47ns → 3.6ns (13x faster)

Update schema.json with detect mode and motion_threshold.
Add threshold tuning guide to README.
This commit is contained in:
Sergey Krashevich
2026-03-05 08:50:27 +03:00
parent a591186da6
commit 78ef8fc064
4 changed files with 204 additions and 110 deletions
+8 -2
View File
@@ -338,13 +338,19 @@
"default": false
},
"motion": {
"description": "Motion detection mode for HKSV: `api` (triggered via HTTP API) or `continuous` (always report motion)",
"description": "Motion detection mode for HKSV: `api` (triggered via HTTP API), `continuous` (always report motion), or `detect` (automatic detection based on P-frame size analysis)",
"type": "string",
"enum": [
"api",
"continuous"
"continuous",
"detect"
],
"default": "api"
},
"motion_threshold": {
"description": "Motion detection sensitivity threshold for `detect` mode. Lower values = more sensitive. Uses EMA-based P-frame size analysis.",
"type": "number",
"default": 2.0
}
}
}