Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart Motion events not arriving with Dahua IP cam #166

Closed
sjaakvandenberg opened this issue Feb 19, 2022 · 21 comments
Closed

Smart Motion events not arriving with Dahua IP cam #166

sjaakvandenberg opened this issue Feb 19, 2022 · 21 comments

Comments

@sjaakvandenberg
Copy link

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.

@rroller
Copy link
Owner

rroller commented Feb 19, 2022

Wow, thank you for the very details logs/examples! I'm going to look into this now...

@rroller
Copy link
Owner

rroller commented 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.

@rroller
Copy link
Owner

rroller commented Feb 19, 2022

I released https://github.com/rroller/dahua/releases/tag/0.9.39

Can you give it a try?

@sjaakvandenberg
Copy link
Author

I'll try it first thing tomorrow morning (in about 7 hours or so). Thank you for your fast response!

@sjaakvandenberg
Copy link
Author

sjaakvandenberg commented Feb 20, 2022

I updated to 0.9.39 and I'm afraid I'm seeing the same thing.

I recorded a little over a minute of a camera where there is some movement and near the end a cars enters and leaves the frame. It is picked up by the stream directly from the camera, but not present as a "Code": "SmartMotionVehicle" from the HA event listener.

HA core log:

2022-02-20 08:30:01 DEBUG (Thread-32) [custom_components.dahua] Keep alive
2022-02-20 08:30:01 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'VideoMotion', 'action': 'Stop', 'index': '0', 'data': {'Id': [0], 'RegionName': ['Region1'], 'SmartMotionEnable': True}}]
2022-02-20 08:30:05 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'VideoMotion', 'action': 'Start', 'index': '0', 'data': {'Id': [0], 'RegionName': ['Region1'], 'SmartMotionEnable': True}}]
2022-02-20 08:30:06 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.605 seconds (success: True)
2022-02-20 08:30:13 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'VideoMotion', 'action': 'Stop', 'index': '0', 'data': {'Id': [0], 'RegionName': ['Region1'], 'SmartMotionEnable': True}}]
2022-02-20 08:30:28 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.687 seconds (success: True)
2022-02-20 08:30:38 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'VideoMotion', 'action': 'Start', 'index': '0', 'data': {'Id': [0], 'RegionName': ['Region1'], 'SmartMotionEnable': True}}]
2022-02-20 08:30:56 DEBUG (Thread-33) [custom_components.dahua] Keep alive
2022-02-20 08:30:58 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.712 seconds (success: True)
2022-02-20 08:31:06 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'VideoMotion', 'action': 'Stop', 'index': '0', 'data': {'Id': [0], 'RegionName': ['Region1'], 'SmartMotionEnable': True}}]
2022-02-20 08:31:07 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'VideoMotion', 'action': 'Start', 'index': '0', 'data': {'Id': [0], 'RegionName': ['Region1'], 'SmartMotionEnable': True}}]
2022-02-20 08:31:12 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'VideoMotion', 'action': 'Stop', 'index': '0', 'data': {'Id': [0], 'RegionName': ['Region1'], 'SmartMotionEnable': True}}]
2022-02-20 08:31:28 DEBUG (MainThread) [custom_components.dahua] Finished fetching dahua data in 0.693 seconds (success: True)

HA event listener recorded 7 events (in reverse order):

