pergolafabio / Hikvision-Addons

Home Assistant: Hikvision Doorbell
178 stars 40 forks source link

DS-K1T502DBFWX-C - Not supported #177

Open seederp2p opened 8 months ago

seederp2p commented 8 months ago

What happened?

I'm trying to add my DS-K1T502DBFWX-C without success.

Add-on

Hikvision Doorbell

What version of the add-on are you running?

3.0.12

Installation type

Home Assistant add-on

Relevant log output

2024-01-05 18:59:28.255 | DEBUG    | config:load_mqtt_config:129 - Loading MQTT configuration from supervisor
2024-01-05 18:59:28.255 | DEBUG    | config:mqtt_config_from_supervisor:36 - Requesting MQTT service configuration to supervisor
2024-01-05 18:59:28.273 | INFO     | sdk.utils:loadSDK:44 - Using OS: Linux with architecture: x86_64
loop[2] find 2 mac and 0 ip
Traceback (most recent call last):
  File "/app/main.py", line 96, in <module>
    asyncio.run(main())
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/app/main.py", line 47, in main
    doorbell.authenticate()
  File "/app/doorbell.py", line 71, in authenticate
    self._type = DeviceType(self._device_info.wDevType)
  File "/usr/local/lib/python3.10/enum.py", line 385, in __call__
    return cls.__new__(cls, value)
  File "/usr/local/lib/python3.10/enum.py", line 710, in __new__
    raise ve_exc
ValueError: 884 is not a valid DeviceType

Relevant configuration

No response

Anything else?

No response

pergolafabio commented 8 months ago

Ok , np , will add it on next release

seederp2p commented 8 months ago

Ok , np , will add it on next release

When do you think it will be released?

Is there something I can do to test it while you don't officialy release the new version?

Thank you so much!

pergolafabio commented 8 months ago

No, I need to add that identifier first

seederp2p commented 8 months ago

No, I need to add that identifier first

Got it.

If you need any info from my side I'm here to help.

When do you think you can add support to this device ID?

pergolafabio commented 8 months ago

This weekend probably

seederp2p commented 8 months ago

This weekend probably

Wow, nice :)

Thank you!

pergolafabio commented 8 months ago

i just updated the beta addon, with version 52 , can you try it? make sure to refresh/update addons, so 52 is visible

seederp2p commented 8 months ago

i just updated the beta addon, with version 52 , can you try it? make sure to refresh/update addons, so 52 is visible

I'm getting this:

2024-01-06 17:14:12.749 | DEBUG | config:load_mqtt_config:129 - Loading MQTT configuration from supervisor 2024-01-06 17:14:12.749 | DEBUG | config:mqtt_config_from_supervisor:36 - Requesting MQTT service configuration to supervisor 2024-01-06 17:14:12.779 | INFO | sdk.utils:loadSDK:44 - Using OS: Linux with architecture: x86_64 loop[2] find 2 mac and 0 ip 2024-01-06 17:14:13.166 | INFO | doorbell:authenticate:79 - Connected to doorbell: Porta_Armazem 2024-01-06 17:14:13.166 | INFO | event:init:87 - Setting up event handler: Console stdout 2024-01-06 17:14:13.168 | INFO | mqtt:init:95 - Setting up event handler: MQTT 2024-01-06 17:14:13.343 | ERROR | main::101 - Error while listening to events in Porta_Armazem: Device does not support this function. Error code:23

seederp2p commented 8 months ago

Debug enabled:

