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

hey, i tried the C++ code, there is a sample file in the downloaded SDK package (consoledemo)
if you start that in terminal, option 3 is to get the alert events

i just added some print commandos to actually see the commands and types, they were wrong too

Guys, integrating the Alertstream in a sensor, is not possible, since its an endless file, so polling it is a nogo

i developed a python script, change offcourse the variables , like username/pass/ip/bearer token

i fire the script with an automation upon start event on Home Assistant

automation:

- alias: Hikvision Door Sensor
  initial_state: 'on'
  trigger:
    - platform: homeassistant
      event: start
  action:
    - service: shell_command.hikvision_stream_sensor

shell command: (the nohup below, makes the script fire in background

hikvision_stream_sensor: nohup python3 /config/python_scripts/hikvision_stream.py $1 > /dev/null 2>&1 &

script:

from requests.auth import HTTPDigestAuth
from datetime import datetime
import requests
import time
import json
#Variables
username = "admin"
password = "XXX"
url = "http://YOUR_IP/ISAPI/Event/notification/alertStream"
headers = {
    'Authorization': 'Bearer ¨XXXXX',
    'content-type': 'application/json',
}
url_states = "http://localhost:8123/api/states/"
sensor_name = "sensor.hikvision_door"

#Creating Sensor
try:
    timestamp = str(datetime.now())
    data = json.dumps({'state': 'off', 'attributes': {'Time': timestamp}})
    response = requests.post(url_states + sensor_name, headers=headers, data=data)
    print("Creating Sensor on start script")
except:
    print("Creating Sensor Failed")


while True:
    try:
        stream = requests.get(url, stream=True, auth=HTTPDigestAuth(username, password))
        print("Status code: " , stream.status_code)
        for line in stream.iter_lines(chunk_size=1):
            str_line = line.decode("utf-8", "ignore")
            print(str_line)
            #Check for event
            if str_line.find('"subEventType":	25') != -1:
                result = str_line.find('eventState')
                print("Found event!")
                try:
                    timestamp = str(datetime.now())
                    data = json.dumps({'state': 'on', 'attributes': {'Time': timestamp}})
                    response = requests.post(url_states + sensor_name, headers=headers, data=data)
                    print("Door Open")
                    #put the sensor "on" for 5 seconds
                    time.sleep(5)
                    timestamp = str(datetime.now())
                    data = json.dumps({'state': 'off', 'attributes': {'Time': timestamp}})
                    response = requests.post(url_states + sensor_name, headers=headers, data=data)                    
                    print("Door Closed")
                    continue
                except:
                    print("Updating sensor failed")
                    continue
        if stream.status_code == 401 or stream.status_code == 403:
            time.sleep(5) 
    except (ValueError,requests.exceptions.ConnectionError,requests.exceptions.ChunkedEncodingError) as err:
        print("Connection Failed")
        continue

Is it possible to get which room was called / which button was pressed on the outdoor station? There is not such property on the callStatus response body, but maybe there’s some chance on the alert stream?

Hmm, no the Alertstream doesn’t provide callstatus, maybe it’s possible with the SDK , SDK also provides info who opened the door

Hopefully someone can help me here.

I’ve got the DS-KD8003-IME1 running custom firmware V2.2.45 build 210721

I factory reset the device by going into iVMS, then system maintenance, and hit “restore all”.

Added back to the indoor station, reconnected, all working, implemented the rest sensor… except call status doesn’t change from “idle”.

What am I doing wrong? Did I do the correct factory reset?

Are you using the correct ISAPI url? I added one in first post… The callstatus url from 8003 is different then the others
The one in the rest sensor example is for other models, you need to change it to the one for 8003
Mine polling is setup to 3 , more then fast enough

Ah you’re right, I will change then test. Thanks!

That means HikVision support team should provide a working SDK with working C++ sample code.

yeah, i have a ticket open with Hikvision, i sended you a PM

btw, do you also want to work with the ISAPI ? would be nice to have this as an offcial integration into HA
you are a developer :slight_smile:
the Hikvision integrtation , is already based on the same ISAPI url, its just the type of events thats needs to be changed in pyhik , and offcourse some changes in hikvision integration, so more binary sensors are created …

Could anyone please share in what format does https://apiieu.hik-connect.com/v3/users/login/v2 expect username/password be submitted?

Tried to send “account” & “password” key in raw format and getting in return ..."ERROR_MSG": "filed 'password', rejected value[xxxxxx];"

Why do you want to go that road? Everything and more is now possible with ISAPI , and faster

My doorbell DS-KB8113-IM doesn’t support these ISAPI methods so I’m thinking about possible alternatives.

First tried to intercept network traffic from the doorbell to indoor station, but with no luck. Now trying with Hikvision app API.

Managed to implement door unlock method with minor modifications though :blush:

Ah ok , i don’t use the hikconnect API anymore, it was temporarily, now using ISAPI

I think you are better of with the SDK, it’s local and super fast and no polling needed

Do you know if Hikvision SDK can be used to get call button press events for my doorbell?

I never used it, but it supports it without the need to poll for status every second I will try that route

Yes, doorbell is supported

Test this one, currently only working for windows…

If it works, i have a c++ project for Linux , a working one

I run MAC so can’t test it, but I’m now looking into linux SDK. Which method could I use to get a button press?

I see there is a way to subscribe for events/alerts, but I believe my doorbell only supports motion detection and door not closed alerts :confused:

    if (alarminfo_alarm_video_intercom.byAlarmType == VIDEO_INTERCOM_ALARM_ALARMTYPE_DOORBELL_RINGING):
        print("Doorbell ringing")

thanks! will be trying it :slight_smile:

Ok, i think everything is supported on the SDK, keep us posted