Event 6 fired 8:31 AM:
{
    "event_type": "dahua_event_received",
    "data": {
        "Code": "VideoMotion",
        "action": "Stop",
        "index": "0",
        "data": {
            "Id": [
                0
            ],
            "RegionName": [
                "Region1"
            ],
            "SmartMotionEnable": true
        },
        "name": "Front yard",
        "DeviceName": "Front yard"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-20T07:31:12.621156+00:00",
    "context": {
        "id": "0d7f04ce480847786e41afed18f746de",
        "parent_id": null,
        "user_id": null
    }
}
Event 5 fired 8:31 AM:
{
    "event_type": "dahua_event_received",
    "data": {
        "Code": "VideoMotion",
        "action": "Start",
        "index": "0",
        "data": {
            "Id": [
                0
            ],
            "RegionName": [
                "Region1"
            ],
            "SmartMotionEnable": true
        },
        "name": "Front yard",
        "DeviceName": "Front yard"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-20T07:31:07.728237+00:00",
    "context": {
        "id": "0a44d08b257ee436371a01022c2df32c",
        "parent_id": null,
        "user_id": null
    }
}
Event 4 fired 8:31 AM:
{
    "event_type": "dahua_event_received",
    "data": {
        "Code": "VideoMotion",
        "action": "Stop",
        "index": "0",
        "data": {
            "Id": [
                0
            ],
            "RegionName": [
                "Region1"
            ],
            "SmartMotionEnable": true
        },
        "name": "Front yard",
        "DeviceName": "Front yard"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-20T07:31:06.621460+00:00",
    "context": {
        "id": "88a37481ee0c56d328cda9fd4b931345",
        "parent_id": null,
        "user_id": null
    }
}
Event 3 fired 8:30 AM:
{
    "event_type": "dahua_event_received",
    "data": {
        "Code": "VideoMotion",
        "action": "Start",
        "index": "0",
        "data": {
            "Id": [
                0
            ],
            "RegionName": [
                "Region1"
            ],
            "SmartMotionEnable": true
        },
        "name": "Front yard",
        "DeviceName": "Front yard"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-20T07:30:38.315017+00:00",
    "context": {
        "id": "516efafdc625340ff20dee4fc4cdbddf",
        "parent_id": null,
        "user_id": null
    }
}
Event 2 fired 8:30 AM:
{
    "event_type": "dahua_event_received",
    "data": {
        "Code": "VideoMotion",
        "action": "Stop",
        "index": "0",
        "data": {
            "Id": [
                0
            ],
            "RegionName": [
                "Region1"
            ],
            "SmartMotionEnable": true
        },
        "name": "Front yard",
        "DeviceName": "Front yard"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-20T07:30:13.594281+00:00",
    "context": {
        "id": "cdaf77100754530dea0469e48132c055",
        "parent_id": null,
        "user_id": null
    }
}
Event 1 fired 8:30 AM:
{
    "event_type": "dahua_event_received",
    "data": {
        "Code": "VideoMotion",
        "action": "Start",
        "index": "0",
        "data": {
            "Id": [
                0
            ],
            "RegionName": [
                "Region1"
            ],
            "SmartMotionEnable": true
        },
        "name": "Front yard",
        "DeviceName": "Front yard"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-20T07:30:05.514329+00:00",
    "context": {
        "id": "c6842d0b63c3c3828a46dbeec2c548f7",
        "parent_id": null,
        "user_id": null
    }
}
Event 0 fired 8:30 AM:
{
    "event_type": "dahua_event_received",
    "data": {
        "Code": "VideoMotion",
        "action": "Stop",
        "index": "0",
        "data": {
            "Id": [
                0
            ],
            "RegionName": [
                "Region1"
            ],
            "SmartMotionEnable": true
        },
        "name": "Front yard",
        "DeviceName": "Front yard"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-20T07:30:01.591866+00:00",
    "context": {
        "id": "fd74613d225f1b94fa4796104a50c2a0",
        "parent_id": null,
        "user_id": null
    }
}

Direct camera stream:

$ 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:9

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

Code=VideoMotionInfo;action=State;index=0

--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:41

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0


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

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0


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

Heartbeat
--myboundary
Content-Type: text/plain
Content-Length:126

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



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

Heartbeat

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

Heartbeat

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

Heartbeat

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

Heartbeat

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

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

Code=VideoMotionInfo;action=State;index=0

--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:41

Code=VideoMotionInfo;action=State;index=0


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

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0


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

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0


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

Heartbeat
--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" : [ 6280, 4248, 7144, 5032 ],
         "VehicleID" : 27833
      }
   ]
}



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

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0

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

Code=SmartMotionVehicle;action=Stop;index=0;data={
   "RegionName" : [ "Region1" ],
   "WindowId" : [ 0 ],
   "object" : [
      {
         "Rect" : [ 7472, 4704, 7840, 5280 ],
         "VehicleID" : 27833
      }
   ]
}



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

Heartbeat
--myboundary
Content-Type: text/plain
Content-Length:126

Code=VideoMotion;action=Stop;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:127

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



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

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0

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

Code=VideoMotionInfo;action=State;index=0

@rroller
Copy link
Owner

rroller commented Feb 20, 2022

Thanks.

When you run the command locally with curl, you are using [All], but for the integration I'm passing in the selected events from the configuration options when the device was setup. I'm wondering if I should just pass [All] too? I can't really think of any downside. Did you select SmartMotionVehicle when you added your device?

image

@rroller
Copy link
Owner

rroller commented 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"

@sjaakvandenberg
Copy link
Author

I re-added the camera to be sure, leaving defaults set as in your screenshot -- no change (Screenshot from 2022-02-20 18-37-04).

As a small aside, I noticed that the use of newlines is inconsistent when watching the direct camera stream:

--myboundary                                                                                      
Content-Type: text/plain                                                                          
Content-Length:41                                                                                 
                                                 
Code=VideoMotionInfo;action=State;index=0        
                                                 
--myboundary                                     
Content-Type: text/plain                         
Content-Length:41                                
                                                 
Code=VideoMotionInfo;action=State;index=0        
                                                 
--myboundary                                     
Content-Type: text/plain 
Content-Length:41

Code=VideoMotionInfo;action=State;index=0


--myboundary 
Content-Type: text/plain 
Content-Length:9
  1. I tried your code change and restarted core. I didn't see any new events coming from the dahua_event_received event listener.
  2. I changed those lines to the following:
        # codes = ",".join(events)
        # codes = "[All]"
        url = "{0}/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5".format(self._base, codes)

And I got some events back from another camera (my doorbell), but not the first camera.
3. I then removed the integration and re-added only the intended camera. Still see only doorbell events.
4. Reboot core. Now no new events with only first camera present.
5. Check infrared toggle switch, it is turning on and off on the camera (checked with gDMSS app.
6. Revert both code changes to original and restart core. VideoMotion events are coming back in. Still no SmartMotionVehicle. Curiously enough those events have also stopped coming on the direct camera stream that I've been monitoring in the background.
7. Check the camera settings:

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

Let me try and get things to a working state again before I continue.

@rroller
Copy link
Owner

rroller commented Feb 20, 2022

Your code change won't work...

        # codes = "[All]"
        url = "{0}/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5".format(self._base, codes)

Needs to be like this...

        # codes = "[All]"
        url = "{0}/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5".format(self._base)

@sjaakvandenberg
Copy link
Author

Ah, I completely read over that. :|

@sjaakvandenberg
Copy link
Author

Hmm.

  1. With the code from 0.9.39. Gave the camera a reboot. SmartMotionVehicle events are back on the direct camera stream
  2. With the following change:
        # codes = "[All]"
        url = "{0}/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5".format(self._base)

I'm getting better results in HA:

HA core log:

2022-02-20 19:58:41 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'SmartMotionVehicle', 'action': 'Start', 'index': '0', 'data': {'RegionName': ['Region1'], 'WindowId': [0], 'object': [{'Rect': [6104, 3744, 8024, 5712], 'VehicleID': 114}]}}]
2022-02-20 19:58:46 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'SmartMotionVehicle', 'action': 'Stop', 'index': '0', 'data': {'RegionName': ['Region1'], 'WindowId': [0], 'object': [{'Rect': [6448, 3720, 7856, 5600], 'VehicleID': 114}]}}]
2022-02-20 19:58:47 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'VideoMotionInfo', 'action': 'State', 'index': '0'}]