[2024-01-06 17:32:50.696][INF] Private connect 172.16.127.211:8000 sock=139 this=0x861775f4 cmd=0x117000 port=51662 [2024-01-06 17:32:50.698][DBG] SimpleSTDCommandToDvr with out cmd[GET /ISAPI/System/deviceInfo], input size[0], max segment length[262144] 2024-01-06 17:32:50.758 | DEBUG | event:start:255 - Registering callback function using SDK 2024-01-06 17:32:50.763 | DEBUG | doorbell:setup_alarm:90 - Arming the device via SDK [2024-01-06 17:32:50.766][INF] Private connect 172.16.127.211:8000 sock=163 this=0x861775f4 cmd=0x111021 port=51674 2024-01-06 17:32:50.768 | ERROR | main::101 - Error while listening to events in Porta_Armazem: Device does not support this function. Error code:23 [2024-01-06 17:32:50.768][ERR] Index[0] cmd[111021] SendCommandWithRecv failed[23] [2024-01-06 17:32:50.768][ERR] CMemberMgrBase::AllocIndex2, MemberStart Failed, iIndex[0]

pergolafabio commented 8 months ago

Hmm that's not good, I don't think your device supports the SDK... Are you using an NVR?

seederp2p commented 8 months ago

Owner

Hi!

No. I just use this as a standalone doorbell with videocom ;)

pergolafabio commented 8 months ago

Hmm, not sure if I can do anything about it, seems your device doesnt support SDK for listening on events :-(

Maybe you can use some Isapi commands instead?

Is it a new device?

seederp2p commented 8 months ago

Hmm, not sure if I can do anything about it, seems your device doesnt support SDK for listening on events :-(

Maybe you can use some Isapi commands instead?

Is it a new device?

Yes. This was released 1 year ago and it's supposed to be a high end terminal.

Is there anything I can do on my side so you can make sure that it doesn't support SDK?

pergolafabio commented 8 months ago

Hm on hikvision site, you can download the SDK files, there are also some client test tools inside, can you try them? Especially the one for events

seederp2p commented 8 months ago

Hm on hikvision site, you can download the SDK files, there are also some client test tools inside, can you try them? Especially the one for events

Can you please give me some basic guidance about the steps I have to follow?

Thank you

pergolafabio commented 8 months ago

Hi, here are the SDK test tools, you can download it for windows and linux

https://www.hikvision.com/europe/support/tools/hitools/?type=IP

extract the zip, and there are some tools / client demo included

seederp2p commented 8 months ago

Hi, here are the SDK test tools, you can download it for windows and linux

https://www.hikvision.com/europe/support/tools/hitools/?type=IP

extract the zip, and there are some tools / client demo included

Ok so I tried to run the C# demo\5-GettingDeviceCapabilities\CapabilityCSharpDemo\bin\ClientDemoEn.exe and it gathers some data. I don't find any specific binary for events...

pergolafabio commented 8 months ago

I believe its this one, but never tried myself

C# demo\4-Alarm(Arm&Listen)\4-Alarm(Arm&Listen)\AlarmCSharpDemo

but if you add your device, can you see the video stream for example?

seederp2p commented 8 months ago

I believe its this one, but never tried myself

C# demo\4-Alarm(Arm&Listen)\4-Alarm(Arm&Listen)\AlarmCSharpDemo

but if you add your device, can you see the video stream for example?

I confirm that I can see the video stream.

I found the path you were refering to:

image

image

image

image

image

pergolafabio commented 8 months ago

what you can do, download the dev branch:

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

copy paste the hikvision-doorbell folder in your "addons" share on your HA download the SDK zip package, but the linux64 edition, extract it there should be a "lib" folder Remove all content from the lib-amd64 folder, and replace it with the new lib, make sure folder structure is the same Then goto HA, do a refresh for your addons, then a local addon should popup in your store , then install it... Then you have the addon, with the new SDK version, not sure if it works, but worth a try

pergolafabio commented 8 months ago

you have also ivms right? Do you see this? the arming/disarming function? this is used for getting events:

image

pergolafabio commented 8 months ago

But i think you are out of luck, i see you also have error 23 in the client demo tool for the alarm functions

seederp2p commented 8 months ago

But i think you are out of luck, i see you also have error 23 in the client demo tool for the alarm functions

I get it. I can try to contact hikvision to get this in future firmware versions. Can you help me formulating a proper request? :)

pergolafabio commented 8 months ago

hmm, i already know the answer, it will get cancelled anwyay, i was told that they are going to stop using SDK, they want all devices with more ISAPI support instead...

seederp2p commented 8 months ago

hmm, i already know the answer, it will get cancelled anwyay, i was told that they are going to stop using SDK, they want all devices with more ISAPI support instead...

Ok. :(

Do you know if is it possible via IS API to get a status o someone fingerprint authentication? Even if I have to pool this very often. My goal was to take an action whenever someone correctly authenticates on the doorbell... In this case via fingerprint...

pergolafabio commented 8 months ago

Hmm, never looked for those, but i shared all isapi docs on community thread, you can have a look at the person based access control document maybe

https://www.dropbox.com/s/obppstvpvxja9l7/isapi.zip?dl=0

also try this command in putty, maybe your devices supports the alertstream?

curl -i --digest -u admin:XXXXXXX http://192.168.0.70/ISAPI/Event/notification/alertStream

seederp2p commented 8 months ago

Hmm, never looked for those, but i shared all isapi docs on community thread, you can have a look at the person based access control document maybe

https://www.dropbox.com/s/obppstvpvxja9l7/isapi.zip?dl=0

also try this command in putty, maybe your devices supports the alertstream?

curl -i --digest -u admin:XXXXXXX http://192.168.0.70/ISAPI/Event/notification/alertStream

I found that I can get the latest fingerprint and door close (that happens 5 seconds after each success finger print via):

curl --location --globoff --digest -u 'admin:mypass' 'http://x.x.x.x/ISAPI/AccessControl/AcsEvent?format=json' --data '{ "AcsEventCond": { "searchID": "1", "searchResultPosition": 0, "maxResults": 1, "timeReverseOrder": true, "major": 5, "minor": 38 } }'

and:

curl --location --globoff --digest -u 'admin:mypass!!' 'http://x.x.x.x/ISAPI/AccessControl/AcsEvent?format=json' \ --data '{ "AcsEventCond": { "searchID": "1", "searchResultPosition": 0, "maxResults": 1, "timeReverseOrder": true, "major": 5, "minor": 22 } }'

The output for fingerprint success is something like:

{ "AcsEvent": { "searchID": "1", "responseStatusStrg": "MORE", "numOfMatches": 1, "totalMatches": 114, "InfoList": [{ "major": 5, "minor": 38, "time": "2024-01-09T16:51:51-00:00", "netUser": "", "cardType": 1, "name": "whatever", "cardReaderNo": 1, "doorNo": 1, "employeeNoString": "20", "type": 0, "serialNo": 1455, "userType": "normal", "currentVerifyMode": "fp" }] }

and for door close:

{ "AcsEvent": { "searchID": "1", "responseStatusStrg": "MORE", "numOfMatches": 1, "totalMatches": 284, "InfoList": [{ "major": 5, "minor": 22, "time": "2024-01-09T16:51:56-00:00", "netUser": "", "doorNo": 1, "type": 0, "serialNo": 1457, "currentVerifyMode": "faceOrFpOrCardOrPw" }] } }

My idea was to create 2 sensors in HA that could store the "time" value of each event (Success FingerPrint and Door Close).

After that I would create another sensor like "Auth Status" that would store the LATEST event based on the other 2 sensors. That way I could fire actions based on this last sensor change of status.

But I'm not sure if this is possible...

pergolafabio commented 8 months ago

Yeah, that should be possible, that are command line or rest sensors for that, and with automation you should be able to check the dates.....

Good find! Did you saw those commands in the Isapi zip ?

pergolafabio commented 8 months ago

Doesnt the alarm stream command work for you? That should give some live data... On mine device it doesn't work, but it works mostly for hikvision cameras for motions etc...

seederp2p commented 8 months ago

Yeah, that should be possible, that are command line or rest sensors for that, and with automation you should be able to check the dates.....

Good find! Did you saw those commands in the Isapi zip ?

I found it searching the wiki: https://tpp.hikvision.com/Wiki/ISAPI

pergolafabio commented 8 months ago

Ahh you have an account there?

seederp2p commented 8 months ago

Ahh you have an account there?

Nop. I think it's public...

seederp2p commented 8 months ago

Hmm, never looked for those, but i shared all isapi docs on community thread, you can have a look at the person based access control document maybe https://www.dropbox.com/s/obppstvpvxja9l7/isapi.zip?dl=0 also try this command in putty, maybe your devices supports the alertstream? curl -i --digest -u admin:XXXXXXX http://192.168.0.70/ISAPI/Event/notification/alertStream

I found that I can get the latest fingerprint and door close (that happens 5 seconds after each success finger print via):

curl --location --globoff --digest -u 'admin:mypass' 'http://x.x.x.x/ISAPI/AccessControl/AcsEvent?format=json' --data '{ "AcsEventCond": { "searchID": "1", "searchResultPosition": 0, "maxResults": 1, "timeReverseOrder": true, "major": 5, "minor": 38 } }'

and:

curl --location --globoff --digest -u 'admin:mypass!!' 'http://x.x.x.x/ISAPI/AccessControl/AcsEvent?format=json' \ --data '{ "AcsEventCond": { "searchID": "1", "searchResultPosition": 0, "maxResults": 1, "timeReverseOrder": true, "major": 5, "minor": 22 } }'

The output for fingerprint success is something like:

{ "AcsEvent": { "searchID": "1", "responseStatusStrg": "MORE", "numOfMatches": 1, "totalMatches": 114, "InfoList": [{ "major": 5, "minor": 38, "time": "2024-01-09T16:51:51-00:00", "netUser": "", "cardType": 1, "name": "whatever", "cardReaderNo": 1, "doorNo": 1, "employeeNoString": "20", "type": 0, "serialNo": 1455, "userType": "normal", "currentVerifyMode": "fp" }] }

and for door close:

{ "AcsEvent": { "searchID": "1", "responseStatusStrg": "MORE", "numOfMatches": 1, "totalMatches": 284, "InfoList": [{ "major": 5, "minor": 22, "time": "2024-01-09T16:51:56-00:00", "netUser": "", "doorNo": 1, "type": 0, "serialNo": 1457, "currentVerifyMode": "faceOrFpOrCardOrPw" }] } }

My idea was to create 2 sensors in HA that could store the "time" value of each event (Success FingerPrint and Door Close).

After that I would create another sensor like "Auth Status" that would store the LATEST event based on the other 2 sensors. That way I could fire actions based on this last sensor change of status.

But I'm not sure if this is possible...

about "alertstream" I got this after the curl:

{ "AcsEvent": { "searchID": "1", "responseStatusStrg": "MORE", "numOfMatches": 1, "totalMatches": 111, "InfoList": [ { "major": 5, "minor": 38, "time": "2024-01-09T14:13:32-00:00", "netUser": "", "cardType": 1, "name": "Person Name", "cardReaderNo": 1, "doorNo": 1, "employeeNoString": "20", "type": 0, "serialNo": 1443, "userType": "normal", "currentVerifyMode": "fp" } ] } }

pergolafabio commented 8 months ago

I think the Alertstream is a continuous command, the curl command is still active and providing data right?

seederp2p commented 8 months ago

I think the Alertstream is a continuous command, the curl command is still active and providing data right?

No it's not... it doesn't remain active :(

pergolafabio commented 8 months ago

I know the hikvision integration for HA makes use of pyHik ... pyHik uses the alertstream Isapi command for getting events... Maybe you can have a look there to grab events and make your own script?

seederp2p commented 8 months ago

about my first idea I tried this sensor:

and got this:

image

But after some time I've "none"... maybe HA gets blacklisted due to requests all the seconds... I dont know

pergolafabio commented 8 months ago

yeah, i think the payload of 1 sec is way to fast, maybe make it more like 4-5 sec

pergolafabio commented 8 months ago

scan interval i mean

seederp2p commented 8 months ago

scan interval i mean

change to 5 and after some time I get "none"

pergolafabio commented 8 months ago

and if you do the curl?

seederp2p commented 8 months ago

and if you do the curl?

I can spam the curl command and I always get the output...

pergolafabio commented 8 months ago

hmm, strange try the command line sensor instear of the rest sensor? then you can use the curl too

seederp2p commented 8 months ago

hmm, strange try the command line sensor instear of the rest sensor? then you can use the curl too

I think it would be better to check the debug of rest sensor, tried to enable debug but it seems that won't show the actual reply... :\

pergolafabio commented 8 months ago

Yeah, I know that there were issues in the ha core with the digest authentication, there are issues created for it..

seederp2p commented 8 months ago

Yeah, I know that there were issues in the ha core with the digest authentication, there are issues created for it..

Well I just tried to remove the If condition from my sensor. I get this log on HA:

Template variable error: 'dict object' has no attribute 'AcsEvent' when rendering '{{ value_json.AcsEvent.InfoList[0].time }}'

So it looks like that maybe HA gets a response withour AcsEvent

pergolafabio commented 8 months ago

or no response at all, strange that the curl always works?

seederp2p commented 8 months ago

or no response at all, strange that the curl always works?

I'm side testing on a ubuntu server machine via command line and it always work...

seederp2p commented 8 months ago

Well I just went all the way arround.

Since I've an internal webserver always on, I created a PHP script to generate a json output after comparing both FP auth and Door close Dates.

<?php
// Função para obter os eventos com base nos parâmetros fornecidos usando cURL com autenticação Digest
function getEvent($minor) {
    $url = 'http://yo.ur.i.p/ISAPI/AccessControl/AcsEvent?format=json';
    $data = array(
        "AcsEventCond" => array(
            "searchID" => "1",
            "searchResultPosition" => 0,
            "maxResults" => 1,
            "timeReverseOrder" => true,
            "major" => 5,
            "minor" => $minor
        )
    );

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
    curl_setopt($ch, CURLOPT_USERPWD, 'admin:YOURPASSWORD');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

    $response = curl_exec($ch);
    if ($response === false) {
        echo json_encode(array("error" => 'Erro ao fazer a requisição: ' . curl_error($ch)));
        return null;
    }

    curl_close($ch);
    return json_decode($response, true);
}

// Obter eventos para minor 38 (Autenticação Digital) e minor 22 (Fecho de Porta)
$event_38 = getEvent(38);
$event_22 = getEvent(22);

if (!$event_38 || !$event_22) {
    echo json_encode(array("error" => "Não foi possível obter os eventos."));
    exit();
}

// Extrair os tempos dos eventos
$time_38 = $event_38['AcsEvent']['InfoList'][0]['time'];
$time_22 = $event_22['AcsEvent']['InfoList'][0]['time'];

// Comparar os tempos para determinar o evento mais recente
if ($time_38 > $time_22) {
    echo json_encode(array("ultimo_evento" => "Autenticacao Digital"));
} elseif ($time_38 < $time_22) {
    echo json_encode(array("ultimo_evento" => "Fecho de Porta"));
} else {
    echo json_encode(array("ultimo_evento" => "Outro"));
}
?>

after that I created a sensor in HA that pools every second:

- platform: rest
  name: Estado_Porta
  resource: http://your.web.server.ip/HA/whatever.php
  value_template: '{{ value_json.ultimo_evento }}'
  scan_interval: 1 

And now I've a working sensor that has the last event between Fingerprint Auth and Door close :)

pergolafabio commented 8 months ago

nice :-) i hope the script doesnt hammer your device with that 1 sec, i hope it keeps stable