DS-KD8003 - DS-KV8113 - DS-KV8213 - DS-KV6113 - DS-KV8413 and .... integration Hikvision HikConnect Video intercom doorbell

ah, what do you see in it? it should be a continous loop of data?
see first post, i created an example to make a sensor based on that stream

edit , look here :

yes i am running hassos in a rpi, and im using the 64 bits version… but the error specifically says “No such file”… couldn’t this be a permissions problem? or even a path issue, is lib really on the root (it starts with /lib)

try accessing the docker? from putty? check the path?
then just edit inside the docker the .py file where i specify the /lib path
for me it works… maybe you need to specify it as maybe like /home/…

normally with “pwd” command you can see the path

dont think its permission, lib should be enough to have read only, i never touched permissions

I tried to set this up but I having a difficult understanding the steps. Please can you help me step by step? I think the best would probably even be a screen recording of the steps posted to youtube or something.

ok, np

but first of all, whats the output if you fire this command in terminal? because i dont think it will work on other models besides ds-kd8003
offcourse, change the IP , it needs to be set to the outdoor station, and also change xxx to your password

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

HTTP/1.1 401 Unauthorized
Date: Thu, 18 Nov 2021 14:00:00 GMT
Server: webs
Content-Length: 235
Connection: close
X-Frame-Options: SAMEORIGIN
Cache-Control: no-store
Pragma: no-cache
WWW-Authenticate: Digest qop="auth", realm="DS-4090FC70", nonce="OTI0YWI3ZGFkZmNlNWQyMTRhMWEzMGM0ZjA2MDJmMGY=", stale="false", opaque="", domain="::"
Content-Type: application/xml

HTTP/1.1 200 OK
Date: Thu, 18 Nov 2021 14:00:00 GMT
Server: webs
Content-Length: 40
Connection: close
X-Frame-Options: SAMEORIGIN
Cache-Control: no-store
Pragma: no-cache
Content-Type: application/xml

<?xml version="1.0" encoding="UTF-8"?>
➜  ~


thats no good, alertstream doesnt work on your model
you can only use the callstatus for ISAPI
if you want also events for door opening, the only option left is the SDK script

I have the SDK running in windows - not sure how to go about integrating it into HA next - id like to receive doorbell presses, and if a keycard is swiped, to send a separate alert.

I get this ISAPI in putty:

➜  ~ curl --digest -u admin:*********** http://192.168.1.61/ISAPI/VideoIntercom/capabilities
<?xml version="1.0" encoding="UTF-8"?>
<VideoIntercomCap version="2.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
<isSupportDeviceId>true</isSupportDeviceId>
<isSupportOperationTime>true</isSupportOperationTime>
<isSupportRemoteOpenDoor>true</isSupportRemoteOpenDoor>
<isSupportKeyCfg>true</isSupportKeyCfg>
<isSupportAlarmUploadCfg>true</isSupportAlarmUploadCfg>
<isSupportSendCardCfg>true</isSupportSendCardCfg>
<isSupportDeviceLanguageCfg>true</isSupportDeviceLanguageCfg>
<isSupportIssueCards>true</isSupportIssueCards>
<isSupportAlarmControlByPhone>false</isSupportAlarmControlByPhone>
<isSupportWorkStatus>true</isSupportWorkStatus>
<isSupportSystemSwitchCfg>true</isSupportSystemSwitchCfg>
<isSupportRingBackTone>true</isSupportRingBackTone>
<isSupportPhoneCfg>true</isSupportPhoneCfg>
<isSupportElevatorControlCfg>true</isSupportElevatorControlCfg>
<isSupportSecurityMode>true</isSupportSecurityMode>
<isSupportDeviceCommunication>true</isSupportDeviceCommunication>
<isSupportKeyCfgPlanTemplate>true</isSupportKeyCfgPlanTemplate>
</VideoIntercomCap>

Isapi works only in your case for callstatus and remote open door… For swipe and keycode event you need SDK or also an custom firmware…

So in your case , use SDK, then you have everything ,easiest way

The part when I cannot seem to integrate is taking the SDK events and pushing them to a restful sensor in HA.

I keep getting an an error: “send failed to sensor”

Did you setup a bearer token? Do you run local on http? Did you setup the template sensor?

@pergola.fabio nice work on this.
what is the easiest way to see in HA that somone swiped a correct mifare card on my 6113?

the only way is the SDK, i have posted the add-on created a few pages back

ok thx, how do i get the Bearer token?

By creating a long lived token in HA

I maded a Bearer token en put it in the config, but is it normal that i only see this sensor?

I found it changed the localhost to my external dns name and it was unreachable :stuck_out_tongue:

Yes, that’s normal, only on event it will be updated… If you defined the correct bearer token and IP and http url

Hi,

I have this inside my windows SDK hik.py file:

from hcnetsdk import HCNetSDK, NET_DVR_DEVICEINFO_V30, NET_DVR_DEVICEINFO_V30, NET_DVR_SETUPALARM_PARAM, fMessageCallBack, COMM_ALARM_V30, COMM_ALARM_VIDEO_INTERCOM, NET_DVR_VIDEO_INTERCOM_ALARM, NET_DVR_ALARMINFO_V30, ALARMINFO_V30_ALARMTYPE_MOTION_DETECTION, VIDEO_INTERCOM_ALARM_ALARMTYPE_DOORBELL_RINGING, VIDEO_INTERCOM_ALARM_ALARMTYPE_DISMISS_INCOMING_CALL, VIDEO_INTERCOM_ALARM_ALARMTYPE_TAMPERING_ALARM, VIDEO_INTERCOM_ALARM_ALARMTYPE_DOOR_NOT_CLOSED, COMM_UPLOAD_VIDEO_INTERCOM_EVENT, NET_DVR_VIDEO_INTERCOM_EVENT, VIDEO_INTERCOM_EVENT_EVENTTYPE_UNLOCK_LOG, VIDEO_INTERCOM_EVENT_EVENTTYPE_ILLEGAL_CARD_SWIPING_EVENT, NET_DVR_UNLOCK_RECORD_INFO
from ctypes import POINTER, cast, c_char_p, c_byte

def callback(command: int, alarmer_pointer, alarminfo_pointer, buffer_length, user_pointer):
    if (command == COMM_ALARM_V30):
        alarminfo_alarm_v30: NET_DVR_ALARMINFO_V30 = cast(
            alarminfo_pointer, POINTER(NET_DVR_ALARMINFO_V30)).contents
        if (alarminfo_alarm_v30.dwAlarmType == ALARMINFO_V30_ALARMTYPE_MOTION_DETECTION):
            print(f"Motion detected")
        else:
            print(
                f"COMM_ALARM_V30, unhandled dwAlarmType: {alarminfo_alarm_v30.dwAlarmType}")
    elif(command == COMM_ALARM_VIDEO_INTERCOM):
        alarminfo_alarm_video_intercom: NET_DVR_VIDEO_INTERCOM_ALARM = cast(
            alarminfo_pointer, POINTER(NET_DVR_VIDEO_INTERCOM_ALARM)).contents        
        if (alarminfo_alarm_video_intercom.byAlarmType == VIDEO_INTERCOM_ALARM_ALARMTYPE_DOORBELL_RINGING):
            print("Doorbell ringing")
            # Doorbell ringing sensor
            try:
                print("Sensor Callstatus updating...")
                set_attribute(sensor_name, "Callstatus", "On")
                time.sleep(1)
                set_attribute(sensor_name, "Callstatus", "Off")
            except:
                print("Sensor updating failed")
        elif (alarminfo_alarm_video_intercom.byAlarmType == VIDEO_INTERCOM_ALARM_ALARMTYPE_DISMISS_INCOMING_CALL):
            print("Call dismissed")
        elif (alarminfo_alarm_video_intercom.byAlarmType == VIDEO_INTERCOM_ALARM_ALARMTYPE_TAMPERING_ALARM):
            print("Tampering alarm")
        elif (alarminfo_alarm_video_intercom.byAlarmType == VIDEO_INTERCOM_ALARM_ALARMTYPE_DOOR_NOT_CLOSED):
            print("Door not closed")
        else:
            print(
                f"COMM_ALARM_VIDEO_INTERCOM, unhandled byAlarmType: {alarminfo_alarm_video_intercom.byAlarmType}")
    elif(command == COMM_UPLOAD_VIDEO_INTERCOM_EVENT):
        alarminfo_upload_video_intercom_event: NET_DVR_VIDEO_INTERCOM_EVENT = cast(
            alarminfo_pointer, POINTER(NET_DVR_VIDEO_INTERCOM_EVENT)).contents
        if (alarminfo_upload_video_intercom_event.byEventType == VIDEO_INTERCOM_EVENT_EVENTTYPE_UNLOCK_LOG):
            print(f"Unlocked by: {list(alarminfo_upload_video_intercom_event.uEventInfo.struUnlockRecord.byControlSrc)}")
            # Door open sensor
            try:
                print("Sensor Door updating...")
                set_attribute(sensor_name, "Door", "On")
                time.sleep(1)
                set_attribute(sensor_name, "Door", "Off")
            except:
                print("Sensor updating failed")
        elif (alarminfo_upload_video_intercom_event.byEventType == VIDEO_INTERCOM_EVENT_EVENTTYPE_ILLEGAL_CARD_SWIPING_EVENT):
            print(f"Illegal card swiping")
        else:
            print(
                f"COMM_ALARM_VIDEO_INTERCOM, unhandled byEventType: {alarminfo_upload_video_intercom_event.byEventType}")
    else:
        print(f"Unhandled command: {command}")

