rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
387 stars 72 forks source link

Cross line alarm sensor does not work with IPC-Color4K-X-2.8MM #138

Closed fuchsbau123 closed 1 year ago

fuchsbau123 commented 2 years ago

Version of the custom_component

NAME = "Dahua" DOMAIN = "dahua" VERSION = "0.5.0"

Configuration

Camera: IPC-Color4K-X-2.8MM identical to Dahua HFW5849T1-ASE-LED. Firmware: 2.840.15OG002.0.R,build:2021-09-08 HA: core-2021.12.8


No log entries found

Describe the bug

I configured a tripwire rule in the IVS of the camera. The tripwire rule triggers the alerts in the web interface of the camera as expected. I added the camera to Home Assistant with the Dahua integration. The sensor "Cross line alarm sensor" was created inside Home Assistant for this camera. When I cross the tripwire, the sensor "Cross line alarm" is not triggered in Home Assistant. I checked the events in Home Assistant and I found the events related to "CrossLineDetection". Below an example for a stop event.

It seems that the events are correctly received from the camera, but the sensor "Cross line alarm" of the camera is not updated. Any idea why?

"event_type": "dahua_event_received",
"data": {
    "name": "Outdoor street",
    "Code": "CrossLineDetection",
    "action": "Stop",
    "index": "0",
    "data": {
        "Class": "Normal",
        "CountInGroup": 1,
        "DetectLine": [
            [
                6353,
                2139
            ],
            [
                4551,
                1750
            ],
            [
                2530,
                1686
            ],
            [
                0,
                2236
            ]
        ],
        "Direction": "RightToLeft",
        "EventID": 10097,
        "GroupID": 52,
        "Name": "IVS-1",
        "Object": {
            "Action": "Appear",
            "BelongID": 0,
            "BoundingBox": [
                5192,
                1152,
                5656,
                2992
            ],
            "Center": [
                5424,
                2072
            ],
            "Confidence": 0,
            "LowerBodyColor": [
                0,
                0,
                0,
                0
            ],
            "MainColor": [
                0,
                0,
                0,
                0
            ],
            "ObjectID": 7299,
            "ObjectType": "Human",
            "RelativeID": 0,
            "Speed": 0,
            "humanTripLineDirection": 0
        },
        "PTS": 43034387550,
        "RuleID": 4,
        "Track": [],
        "UTC": 1641559601,
        "UTCMS": 503
    },
    "DeviceName": "Outdoor street"
},
"origin": "LOCAL",
"time_fired": "2022-01-07T11:46:42.412439+00:00",
"context": {
    "id": "bc088b9640c2e0de8346f2cc062b521b",
    "parent_id": null,
    "user_id": null
}

}

Debug log

dahua.zip

mcdhome commented 2 years ago

I am having the same issue with N43AM5Z cameras. In The dahua interface, my IVS tripwre rule works and fires. But the Cross Line Alarm doesn't fire in Home Assistant sensor added by this repo. Smart Human Detection works fine and I can see if fire in home assistant. I see no log errors, Cross Line Alarm just stays in the "Clear" status even though on the Dahua NVR I can see the Trip wire IVS fired. Thanks for this repo, very useful. I am using the latest main release version of of today.

mcdhome commented 2 years ago

Found this in the release notes. Guess it was intentional. Trying to figure out how to reverse it in my case so Line sensor takes precedence. 0.9.21(Aug 30, 2021) BREAKING CHANGE If human detection is enabled, fires the SmartMotionHuman binary sensor instead of the CrossLineDetection or CrossRegionDetection binary sensor, for both VTO/Doorbells/Cameras

mcdhome commented 2 years ago

Think I have a solution per what he was expressing in the notes. If I turn off smart human detection on a camera in the Home Assistant interface for that camera, the Smart Motion Human in Home Assistant now only fires when it is a cross line event, not just when it sees a human in the target area. Tested it manually with the camera and seems to be working well. so @fuchsbau123 this might be a solution. You lose basic smart human detection but gain Tripwire.

rroller commented 2 years ago

I have an IPC-Color4K-X-2.8MM arriving today. I'll set it up and test out.

I assume you are still having this issue?

fuchsbau123 commented 2 years ago

I have an IPC-Color4K-X-2.8MM arriving today. I'll set it up and test out.

I assume you are still having this issue?

Hi Ronnie, yes I still have the issue. Thanks for all your effort put into this integration. BTW: The camera is really nice and have a very impressive color night view :-)

rroller commented 2 years ago

Just setup the IPC-Color4K-X-2.8MM camera. I'd still say that I can't find a camera with better quality than my IPC-HDW5831R-ZE. Little disappointed to be honest.

I also ordered 2 IPC-HDW5842T-ZE-S2 but they won't be here for another couple of weeks, I'll see how they compare to the IPC-HDW5831R-ZE.

rroller commented 2 years ago

Update: The nighttime color and level of detail is insane on this cam. Wow!

fuchsbau123 commented 2 years ago

Hi Ronnie, I still have the issue. It also affects the following Dahua camera: IPC-HDW3841EMP-AS

Again: I was able to fix it with listening to the event _dahua_eventreceived in NodeRed for CrossRegionDetection or CrossLineDetection events and trigger an input_boolean. So all events are correctly generated by the cameras, but the integration did not set correctly the sensor Cross Line Alarm or Cross Region Detection.

I use the Dahua integration version 0.9.39 and HA core-2021.12.10

RobinHarteveld commented 2 years ago

Hello all, Any news on this problem? I have the same problem(debug logs crossline alarm, but no trigger in HA). Camera: IPC-HDW5442TM-ASE Firmware: 2.800.0000000.19.R,build:2020-07-09

I think maybe the extra "data" in the trigger is not processed correctly by the add-on, but my scripting knowledge is not good enough to debug this.

Is there a way to debug this?

zabda commented 2 years ago

Hello,

Same here,

Device Type: DH-IPC-HFW3849T1-AS-PV-S3 System Version: V2.840.0000000.10.R, Build Date: 2021-09-30 WEB Version: V3.2.1.1127102 ONVIF Version: 20.12(V3.1.0.1064635) Algorithm Version: 1.0.7 Security Baseline Version: V2.1

(event is triggered)

Event 15 fired 21:50: { "event_type": "dahua_event_received", "data": { "Code": "CrossRegionDetection", "action": "Start", "index": "0", "data": { "Action": "Inside", "Class": "Normal", "CountInGroup": 1, "DetectRegion": [ ... omitted for brevity ], "EventID": 10233, "GroupID": 0, "Name": "Pool Entry", "Object": { "Action": "Appear", "BelongID": 0, "BoundingBox": [ 5488, 2488, 5984, 4648 ], "Center": [ 5736, 3568 ], "Confidence": 0, "FusionInfo": { "BelongID": 0, "CartPosX": 0, "CartPosY": 0, "GpsPosValid": 0, "GpsPostion": { "Latitude": 0, "Longitude": 0 }, "ObjectSource": 0, "RadarCoorXyValid": 0, "Speed": 0, "SpeedValid": 0 }, "LowerBodyColor": [ 0, 0, 0, 0 ], "MainColor": [ 0, 0, 0, 0 ], "ObjectID": 4695, "ObjectType": "Human", "RelativeID": 0, "Speed": 0, "humanTripLineDirection": 0 }, "PTS": 43050691060, "RuleID": 1, "Track": [], "UTC": 1654552254, "UTCMS": 686 }, "name": "Front Garden Cam", "DeviceName": "Front Garden Cam" }, "origin": "LOCAL", "time_fired": "2022-06-06T19:50:54.861258+00:00", "context": { "id": "01G4X93Z4DVBMVW85NBRRJXYR7", "parent_id": null, "user_id": null } }

Event 16 fired 21:50: { "event_type": "dahua_event_received", "data": { "Code": "CrossRegionDetection", "action": "Stop", "index": "0", "data": { "Action": "Inside", "Class": "Normal", "CountInGroup": 1, "DetectRegion": [ ... omitted for brevity "EventID": 10233, "GroupID": 0, "Name": "Pool Entry", "Object": { "Action": "Appear", "BelongID": 0, "BoundingBox": [ 5488, 2488, 5984, 4648 ], "Center": [ 5736, 3568 ], "Confidence": 0, "FusionInfo": { "BelongID": 0, "CartPosX": 0, "CartPosY": 0, "GpsPosValid": 0, "GpsPostion": { "Latitude": 0, "Longitude": 0 }, "ObjectSource": 0, "RadarCoorXyValid": 0, "Speed": 0, "SpeedValid": 0 }, "LowerBodyColor": [ 0, 0, 0, 0 ], "MainColor": [ 0, 0, 0, 0 ], "ObjectID": 4695, "ObjectType": "Human", "RelativeID": 0, "Speed": 0, "humanTripLineDirection": 0 }, "PTS": 43050691060, "RuleID": 1, "Track": [], "UTC": 1654552254, "UTCMS": 686 }, "name": "Front Garden Cam", "DeviceName": "Front Garden Cam" }, "origin": "LOCAL", "time_fired": "2022-06-06T19:50:57.654690+00:00", "context": { "id": "01G4X941VP6BAA86RW7GS441ZK", "parent_id": null, "user_id": null } } However the "Cross Region Detection" entity did not report an event. image

zabda commented 2 years ago

Hello,

Same here,

Device Type: DH-IPC-HFW3849T1-AS-PV-S3 System Version: V2.840.0000000.10.R, Build Date: 2021-09-30 WEB Version: V3.2.1.1127102 ONVIF Version: 20.12(V3.1.0.1064635) Algorithm Version: 1.0.7 Security Baseline Version: V2.1

(event is triggered)

Event 15 fired 21:50: { "event_type": "dahua_event_received", "data": { "Code": "CrossRegionDetection", "action": "Start", "index": "0", "data": { "Action": "Inside", "Class": "Normal", "CountInGroup": 1, "DetectRegion": [ ... omitted for brevity ], "EventID": 10233, "GroupID": 0, "Name": "Pool Entry", "Object": { "Action": "Appear", "BelongID": 0, "BoundingBox": [ 5488, 2488, 5984, 4648 ], "Center": [ 5736, 3568 ], "Confidence": 0, "FusionInfo": { "BelongID": 0, "CartPosX": 0, "CartPosY": 0, "GpsPosValid": 0, "GpsPostion": { "Latitude": 0, "Longitude": 0 }, "ObjectSource": 0, "RadarCoorXyValid": 0, "Speed": 0, "SpeedValid": 0 }, "LowerBodyColor": [ 0, 0, 0, 0 ], "MainColor": [ 0, 0, 0, 0 ], "ObjectID": 4695, "ObjectType": "Human", "RelativeID": 0, "Speed": 0, "humanTripLineDirection": 0 }, "PTS": 43050691060, "RuleID": 1, "Track": [], "UTC": 1654552254, "UTCMS": 686 }, "name": "Front Garden Cam", "DeviceName": "Front Garden Cam" }, "origin": "LOCAL", "time_fired": "2022-06-06T19:50:54.861258+00:00", "context": { "id": "01G4X93Z4DVBMVW85NBRRJXYR7", "parent_id": null, "user_id": null } }

Event 16 fired 21:50: { "event_type": "dahua_event_received", "data": { "Code": "CrossRegionDetection", "action": "Stop", "index": "0", "data": { "Action": "Inside", "Class": "Normal", "CountInGroup": 1, "DetectRegion": [ ... omitted for brevity "EventID": 10233, "GroupID": 0, "Name": "Pool Entry", "Object": { "Action": "Appear", "BelongID": 0, "BoundingBox": [ 5488, 2488, 5984, 4648 ], "Center": [ 5736, 3568 ], "Confidence": 0, "FusionInfo": { "BelongID": 0, "CartPosX": 0, "CartPosY": 0, "GpsPosValid": 0, "GpsPostion": { "Latitude": 0, "Longitude": 0 }, "ObjectSource": 0, "RadarCoorXyValid": 0, "Speed": 0, "SpeedValid": 0 }, "LowerBodyColor": [ 0, 0, 0, 0 ], "MainColor": [ 0, 0, 0, 0 ], "ObjectID": 4695, "ObjectType": "Human", "RelativeID": 0, "Speed": 0, "humanTripLineDirection": 0 }, "PTS": 43050691060, "RuleID": 1, "Track": [], "UTC": 1654552254, "UTCMS": 686 }, "name": "Front Garden Cam", "DeviceName": "Front Garden Cam" }, "origin": "LOCAL", "time_fired": "2022-06-06T19:50:57.654690+00:00", "context": { "id": "01G4X941VP6BAA86RW7GS441ZK", "parent_id": null, "user_id": null } } However the "Cross Region Detection" entity did not report an event. image

I think it may be caused by this bit of code from init.py

` # For CrossLineDetection, the event data will look like this... and if there's a human detected then we'll use the SmartMotionHuman code instead

{

    #    "Code": "CrossRegionDetection",
    #    "Data": {
    #        "Object": {
    #            "ObjectType": "Human",
    #        }
    #    }
    # }
    if code == "CrossLineDetection" or code == "CrossRegionDetection":
        data = event.get("data", event.get("Data", {}))
        is_human = data.get("Object", {}).get("ObjectType", "").lower() == "human"
        if is_human and self._dahua_event_listeners.get(self.get_event_key(code)) is not None:
            return "SmartMotionHuman"`

The events are being converted to "SmartMotionHuman" if there is a human, (and not triggering the other two entities... ('CrossLineDetection/CrossRegionDetection') ? ).

https://github.com/rroller/dahua/commit/99457845a114c1f592b3a39c0d5ee11415412f15#commitcomment-75465139

timvdsm commented 2 years ago

Indeed this doesn't sound logical. I have a camera in front of my house, which sees my entry area and a part of the street. On the street, there are off course many humans passing by and they are generating the Smartmotion human detection. However i've created an IVS intrusion zone for my entry area. And i want an automation to run when a human enters this area. The Dahua camera is generating a CrossRegionDetection, however HA only receives a Smartmotion Human detection. So for me I am unable to trigger an automation, as it will fire the automation every time a human is detected in the street as well. Is there a possibility to change it?