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
stezak
August 2, 2021, 8:18am
528
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
andrewsmit
(Andrew Smit)
August 3, 2021, 3:11pm
530
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
andrewsmit
(Andrew Smit)
August 3, 2021, 6:28pm
532
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
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 âŚ
iko3
(Oleg)
August 6, 2021, 7:50pm
535
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
iko3
(Oleg)
August 7, 2021, 1:48pm
537
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
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
iko3
(Oleg)
August 7, 2021, 3:03pm
539
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
iko3
(Oleg)
August 7, 2021, 8:25pm
542
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
if (alarminfo_alarm_video_intercom.byAlarmType == VIDEO_INTERCOM_ALARM_ALARMTYPE_DOORBELL_RINGING):
print("Doorbell ringing")
iko3
(Oleg)
August 8, 2021, 8:22am
544
thanks! will be trying it
Ok, i think everything is supported on the SDK, keep us posted