def set_attribute(sensor_name, attribute, value):
    response = requests.get(url_states + sensor_name, headers=headers)
    msg = json.loads(response.text)
    msg['attributes'][attribute] = value
    payload = json.dumps({'state':  msg['state'], 'attributes': msg['attributes']})
    requests.post(url_states + sensor_name, headers=headers, data=payload)


HCNetSDK.NET_DVR_Init()
HCNetSDK.NET_DVR_SetValidIP(0, True)

device_info = NET_DVR_DEVICEINFO_V30()

user_id = HCNetSDK.NET_DVR_Login_V30("192.168.1.61".encode('utf-8'), 8000, "admin".encode('utf-8'),
                                     "**********".encode('utf-8'), device_info)

if (user_id < 0):
    print(
        f"NET_DVR_Login_V30 failed, error code = {HCNetSDK.NET_DVR_GetLastError()}")
    HCNetSDK.NET_DVR_Cleanup()
    exit(1)

alarm_param = NET_DVR_SETUPALARM_PARAM()
alarm_param.dwSize = 20
alarm_param.byLevel = 1
alarm_param.byAlarmInfoType = 1
alarm_param.byFaceAlarmDetection = 1

alarm_handle = HCNetSDK.NET_DVR_SetupAlarmChan_V41(user_id, alarm_param)

if (alarm_handle < 0):
    print(
        f"NET_DVR_SetupAlarmChan_V41 failed, error code = {HCNetSDK.NET_DVR_GetLastError()}")
    HCNetSDK.NET_DVR_Logout_V30(user_id)
    HCNetSDK.NET_DVR_Cleanup()
    exit(2)

# Change HA Variables sensor name + bearer
url_states = "http://192.168.1.39:8123/api/states/"
sensor_name = "sensor.Doorbell_Status"
headers = {
    'Authorization': 'BEARER ********',
    'content-type': 'application/json',
}

message_callback = fMessageCallBack(callback)
HCNetSDK.NET_DVR_SetDVRMessageCallBack_V50(0, message_callback, user_id)

input("Press Enter to exit...\n")

HCNetSDK.NET_DVR_CloseAlarmChan_V30(alarm_handle)
HCNetSDK.NET_DVR_Logout_V30(user_id)
HCNetSDK.NET_DVR_Cleanup()

I also have this sensor in my sensor.yaml:

- platform: rest
  name: Doorbell Status
  authentication: digest
  username: admin
  password: ******
  scan_interval: 1
  resource: http://192.168.1.61/ISAPI/VideoIntercom/callStatus?format=json
  value_template: "{{ value_json.CallStatus.status }}"

Is this sensor the right configuration? the hik.py is running on a different machine, but within the same LAN as the Hassio. Do I need to add additional items to Hassio? or change lines in the hik.py? it seems to running well in putty, grabbing all commands and events from the door and even hikconnect initiated commands.

Below is a screenshot of my putty output from hik.py (SDK)