Repository navigation
Add HomeKit Secure Video recording to HomeKit cameras - #190676
Conversation
A camera in accessory mode can record to HomeKit Secure Video when its motion sensor detects motion. The option is set per camera in the options flow. Each recording runs one ffmpeg that encodes what the home hub selects, or copies the camera stream. Diagnostics show the recording state.
|
Hey there @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
🟡 Changes recommended
The unawaited stream.kill() call can leave ffmpeg running and recording cleanup blocked indefinitely in process.wait(), while the synchronous test mock masks the failure.
1 open issue
What changed in this PR
Adds opt-in HomeKit Secure Video recording for cameras exposed as standalone accessories, triggered by a linked motion sensor. The feature depends on an upcoming HAP-python release and does not provide prebuffering.
Changes:
- Adds per-camera recording configuration to the options flow.
- Implements ffmpeg recording, transport lifecycle handling, and diagnostics.
- Adds tests for configuration, recording behavior, failures, and cleanup.
| File | Description |
|---|---|
tests/components/homekit/test_type_cameras.py |
Tests recording arguments, lifecycle, failures, and diagnostics. |
tests/components/homekit/test_diagnostics.py |
Tests recording state in integration diagnostics. |
tests/components/homekit/test_config_flow.py |
Tests enabling and disabling recording through options. |
homeassistant/components/homekit/type_cameras.py |
Implements recording streams and transport management. |
homeassistant/components/homekit/strings.json |
Adds recording option text and requirements. |
homeassistant/components/homekit/diagnostics.py |
Includes recording diagnostics for enabled cameras. |
homeassistant/components/homekit/const.py |
Defines the recording setting and disabled default. |
homeassistant/components/homekit/config_flow.py |
Adds the recording selector for accessory-mode cameras. |
Review effort: Balanced
|
Tested locally with HAP-python from The second commit fixes an error that was logged when a recording ended (two readers on the ffmpeg stderr). |
|
|
halibsbot
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
There was a problem hiding this comment.
🔵 Needs a closer look
HKSV depends on six unreleased HAP-python changes, while mocked tests leave negotiation, recording completion, cleanup, and privacy controls requiring human end-to-end validation with a real HomeKit hub and ffmpeg.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
2, 3 and 4 are in c21a055. 1 is handled in HAP-python (ikalchev/HAP-python#502): a start still binding when a stop comes in closes its own listener. 5 is intended, the service set only follows the configuration so the accessory database does not change at runtime. |
There was a problem hiding this comment.
🔵 Needs a closer look
The stderr handling can discard a legitimate error after an oversized line, hiding the failure’s cause, and needs targeted draining plus a regression test for both lines arriving together.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
PR Review — Add HomeKit Secure Video recording to HomeKit camerasMerge-ready once the HAP-python bump in #191104 lands. The two stderr findings from the last review are fixed in 15a0101, and the two suggestions below remain. What the PR does well:
Remaining suggestions (non-blocking):
Not raised again:
✅ Resolved since last review (2)Previously-flagged issues verified fixed
🟢 Suggestions
1. End-session task skips freeing the slot if teardown raises
|
halibsbot
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
On the remaining two: |
There was a problem hiding this comment.
🔵 Needs a closer look
Mocked HDS and ffmpeg tests and native-H.264-only device coverage leave privacy-sensitive cancellation during permission changes or reloads, plus transcoded and hardware-encoded delivery, requiring human validation.
No open issues 🎉
Review effort: Balanced
|
👋 Hi! Thanks for contributing to Home Assistant. This is your PR dashboard which flags anything you need to address before your PR can be reviewed. Once everything is green, you can press the 'Ready for review' button at the bottom of the page to notify reviewers to take a look. More information about this dashboardThis dashboard automatically updates on every change to this PR and reevaluates the rules as you go. Until everything has been addressed, the bot will keep the PR in draft. Skip a check that doesn't applyIf you think a check doesn't apply to your PR (or the rule is bugged), comment Bot commandsReply with
Checks✨ Everything's in order! 5 checks passed (5 skipped)
|
|
Note No code changes since the last review ( |
|
Changed the Secure Video switch to a camera mode select, so H.265 can be added later as a third mode without migrating options:
With up to 3 streams (high, medium, low) the Home app picks the quality per view and connection, e.g. full resolution at home, a smaller stream remote or in the camera grid, all copied from the camera without transcoding. This already works locally on top of this PR. HKSV 3 recording doesn't work in any project yet (homebridge/hap-nodejs#1132, Scrypted). I tried it too: Apple's server accepts the segments and playlists, but the client never gets them, so the clips don't play. |
|
Thanks for working on this! Tested it on my own setup. Setup
What works
Diagnostics after enabling recording: Notes
Not tested
|


Proposed change
This adds HomeKit Secure Video recording to HomeKit cameras in accessory mode. I added the recording support to HAP-python for this (ikalchev/HAP-python#493 and its follow-ups).
Opt-in per camera with the camera mode in the options flow, needs a linked motion sensor. On a recording request, ffmpeg encodes the stream to H.264 as selected by the home hub, or copies native H.264, and sends it as fragmented MP4. Turning the camera off in the Home app also stops live video and snapshots, and a running recording ends when the hub changes the recording or audio permission. A prebuffer is not included and could be a follow-up.
Type of change
Additional information
#190234 builds on the same API but also changes stream, camera and go2rtc; this PR stays inside HomeKit.
Tested with Apple Home, a home hub and a UniFi Protect G4 Dome sending H.264 with native H.264 enabled: motion on the camera's sensor produced a recording in the Home app, closed normally by the hub. Transcoding an H.265 source did not finish within the hub's time limit, because without a prebuffer the first fragment waits for the camera's next keyframe. That case is left for a follow-up.
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: