Skip to content

reolink(nvr): ONVIF push-based motion for Home Hub battery cameras#2

Open
SnoElement wants to merge 1 commit into
mainfrom
reolink-onvif-hub-motion
Open

reolink(nvr): ONVIF push-based motion for Home Hub battery cameras#2
SnoElement wants to merge 1 commit into
mainfrom
reolink-onvif-hub-motion

Conversation

@SnoElement

Copy link
Copy Markdown
Owner

Problem

Battery/solar cameras behind a Reolink Home Hub (Pro) sleep to save power. While asleep, the hub answers the GetMdState/GetAiState polling the NVR client relies on with "device offline" (rspCode -99), so motion never reaches Scrypted/HomeKit and HKSV never records. The hub does push these events over ONVIF PullPoint.

Refs koush#1947 (Home Hub NVR support, @apocaliss92) and koush#1642 (battery motion via Home Hub never reaching Scrypted).

Change

Add an opt-in ONVIF push path for hub channels:

  • onvif/onvif-api.tslistenEvents() now interprets each event topic once (motion + optional object class), extracts the source channel from the <tt:Source> SimpleItem, and emits an interpreted, channel-aware onvifEvent(motion, className, channel). Adds the Reolink MyRuleDetector/* AI-rule class map (People/Vehicle/DogCat/Face/Package). Existing standalone OnvifEvent emissions are unchanged.
  • reolink/nvr/nvr.ts — open one hub-level PullPoint subscription and route each event by channel to the matching camera. Start/stop lifecycle tied to whether any camera wants ONVIF; a generation counter prevents a torn-down start (mid-connect) from resurrecting. Raw XML logged only under "Debug Events".
  • reolink/nvr/camera.ts — add a "Use ONVIF for Object Detection" toggle and a debounced triggerOnvifMotion() that sets motionDetected (sharing the existing motionTimeout) and fires an ObjectDetector event (guarded by the camera's advertised object types). The polled-motion path is skipped while ONVIF is the source, so the two never race.

Validation

Tested on a real Reolink Home Hub Pro with sleeping battery cameras. The ONVIF Source token equals rtspChannel (both 0-based hub index): events route correctly with no cross-fire — e.g. token 001→ch1 Front Door (PeopleDetect), 005→ch5 Gate Area (motion). Cameras that returned device offline to polling now report motion and trigger HKSV recordings.

Note

Like the existing per-camera onvif-events.ts, the subscription is not explicitly renewed — the continuous PullMessages loop keeps it alive in practice. A follow-up could add Renew for hubs whose firmware enforces TerminationTime.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an opt-in ONVIF PullPoint (push) event path for Reolink Home Hub (Pro) channels so sleeping battery/solar cameras can still deliver motion and AI/object detections to Scrypted/HomeKit when Reolink polling endpoints return “device offline”.

Changes:

  • Adds hub-level ONVIF subscription management in the Reolink NVR device and routes events to cameras by channel.
  • Adds a per-camera toggle to use ONVIF for motion/object detection and debounced motion/object emission driven by ONVIF.
  • Enhances ONVIF event parsing to extract source channel and interpret Reolink AI rule topics into motion/class signals.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
plugins/reolink/src/nvr/nvr.ts Starts/stops a single hub-level ONVIF PullPoint subscription and routes interpreted events to the correct camera by channel.
plugins/reolink/src/nvr/camera.ts Adds per-camera “Use ONVIF for Object Detection” toggle and ONVIF-driven motion/object emission; skips polled motion when ONVIF is enabled.
plugins/onvif/src/onvif-api.ts Parses ONVIF events to extract source channel and interpret motion/object topics for push-based consumers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/onvif/src/onvif-api.ts
Comment thread plugins/onvif/src/onvif-api.ts Outdated
Comment thread plugins/onvif/src/onvif-api.ts Outdated
Comment thread plugins/reolink/src/nvr/nvr.ts
Comment thread plugins/reolink/src/nvr/nvr.ts
Comment thread plugins/reolink/src/nvr/camera.ts
@apocaliss92

Copy link
Copy Markdown

I don't see any need to enable onvif on the hub, considering the hub itsself already ships camera motion while they do sleep (the hub has an internal network catching mail events), if that does not work the fix is something else, please check logs if anything is logged there, I haven't looked at this plugin for a while

@SnoElement SnoElement force-pushed the reolink-onvif-hub-motion branch 2 times, most recently from dca0d2c to dac0369 Compare June 21, 2026 18:49
Battery/solar cameras behind a Reolink Home Hub (Pro) sleep to save power.
While asleep the hub answers the GetMdState/GetAiState polling the NVR client
relies on with "device offline", so motion never reaches Scrypted/HomeKit and
HomeKit Secure Video never records. The hub does, however, push these events
over ONVIF PullPoint.

Add an opt-in ONVIF push path for hub channels:

- onvif-api.ts: extract the source channel token from each event
  (<tt:Source> SimpleItem VideoSourceConfigurationToken/Source/VideoSourceToken),
  interpret the topic into a motion flag plus an optional object class, and emit
  a separate channel-aware 'onvifChannelEvent' (motion, class, channel). The
  existing 'onvifEvent'/'event'/'data' emissions are left unchanged, so this is
  purely additive and existing consumers are unaffected.
- nvr.ts: open ONE hub-level PullPoint subscription, route each event by
  channel to the matching camera, mapping Reolink rule topics
  (People/Vehicle/DogCat/Face/Package + CellMotion/MotionAlarm) to motion and
  an optional ObjectDetector class. Raw event XML is logged only when
  'Debug Events' is enabled.
- camera.ts: add a 'Use ONVIF for Object Detection' control that registers the
  channel and a debounced triggerOnvifMotion() that sets motionDetected and
  fires the ObjectDetector event.

Validated on real hardware (Home Hub Pro, firmware-current) with sleeping
battery cameras: person/vehicle/motion events now arrive over the push
subscription and trigger HomeKit recordings where polling returned offline.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@SnoElement SnoElement force-pushed the reolink-onvif-hub-motion branch from dac0369 to e242322 Compare June 21, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants