question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Smart Motion events not arriving with Dahua IP cam

See original GitHub issue

Hi Ronnie, thanks for your work on the integration!

I’m having some issues receiving SMD events from my Dahua cameras.

I’m using a Dahua IPC-HDW5442TP-ZE-2712, firmware: 2.820.15OG001.0.R,build:2021-05-25. Integration version 0.9.38. HA 2022.2.9.

Enabled entities in HA: Screenshot from 2022-02-19 16-44-21

When I query a camera’s API directly, I see smart motion events:

$ curl -s --digest -u admin:$DAHUA_PASSWORD \
  "http://10.0.60.2/cgi-bin/configManager.cgi?action=getConfig&name=SmartMotionDetect"
table.SmartMotionDetect[0].Enable=true
table.SmartMotionDetect[0].ObjectTypes.Human=true
table.SmartMotionDetect[0].ObjectTypes.Vehicle=true
table.SmartMotionDetect[0].Sensitivity=High

$ curl -s --digest -u admin:$DAHUA_PASSWORD \
  "http://10.0.60.2/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5"
--myboundary
Content-Type: text/plain
Content-Length:127

Code=VideoMotion;action=Start;index=0;data={
   "Id" : [ 0 ],
   "RegionName" : [ "Region1" ],
   "SmartMotionEnable" : true
}

--myboundary
Content-Type: text/plain
Content-Length:41

Code=VideoMotionInfo;action=State;index=0

--myboundary
Content-Type: text/plain
Content-Length:222

Code=SmartMotionVehicle;action=Start;index=0;data={
   "RegionName" : [ "Region1" ],
   "WindowId" : [ 0 ],
   "object" : [
      {
         "Rect" : [ 5384, 4096, 6352, 4904 ],
         "VehicleID" : 18028
      }
   ]
}

Using the event listener in HA, I only get generic VideoMotion events (instead of code SmartMotionVehicle, see DAHUA_HTTP_API_V2.76 page 83):

{
    "event_type": "dahua_event_received",
    "data": {
        "name": "Front yard",
        "Code": "VideoMotion",
        "action": "Start",
        "index": "0",
        "data": {
            "Id": [
                0
            ],
            "RegionName": [
                "Region1"
            ],
            "SmartMotionEnable": true
        },
        "DeviceName": "Front yard"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-19T15:56:34.971665+00:00",
    "context": {
        "id": "41827b2271a562574581382fe319943c",
        "parent_id": null,
        "user_id": null
    }
}

Debug logs:

2022-02-19 16:56:34 DEBUG (MainThread) [custom_components.dahua] Cam Data received from channel 0: {'name': 'Front yard', 'Code': 'VideoMotion', 'action': 'Start', 'index': '0', 'data': {'Id': [0], 'RegionName': ['Region1'], 'SmartMotionEnable': True}, 'DeviceName': 'Front yard'}
2022-02-19 16:56:37 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.068 seconds (success: True)
2022-02-19 16:57:20 DEBUG (MainThread) [custom_components.dahua] Cam Data received from channel 0: {'name': 'Front yard', 'Code': 'VideoMotion', 'action': 'Stop', 'index': '0', 'data': {'Id': [0], 'RegionName': ['Region1'], 'SmartMotionEnable': True}, 'DeviceName': 'Front yard'}

So the binary_sensor.front_yard_smart_motion_human and binary_sensor.front_yard_smart_motion_vehicle sensors remain quiet, while the generic binary_sensor.front_yard_motion_alarm_2 does respond to generic motion events.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
rrollercommented, Feb 20, 2022

BTW, you can try this locally… Edit this file - https://github.com/rroller/dahua/blob/main/custom_components/dahua/client.py#L608

Change codes = ",".join(events) to codes = "All"

1reaction
rrollercommented, Feb 19, 2022

I might have an idea of what’s going on, maybe, but it’s hard to confirm. It’s possible that the event parsing isn’t that great and if more than 1 event arrives in a single message, only the first one is processed. I have some better event handling code I’ve just written that I’ve tested and verified works when it receives more than 1 event. I’ll let you know when I release the code… should be today.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot/NVR/Motion Record Troubleshoot - Dahua Wiki
Motion detection function does not work. There are following possibilities: 1. Sensitivity is too low, or Threshold too high.
Read more >
Dahua NVR 2108 with Foscam IP cameras (ONVIF). Motion ...
So no 'Rules' showing for motion detection or other analytics in ODM? And no events showing up in the Events page?
Read more >
Feature Request: Smart motion event support #15 - GitHub
My initial idea is that if a VideoMotion event came in with ... Motion for Driveway posted to homebridge-camera-ffmpeg, received { error: ...
Read more >
Dahua CCTV How to set up Smart Motion Detection - YouTube
Dahua CCTV How to set up Smart Motion Detection ... How to set up motion & smart events on your Gen2 Hikvision Cameras...
Read more >
Dahua IP camera setup with remote view - no NVR - YouTube
Dahua IP camera setup with remote view - step by step - 2021.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found