pergolafabio / Hikvision-Addons

Home Assistant: Hikvision Doorbell
184 stars 41 forks source link

DS-KD8003-IME1 with DS-KD-KP code support #204

Open AYahoo opened 6 months ago

AYahoo commented 6 months ago

Is there an existing feature request for this?

Add-on

None

Your feature request

DS-KD-KP, is a numeric pad with a access control code to open relays on the KD8003, I would love to have the ability to know which user entered and if the wrong password has been pressed to know if someone is trying to mess with the code, guess it, or just playing with it. I'm sure I saw it on the SDK in the past.

AYahoo commented 6 months ago

Entering the wrong Keypad pin code got me these events:

2024-05-06 21:26:58.951 | DEBUG    | event:_handle_callback:220 - Callback invoked from SDK
2024-05-06 21:26:58.952 | DEBUG    | event:_invoke_handlers:192 - Invoking 2 handlers
2024-05-06 21:26:58.952 | DEBUG    | mqtt:isapi_alarm:279 - Isapi alarm from Gate
2024-05-06 21:26:58.953 | INFO     | event:isapi_alarm:131 - Isapi alarm from Gate

Entering the right code, got me these events (with the door being opened):

2024-05-06 21:25:32.635 | DEBUG    | event:_handle_callback:220 - Callback invoked from SDK
2024-05-06 21:25:32.636 | DEBUG    | event:_invoke_handlers:192 - Invoking 2 handlers
2024-05-06 21:25:32.637 | INFO     | mqtt:update_door_entities:295 - Door 1 unlocked by 112117981081059900 , updating sensor and device trigger
2024-05-06 21:25:32.637 | DEBUG    | sdk.utils:call_ISAPI:125 - Call ISAPI request method url body: GET /ISAPI/System/deviceInfo  
2024-05-06 21:25:32.742 | DEBUG    | sdk.utils:call_ISAPI:165 - Response output: <DeviceInfo version="2.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
<deviceName>OUTDOOR STATION</deviceName>
<deviceID>DELETED</deviceID>
<deviceDescription> Vis</deviceDescription>
<deviceLocation>STD-CGI</deviceLocation>
<systemContact>STD-CGI</systemContact>
<model>DS-KD8003-IME1</model>
<serialNumber>DELETED</serialNumber>
<macAddress>DELETED</macAddress>
<firmwareVersion>V2.2.45</firmwareVersion>
<firmwareReleasedDate>build 210430</firmwareReleasedDate>
<bootVersion>33685549</bootVersion>
<bootReleasedDate>1377310</bootReleasedDate>
<hardwareVersion>0x0</hardwareVersion>
<encoderVersion>V4.0</encoderVersion>
<encoderReleasedDate>build 181206</encoderReleasedDate>
<deviceType>    Vis</deviceType>
<telecontrolID>88</telecontrolID>
<supportBeep>true</supportBeep>
<supportVideoLoss>true</supportVideoLoss>
<alarmOutNum>2</alarmOutNum>
<alarmInNum>4</alarmInNum>
<RS485Num>1</RS485Num>
<customizedInfo></customizedInfo>
</DeviceInfo>

2024-05-06 21:25:32.746 | INFO     | mqtt:handle_device_trigger:456 - Invoking device trigger automation{'name': 'Door unlocked', 'type': 'door open', 'subtype': 'door 0', 'payload': {'control_source': '112117981081059900'}}
2024-05-06 21:25:32.748 | INFO     | event:video_intercom_event:109 - Video intercom event from Gate
pergolafabio commented 6 months ago

Hm, it should be an intercom event, not an isapi one... Do you also have a badge reader? I added an illegal swipe event, there is one in the SDK for that... But I don't think there is an illegal keypad entry

pergolafabio commented 6 months ago

Here is the isapi event SDK, not much usefull info...

https://open.hikvision.com/hardware/structures/NET_DVR_ALARM_ISAPI_INFO.html

pergolafabio commented 6 months ago

Here is the event SDK, only card access is logged, not keypad :-(

pergolafabio commented 6 months ago

https://open.hikvision.com/hardware/structures/NET_DVR_VIDEO_INTERCOM_EVENT.html

AYahoo commented 6 months ago

Nope, no badge reader, only keypad. This is the only events that happened when i used the keypad.

I didn't see it on the SDK, i saw that control4 was able to integrate it somehow.

On Mon, May 6, 2024, 21:47 Pergola Fabio @.***> wrote:

Hm, it should be an intercom event, not an isapi one... Do you also have a badge reader? I added an illegal swipe event, there is one in the SDK for that... But I don't think there is an illegal keypad entry

— Reply to this email directly, view it on GitHub https://github.com/pergolafabio/Hikvision-Addons/issues/204#issuecomment-2096685864, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPRV3R2XKESSKQGQ4MB2NDZA7F3RAVCNFSM6AAAAABHJORXICVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJWGY4DKOBWGQ . You are receiving this because you authored the thread.Message ID: @.***>

AYahoo commented 6 months ago

https://automatednow.com/index.php?dispatch=attachments.getfile&attachment_id=1145

"The driver will fire the Keypad - Valid Password or Keypad - Invalid Password Event when a code is entered. "

Now I know it doesn't really help, just shows that it is possible.

pergolafabio commented 6 months ago

do you know if that is based on SDK or ISAPI directly to port 80 ?

pergolafabio commented 6 months ago

if you use ivms, do you see the event there?

AYahoo commented 6 months ago

Since I'm using an NVR I need to connect the PC to the internal network of the NVR, I will try tomorrow to verify.

Also from the NET_DVR_ALARM_ISAPI_INFO: ISAPI alarm information (XML/JSON message, does not include subsequent binary data); the specific alarm type needs to be obtained by parsing the eventType field of the message.

Not sure that I understand it correctly but it seems like there is more data there to be obtained, even though it is weird that it is ISPAI event.

pergolafabio commented 6 months ago

yeah, that isapi alarm is more for cameras, not intercoms

AYahoo commented 6 months ago

do you know if that is based on SDK or ISAPI directly to port 80 ?

No Idea, never had control4 system or tried it.

AYahoo commented 6 months ago

if you use ivms, do you see the event there?

https://supportusa.hikvision.com/support/solutions/articles/17000110474-pin-code-setup-for-hikvision-keypad-readers-including-ds-k170hpk-

"If PIN entered does not even show up in iVMS-4200 but card scan does, it is likely due to PIN format being accidentally toggled. Follow instructions in the sheet manual, power cycle the reader, and scan the Data Mode card once to toggle it back to 4-bit burst and try again."

from the manual it seems like maybe Hikvision is using cards and keypad as the same integration?

pergolafabio commented 6 months ago

hmm, i dont think those setting are for 8003 ? i also have an ds-kd8003 btw

AYahoo commented 6 months ago

if you use ivms, do you see the event there?

Ok, Using the IVMS I can see the event when I press the wrong key - Authentication error.

pergolafabio commented 6 months ago

Hm, strange that it doesn't create that event using the SDK :-(

AYahoo commented 6 months ago

2024-05-06 21:26:58.953 | INFO | event:isapi_alarm:131 - Isapi alarm from Gate

I think we get it an ISAPI with a payload that we need to read.

AYahoo commented 6 months ago

Screenshot 2024-05-08 185555

So as you can see in the attached file: Events type + Events Details can show if the correct code was entered or not.

pergolafabio commented 6 months ago

hmm, your previous reply seems empty about the isapi ? can you pots that again? do you always see the isapi event with unknnown key code? then its indeed worth investigating!

AYahoo commented 6 months ago

Everytime i pinch the wrong pin code, i get:

event:isapi_alarm:131 - Isapi alarm from Gate

pergolafabio commented 6 months ago

Hmm, i tried it on mine ds-kd8003, and i receive below DO you have DS-KD8003 rev a or b ? , what firmware?

2024-05-08 20:23:24.306 | DEBUG    | event:_handle_callback:220 - Callback invoked from SDK
2024-05-08 20:23:24.307 | DEBUG    | event:_invoke_handlers:192 - Invoking 2 handlers
2024-05-08 20:23:24.307 | INFO     | event:video_intercom_alarm:120 - Video intercom alarm from DS-KD8003
2024-05-08 20:23:24.308 | WARNING  | mqtt:video_intercom_alarm:364 - Received unknown alarm type: 0
[2024-05-08 20:23:24.306][INF] Alarm[0] IP[192.168.0.70] data_len[568] alarm_len[568] status[430]
[2024-05-08 20:23:54.972][DBG] Alarm chan [0] recv timeout[2]!
pergolafabio commented 6 months ago

I just pushed beta 62, added some more isapi data in debug , can you test? i have no idea what it will show...

https://github.com/pergolafabio/Hikvision-Addons/commit/13f0d6f188568676256d4491c08bb2b45429a5a2

AYahoo commented 6 months ago

Hmm, i tried it on mine ds-kd8003, and i receive below DO you have DS-KD8003 rev a or b ? , what firmware?

2024-05-08 20:23:24.306 | DEBUG    | event:_handle_callback:220 - Callback invoked from SDK
2024-05-08 20:23:24.307 | DEBUG    | event:_invoke_handlers:192 - Invoking 2 handlers
2024-05-08 20:23:24.307 | INFO     | event:video_intercom_alarm:120 - Video intercom alarm from DS-KD8003
2024-05-08 20:23:24.308 | WARNING  | mqtt:video_intercom_alarm:364 - Received unknown alarm type: 0
[2024-05-08 20:23:24.306][INF] Alarm[0] IP[192.168.0.70] data_len[568] alarm_len[568] status[430]
[2024-05-08 20:23:54.972][DBG] Alarm chan [0] recv timeout[2]!

DS-KD8003-IME1 Firmware: V2.2.45 build 210430

AYahoo commented 6 months ago

I just pushed beta 62, added some more isapi data in debug , can you test? i have no idea what it will show...

13f0d6f

Do I need to uninstall the stable version first?

pergolafabio commented 6 months ago

no need to uninstall, but just stop the addon , thats enough, then install beta addon, copy/paste the config

pergolafabio commented 6 months ago

Hmm, i tried it on mine ds-kd8003, and i receive below DO you have DS-KD8003 rev a or b ? , what firmware?

2024-05-08 20:23:24.306 | DEBUG    | event:_handle_callback:220 - Callback invoked from SDK
2024-05-08 20:23:24.307 | DEBUG    | event:_invoke_handlers:192 - Invoking 2 handlers
2024-05-08 20:23:24.307 | INFO     | event:video_intercom_alarm:120 - Video intercom alarm from DS-KD8003
2024-05-08 20:23:24.308 | WARNING  | mqtt:video_intercom_alarm:364 - Received unknown alarm type: 0
[2024-05-08 20:23:24.306][INF] Alarm[0] IP[192.168.0.70] data_len[568] alarm_len[568] status[430]
[2024-05-08 20:23:54.972][DBG] Alarm chan [0] recv timeout[2]!

DS-KD8003-IME1 Firmware: V2.2.45 build 210430

thats indeed an old firmware, i'm running : V2.2.62 build 230204 thats maybe why log is different

pergolafabio commented 6 months ago

also setup both to DEBUG::

log_level: DEBUG
sdk_log_level: DEBUG
AYahoo commented 6 months ago
2024-05-08 21:52:41.664 | DEBUG    | mqtt:isapi_alarm:277 - Isapi alarm from Gate with Alarmdata: b'0' 
2024-05-08 21:52:41.664 | INFO     | event:isapi_alarm:131 - Isapi alarm from Gate
pergolafabio commented 6 months ago

hmm , not really helpfull :-)

AYahoo commented 6 months ago
[2024-05-08 21:54:58.226][INF] Alarm[0] IP[192.168.254.99] data_len[568] alarm_len[568] status[424]
pergolafabio commented 6 months ago

thats not related

AYahoo commented 6 months ago

It show that you have some data in data, alarm & status... maybe in one of them.

pergolafabio commented 6 months ago

yea, but i have type 0 , thats also not correct, there is no "0" in the types here:

https://open.hikvision.com/hardware/definitions/NET_DVR_StartListen_V30.html

it should be a value like "0x6009", thats for ISAPI alarm , then i can extract it

WARNING | mqtt:video_intercom_alarm:364 - Received unknown alarm type: 0

pergolafabio commented 6 months ago

wait, disregard my previosu message...

as you can see, i have an unknown event coming from: i have in code all events:

https://github.com/pergolafabio/Hikvision-Addons/blob/dev/hikvision-doorbell/src/mqtt.py#L374

listed here:

https://github.com/pergolafabio/Hikvision-Addons/blob/dev/hikvision-doorbell/src/sdk/hcnetsdk.py#L131

using this from the docs:

https://open.hikvision.com/hardware/structures/NET_DVR_VIDEO_INTERCOM_ALARM.html

maybe the docs are indeed incomplete, since the "unkwown key" is not listed there...

pergolafabio commented 6 months ago

for some reason, the "illegal key" is reporting a bad event in the SDK :-(

AYahoo commented 6 months ago

I'm not getting the same error as you, I'm getting:

[2024-05-08 22:10:09.918][DBG] Alarm chan [0] recv timeout[2]!
2024-05-08 22:10:11.839 | DEBUG    | event:_handle_callback:220 - Callback invoked from SDK
2024-05-08 22:10:11.840 | DEBUG    | event:_invoke_handlers:192 - Invoking 2 handlers
2024-05-08 22:10:11.841 | DEBUG    | mqtt:isapi_alarm:277 - Isapi alarm from Gate with Alarmdata: b'@' 
2024-05-08 22:10:11.841 | INFO     | event:isapi_alarm:131 - Isapi alarm from Gate
[2024-05-08 22:10:11.838][INF] Alarm[0] IP[192.168.254.99] data_len[568] alarm_len[568] status[424]
AYahoo commented 6 months ago

According to the SDK:

Alarm type: 1-zone alarm, 2-tampering alarm, 3-duress alarm, 4-opening door by password failed for multiple times, 5-opening door failed, 6-closing door failed, 7-panic alarm), 8-intercom alarm, 9-smart lock: fingerprint duress alarm, 10-smart lock: password duress alarm, 11-smart lock: tampering alarm, 12-smart lock: locked alarm, 13-smart lock: low battery alarm, 14- blocklist alarm, 15-smart lock disconnected, 16-access control module: anti-tampering alarm, 17-video intercom started, 18-video intercom stopped.

but no type 0. Device Network SDK (Video Intercom)_Developer Guide_V6.1.7.X_20230330.pdf

pergolafabio commented 6 months ago