Camera stream:

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

Code=SmartMotionVehicle;action=Stop;index=0;data={
   "RegionName" : [ "Region1" ],
   "WindowId" : [ 0 ],
   "object" : [
      {
         "Rect" : [ 6448, 3720, 7856, 5600 ],
         "VehicleID" : 114
      }
   ]
}


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

Code=VideoMotionInfo;action=State;index=0

--myboundary

HA event log!:

Event 47 fired 7:58 PM:
{
    "event_type": "dahua_event_received",
    "data": {
        "Code": "SmartMotionVehicle",
        "action": "Start",
        "index": "0",
        "data": {
            "RegionName": [
                "Region1"
            ],
            "WindowId": [
                0
            ],
            "object": [
                {
                    "Rect": [
                        6104,
                        3744,
                        8024,
                        5712
                    ],
                    "VehicleID": 114
                }
            ]
        },
        "name": "Front yard",
        "DeviceName": "Front yard"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-20T18:58:41.365506+00:00",
    "context": {
        "id": "d2592901a3c5262d34b8fafb3a06bcad",
        "parent_id": null,
        "user_id": null
    }
}

I'm going to try and see whether I can reproduce it with another camera.

@sjaakvandenberg
Copy link
Author

I could reproduce it with:

        # Use codes=[All] for all codes
        # codes = ",".join(events)
        url = "{0}/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5".format(self._base)
Event 120 fired 8:21 PM:
{
    "event_type": "dahua_event_received",
    "data": {
        "Code": "SmartMotionVehicle",
        "action": "Stop",
        "index": "0",
        "data": {
            "RegionName": [
                "Region1"
            ],
            "WindowId": [
                0
            ],
            "object": [
                {
                    "Rect": [
                        6856,
                        3960,
                        7960,
                        5632
                    ],
                    "VehicleID": 640
                }
            ]
        },
        "name": "Camera x",
        "DeviceName": "Camera x"
    },
    "origin": "LOCAL",
    "time_fired": "2022-02-20T19:21:48.081827+00:00",
    "context": {
        "id": "272301c0f7769ccf8578c42db3e80b22",
        "parent_id": null,
        "user_id": null
    }
}

Camera stream:

Heartbeat                                        
--myboundary                                     
Content-Type: text/plain                         
Content-Length:219                               
                                                 
Code=SmartMotionVehicle;action=Stop;index=0;data={
   "RegionName" : [ "Region1" ],                 
   "WindowId" : [ 0 ],                           
   "object" : [                                  
      {                                          
         "Rect" : [ 6856, 3960, 7960, 5632 ],    
         "VehicleID" : 640                       
      }                                          
   ]                                             
}

Going to revert to 0.9.39 and retry.

@sjaakvandenberg
Copy link
Author

Could also reproduce the intended behavior on 0.9.39. So it appears to be working. I'll continue testing some more.

2022-02-20 20:58:04 DEBUG (MainThread) [custom_components.dahua] Events received from 10.0.60.2 on channel 0: [{'Code': 'SmartMotionHuman', 'action': 'Start', 'index': '0', 'data': {'RegionName': ['Region1'], 'WindowId': [0], 'object': [{'HumamID': 161, 'Rect': [5136, 3848, 5392, 4784]}]}}]
--myboundary
Content-Type: text/plain
Content-Length:216

Code=SmartMotionHuman;action=Start;index=0;data={
   "RegionName" : [ "Region1" ],
   "WindowId" : [ 0 ],
   "object" : [
      {
         "HumamID" : 108,
         "Rect" : [ 3648, 2456, 4496, 4312 ]
      }
   ]
}

@rroller
Copy link
Owner

rroller commented Feb 20, 2022

Sorry, what was the thing you did to get it working?

@sjaakvandenberg
Copy link
Author

The HA event listener is outputting SmartMotionHuman and SmartMotionVehicle events now.

@rroller
Copy link
Owner

rroller commented Feb 20, 2022

Great! But did you have to change anything to get it working? Or does it just work with 0.9.39 without any changes?

@sjaakvandenberg
Copy link
Author

Your code change won't work...

        # codes = "[All]"
        url = "{0}/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5".format(self._base, codes)

Needs to be like this...

        # codes = "[All]"
        url = "{0}/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5".format(self._base)

This looks like it worked normally, event with my error:

>>> "{0} {1}".format("a", "b")
'a b'
>>> "{0} ".format("a", "b")
'a '
>>>

@rroller
Copy link
Owner

rroller commented Feb 20, 2022

Sorry, I'm not following. Do you need any changes from me? Or is it jus working now?

@sjaakvandenberg
Copy link
Author

Great! But did you have to change anything to get it working? Or does it just work with 0.9.39 without any changes?

It just works...

Sorry, I'm not following. Do you need any changes from me? Or is it jus working now?

No, it looks like 0.9.39 just works. Binary sensors for SmartMotionHuman and SmartMotionVehicle included. I'm not sure what was causing it.

@rroller
Copy link
Owner

rroller commented Feb 20, 2022

Nice, so maybe the better event parsing in 0.9.39 worked.

@sjaakvandenberg
Copy link
Author

Thanks for your work. I'll open a new linked issue if anything new arises.

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

No branches or pull requests

2 participants