Skip to content

Fix SmartMotionHuman/Vehicle not triggered with CrossLine/CrossRegion events - #557

Merged
rroller merged 1 commit into
rroller:mainfrom
MicheleMercuri:fix/smart-motion-human-priority
Mar 21, 2026
Merged

Fix SmartMotionHuman/Vehicle not triggered with CrossLine/CrossRegion events#557
rroller merged 1 commit into
rroller:mainfrom
MicheleMercuri:fix/smart-motion-human-priority

Conversation

@MicheleMercuri

Copy link
Copy Markdown
Contributor

Problem

When both CrossLineDetection/CrossRegionDetection and SmartMotionHuman are included in the configured events list, translate_event_code() fails to translate CrossLine/CrossRegion events with ObjectType=Human into SmartMotionHuman. This leaves the SmartMotionHuman binary sensor permanently off, even though the camera correctly detects humans.

Root cause

In translate_event_code(), the existing logic at line 597:

if is_human and self._dahua_event_listeners.get(self.get_event_key(code)) is None:
    return "SmartMotionHuman"

checks whether the listener for the CrossLineDetection event key is None. But when both CrossLineDetection and SmartMotionHuman are in the events list, the CrossLineDetection listener is registered, so get() returns the listener (not None), and the condition always evaluates to False. The translation never happens.

This affects users who have both IVS (CrossLineDetection/CrossRegionDetection) and SmartMotion events enabled — a common setup with WizSense cameras (e.g. IPC-HDW3441TM-AS) connected through an NVR.

Fix

Added a priority check before the existing fallback: if a SmartMotionHuman or SmartMotionVehicle listener exists, translate to it directly when the ObjectType matches. The original fallback logic is preserved for backward compatibility (translates to SmartMotionHuman when no CrossLine listener exists).

is_vehicle = data.get("Object", {}).get("ObjectType", "").lower() == "vehicle"
if is_human and self._dahua_event_listeners.get(self.get_event_key("SmartMotionHuman")) is not None:
    return "SmartMotionHuman"
if is_vehicle and self._dahua_event_listeners.get(self.get_event_key("SmartMotionVehicle")) is not None:
    return "SmartMotionVehicle"

Testing

  • Tested with 4x IPC-HDW3441TM-AS cameras connected via NVR DHI-NVR4104HS-P-4KS2
  • Both CrossRegionDetection and SmartMotionHuman in the events list
  • Before fix: SmartMotionHuman binary sensors never turned on
  • After fix: SmartMotionHuman correctly triggers on human detection events
  • No regressions observed on other event types

… events are subscribed

When both CrossLineDetection/CrossRegionDetection and SmartMotionHuman are in
the events list, translate_event_code() should prioritize translating to
SmartMotionHuman/SmartMotionVehicle when the ObjectType matches and a listener
exists for the SmartMotion event.

Previously, the `is None` check on the CrossLineDetection listener always
failed (returned False) when both events were subscribed, because the listener
for CrossLineDetection was registered. This meant CrossLineDetection events
with ObjectType=Human were never translated to SmartMotionHuman, leaving those
binary_sensors permanently off.

The fix adds a priority check: if a SmartMotionHuman or SmartMotionVehicle
listener exists, translate to it first. The original fallback (translate when
no CrossLine listener exists) is preserved for backward compatibility.

@rroller rroller left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you!

@rroller
rroller merged commit f4d7351 into rroller:main Mar 21, 2026
3 checks passed
@rroller

rroller commented Mar 21, 2026

Copy link
Copy Markdown
Owner

@MicheleMercuri

Copy link
Copy Markdown
Contributor Author

Thanks.

@rroller

rroller commented Mar 22, 2026

Copy link
Copy Markdown
Owner

Seems this is causing issues and I'll need to revert it #560

MicheleMercuri added a commit to MicheleMercuri/dahua that referenced this pull request Mar 23, 2026
…teners

Fixes rroller#560. The previous implementation (rroller#557) returned a single event
code, which meant CrossLineDetection was silently dropped when a
SmartMotion* listener also existed. This change makes
translate_event_code() return a list of codes so both the original
CrossLine/CrossRegion sensor AND the SmartMotion* sensor fire on the
same raw event.

Three touch points:
1. translate_event_code() → returns list[str] instead of str
2. on_receive_vto_event() → iterates over the list
3. on_receive() → iterates over the list

Behavior matrix:
| Config                     | CrossLine + Human | Result                              |
|----------------------------|-------------------|-------------------------------------|
| Only CrossLine subscribed  | ✓                 | [CrossLineDetection]                |
| Only SmartMotion subscribed| ✓                 | [SmartMotionHuman]                  |
| Both subscribed            | ✓                 | [CrossLineDetection, SmartMotionHuman] |
| Neither subscribed         | ✓                 | [SmartMotionHuman] (fallback)       |
rroller pushed a commit that referenced this pull request Mar 23, 2026
…teners (#561)

Fixes #560. The previous implementation (#557) returned a single event
code, which meant CrossLineDetection was silently dropped when a
SmartMotion* listener also existed. This change makes
translate_event_code() return a list of codes so both the original
CrossLine/CrossRegion sensor AND the SmartMotion* sensor fire on the
same raw event.

Three touch points:
1. translate_event_code() → returns list[str] instead of str
2. on_receive_vto_event() → iterates over the list
3. on_receive() → iterates over the list

Behavior matrix:
| Config                     | CrossLine + Human | Result                              |
|----------------------------|-------------------|-------------------------------------|
| Only CrossLine subscribed  | ✓                 | [CrossLineDetection]                |
| Only SmartMotion subscribed| ✓                 | [SmartMotionHuman]                  |
| Both subscribed            | ✓                 | [CrossLineDetection, SmartMotionHuman] |
| Neither subscribed         | ✓                 | [SmartMotionHuman] (fallback)       |
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.

2 participants