Yes indeed :-(

AYahoo commented 6 months ago

I'm guessing you are using Arming mode, right?

The alarm/event information from the device can be received in third-party platform or system when the alarms are triggered or event occurred. Two modes are available for receiving alarms, including arming mode and listening mode. Arming Mode The third-party platform connects to device automatically, when the alarm is triggered, the platform sends alarm uploading command to the device, and then the device will upload the alarm to the platform. Listening Mode When alarm is triggered, the device automatically uploads the alarm, and then the third-party platform receives the uploaded alarm via the configured listening host (listening address and port should be configured). This mode is applicable for multiple devices uploading alarm/event information to one third-party platform without logging in to devices, and the restart of devices will not affect the alarm/event uploading. But a device can only support the configuration of one or two listening addresses and ports.

if so:

● For the integration via device network SDK (HCNetSDK), to receive different types of alarm/event information, the parameter lCommand (data type to be uploaded) in the configured callback function should be different (refer to the typical alarm/event configurations). For the integration via text protocol, the lCommand should be set to "COMM_ISAPI_ALARM" (command No.: 0x6009) and the input parameter pAlarmInfo in the callback function MSGCallBack should be set to NET_DVR_ALARM_ISAPI_INFO .

AYahoo commented 6 months ago

Hey, It seems that you're dumping the AlarmData as string.. while it's actually a byte array.

If you could dump to the DEBUG log the AlarmData as a byte array, maybe that would be a little bit more helpful to try and figure out the Alarm type that we're looking for.

AYahoo commented 6 months ago

I've upgraded to the same firmware, and now I get that same log as you:

2024-05-09 15:37:09.585 | DEBUG    | event:_handle_callback:220 - Callback invoked from SDK
2024-05-09 15:37:09.587 | DEBUG    | event:_invoke_handlers:192 - Invoking 2 handlers
2024-05-09 15:37:09.587 | WARNING  | mqtt:video_intercom_alarm:377 - Received unknown alarm type: 0
2024-05-09 15:37:09.588 | INFO     | event:video_intercom_alarm:120 - Video intercom alarm from Gate
[2024-05-09 15:37:09.585][INF] Alarm[0] IP[192.168.254.99] data_len[568] alarm_len[568] status[430]

Try to see if you can dump the entire MQTT "video_intercom_alarm" payload. Maybe we'll succeed to figure out something about it.

pergolafabio commented 6 months ago

Correct, it's in arming mode, and e are indeed using the lCommamd...

I have a look later if I can dump more data...

That info, did you download the SDK tool? There is a client demo inside, also an alarm event demo, have you tried running it to see if you have the keypad event?

AYahoo commented 6 months ago

Yes i did, but i think it is too old, it uses login_v30 and I'm unable to listen to the alarms with it

On Fri, May 10, 2024, 08:42 Pergola Fabio @.***> wrote:

Correct, it's in arming mode, and e are indeed using the lCommamd...

I have a look later if I can dump more data...

That info, did you download the SDK tool? There is a client demo inside, also an alarm event demo, have you tried running it to see if you have the keypad event?

— Reply to this email directly, view it on GitHub https://github.com/pergolafabio/Hikvision-Addons/issues/204#issuecomment-2103908747, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPRV3XDNTAUB4ISVPDPYSTZBRM35AVCNFSM6AAAAABHJORXICVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBTHEYDQNZUG4 . You are receiving this because you authored the thread.Message ID: @.***>

pergolafabio commented 6 months ago

The SDK in this addon is also older then listed on the Hikvision site, maybe worth testing with a newer version indeed

pergolafabio commented 6 months ago

If you want, fork my dev repo, replace this folder and all contents below with a newer one downloaded from Hikvision, and build/run the docker image...

https://github.com/pergolafabio/Hikvision-Addons/tree/dev/hikvision-doorbell/lib-amd64

pergolafabio commented 6 months ago

were you able to test the new sdk ?

AYahoo commented 6 months ago

Sadly no, I don't know how to...

On Tue, May 14, 2024, 19:58 Pergola Fabio @.***> wrote:

were you able to test the new sdk ?

— Reply to this email directly, view it on GitHub https://github.com/pergolafabio/Hikvision-Addons/issues/204#issuecomment-2110706995, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPRV3W74WNAVAOHDPTM6ADZCI7C7AVCNFSM6AAAAABHJORXICVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJQG4YDMOJZGU . You are receiving this because you authored the thread.Message ID: @.***>

pergolafabio commented 6 months ago

Are you familiar with docker and building images?

AYahoo commented 6 months ago

Yeah sure, but I'm not running my HA as a docker.

On Tue, May 14, 2024, 21:24 Pergola Fabio @.***> wrote:

Are you familiar with docker and building images?

— Reply to this email directly, view it on GitHub https://github.com/pergolafabio/Hikvision-Addons/issues/204#issuecomment-2110851783, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPRV3VZXAQST2SE35JL3WDZCJJGLAVCNFSM6AAAAABHJORXICVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJQHA2TCNZYGM . You are receiving this because you authored the thread.Message ID: @.***>

pergolafabio commented 6 months ago

you dont need to... just stop the addon you can build a docker image and run it, its explained here:

https://github.com/pergolafabio/Hikvision-Addons/blob/main/docs/docker.md#manually-building-and-running-the-container

so you you can git clone my code, make sure to download the "dev" branch, the code is there:

https://github.com/pergolafabio/Hikvision-Addons/tree/dev/hikvision-doorbell

there is an SDK folder in here: https://github.com/pergolafabio/Hikvision-Addons/tree/dev/hikvision-doorbell/lib-amd64

download this one, seems pretty recent: https://www.hikvision.com/europe/support/tools/hitools/clf4633a00e385d6ea/ extract it, there is a folder in there: \EN-HCNetSDKV6.1.9.48_build20230410_linux64\lib

replace those with my files from the addon, build and run the docker make sure to enable debug, so you can see if the new sdk version is running