Conversation
…nctionality - Introduced HKSV configuration options in homekit.go, allowing for motion detection and doorbell features. - Implemented API endpoints for triggering motion detection and doorbell events. - Enhanced server.go to handle HKSV sessions and manage motion detection states. - Created new accessory types for HKSV and doorbell in accessory.go. - Added support for audio recording configurations in ch207.go. - Defined new services for motion detection and doorbell in services_hksv.go. - Implemented opack encoding/decoding for HDS protocol in opack.go and protocol.go. - Updated OpenAPI documentation to reflect new endpoints and features. - Extended schema.json to include HKSV configuration options.
… and add motion detector functionality
…g GOP buffering The HKSV recording was failing because: 1. The dataSend.data message structure was wrong - `packets` was a flat integer instead of an array of objects with `data` and `metadata` fields matching the HAP-NodeJS specification 2. Each video/audio frame was sent as a separate mediaFragment, but Home Hub expects GOP-based fragments (~2-4 seconds of accumulated data) 3. Large fragments were not chunked (max 256 KiB per chunk) Changes: - Fix HDS dataSend.data message structure to use proper packets array with nested data/metadata (dataType, dataSequenceNumber, dataChunkSequenceNumber, isLastDataChunk, dataTotalSize) - Add 256 KiB chunking for large media fragments - Buffer moof+mdat pairs in hksvConsumer and flush on keyframe boundaries (GOP-based fragmentation) - Pre-start consumer at pair-verify for instant init segment delivery - Add write-response support to HAP PUT handler for ch131 DataStream setup - Fix HAP service linking to match HAP-NodeJS reference - Add default SelectedCameraRecordingConfiguration (ch209) value - Start continuous motion generator at pair-verify with dedup protection
|
It's not ready to merge yet, but it is already fully functional and ready for testing by any user |
…sumer HDS protocol tests (15 tests, 4 benchmarks): - Message structure for SendMediaInit and SendMediaFragment - Multi-chunk splitting for fragments > 256KB - Chunk boundary handling and sequence preservation - WriteEvent/WriteResponse/WriteRequest round-trip - opack helper functions HKSV consumer tests (14 tests, 3 benchmarks): - Consumer creation and field initialization - GOP buffer flush with sequence numbering - Activate with init segment and seqNum=2 - Activate timeout and error handling - Stop safety (double-stop, deactivation) - WriteTo blocking until Stop Also fixes broken hds_test.go (undefined Client → NewConn).
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.
|
I’m going to jump on trying this right away. I’ve been hoping for this for a while!! |
- Implemented MotionDetector for detecting motion based on H.264 P-frame sizes. - Introduced adjustable sensitivity threshold for motion detection. - Added tests for various scenarios including motion detection, hold time, cooldown, and baseline adaptation. - Created hksvSession to manage HDS DataStream connections for HKSV recording. - Updated schema.json to include a new speaker option for 2-way audio support.
|
@skrashevich first initial attempt for this was partially successful. I was able to add the camera and the hksv settings were enabled in the home app settings (when/what to record). I set it up to record all motion but it seems that part was not working. No recordings were ever triggered. I am using the basic “continuous” motion config, have not tried to get the motion api hooked up yet. |
Try to update to the latest version of this PR It’s a known bug, I hope i fixed it in c567831 |
Will try this afternoon if possible! Thanks |
In any case, try to re-pair the camera in HomeKit. |
|
Worked with the latest commit! I currently use the same cameras via scrypted for this use case. So I can easily do a side by side on functionality. Great work so far, this is a game changer in my opinion. When this is stable, I can’t wait to try to integrate it directly into thingino on camera (thingino optionally supports go2rtc) |
Although my motion detector implementation is very "cheap" in terms of CPU, I'm not sure if the camera's processor can handle it |
With motion set to continuous is it needed? |
No. Continuous is an emulation of a motion sensor that just reports motion event every 30 seconds. |
seems like two way audio is broken now though. the talk button has disappeared. (cam in go2rtc via onvif) |
homekit:
camera1:
hksv: true
speaker: true # RTFM ! |
|
Very nice! Do ONVIF motion events trigger the motion for HKSV or do we need a third party program to hit that API? |
Currently -- no. I don't have cameras with ONVIF motion detector for such development and testing. |
You should be able to emulate one with https://github.com/roleoroleo/onvif_simple_server and a RTSP feed. I noticed that the HomeKit source already is able to forward motion events to a destination. Ideally this is generalized such that other motion events are supported. Maybe a follow up PR :-) |
|
This looks great! Will try this out ASAP 🙌 |
|
Hi guys! Right now im working on a project to automate my analog intercom. I'm using an IP camera pointing to my door and a Raspberry Pi to transmit the audio from the 4N intercom. I've created a device in Go2RTC that mixes the camera's video with the incoming intercom audio, and I've also added the outgoing intercom audio as a backchannel. But I'm having trouble with two way audio as HomeKit outputs audio in OPUS raw packets (as far as I know) and I'm unable to decode them with ffmpeg. Using go2rtc website everything works perfectly. Also I'm trying to set it up as a video doorbell, but im getting "out of compilance error", if I disable category: doorbell it works but as simple cam and the trigger doorbell ring event is not working. I've set up the audio to be streamed over UDP for testing and this is what I get when I press Talk button in Home App: Any help is appreciated |
- implement ONVIF motion watcher to handle motion events - add configuration options for motion hold time and ONVIF URL - remap motion mode from "onvif" to "api" for compatibility - log ONVIF motion watcher activity for better debugging feat(onvif): implement event subscription for motion detection - create PullPoint subscription to receive motion events - implement methods for pulling messages and renewing subscriptions - handle event requests and responses specific to motion detection test(onvif): add unit tests for motion event parsing and subscription - create tests for parsing various motion event XML responses - verify correct handling of multiple notifications and edge cases - test resolving event addresses for ONVIF clients fix(hksv): improve motion detection logging - log warnings when accessory or character not found during motion detection - log number of listeners notified during motion state changes feat(hap): add listener count method - introduce method to retrieve the number of listeners for a character feat(onvif): enhance ONVIF client with event URL handling - extract event URL from ONVIF device response for subscription management
|
The ONVIF commit is pretty huge. I’ll go back to onvif on mine and test. Thanks for all the work on this. Can confirm after a few days with the previous commit I am getting consistent recordings to hksv so far! |
|
Can confirm the onvif motion detection triggered and hksv recorded with default settings hooked up to a Wyze cam v3 running Thingino. Great work!! FYI your commit did not update the Yaml schema.json with the onvif option so web |
…d motion detection modes to include 'onvif' for event subscription - introduce 'motion_hold_time' to manage active motion duration - add 'onvif_url' for specifying ONVIF device URL for detection
Thank you. I really forgot. |
|
@mikemwalsh |
Summary
Add HomeKit Secure Video (HKSV) support — go2rtc can now expose any camera as an HKSV-compatible device for Apple Home, recording video clips to iCloud when motion is detected.
Key features
continuous— always report motion, Home Hub decides what to recorddetect— automatic P-frame size analysis using EMA baseline (no CPU-heavy decoding needed)api— external trigger via HTTP API (for Frigate, ONVIF events, etc.)category_id: doorbellwith ring event APIpkg/hksv/has zerointernal/imports, can be used in any Go projectNew packages
pkg/hksv/pkg/hap/hds/pkg/hap/camera/services_hksv.go,ch207.go)New API endpoints
POST /api/homekit/motion?id=— trigger motion detectionDELETE /api/homekit/motion?id=— clear motion detectionPOST /api/homekit/doorbell?id=— trigger doorbell ring eventConfiguration
Binary size impact