Coder Social home page Coder Social logo

pyhik's Introduction

PyPI

Introduction

This is a python module aiming to expose common API events from a Hikvision IP camera or nvr. Most rebadged models work as well with full functionality.

Code is licensed under the MIT license.

Requirements

If internal callback methods are used no external libraries are required, otherwise:

  • [pyDispatcher] 2.0.5

Installation

pip install pyhik

Usage

import pyhik.hikvision

camera = pyhik.hikvision.HikCamera('http://X.X.X.X', port=80, usr='admin', pwd='1234')

Available Methods

Callbacks

  • add_update_callback(callback, msg) - used to register an update callback function. ** msg should take the form: cam_id.event_type.channel

Properties

  • get_id - returns unique camera/nvr id
  • get_name - returns camera/nvr name
  • current_event_states - returns the event state dictionary

Functions

  • start_stream - initialzes the event stream processing thread
  • disconnect - closes the http stream session and stops the processing thread

TODO

  • Support motion detection status and ability to turn on/off
  • Support IR day/night status and ability to switch between day/night/auto

pyhik's People

Contributors

aarond10 avatar ahsem avatar fabaff avatar jeyrb avatar lauritssn avatar maelstrom96 avatar mezz64 avatar miquelruiz avatar randellhodges avatar smeegoan avatar spawnax avatar tech165 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyhik's Issues

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

I got this "parse_strnig" from cam:

<ipAddress>192.168.1.99</ipAddress>
<portNo>81</portNo>
<protocolType>HTTP</protocolType>
<macAddress>98:8b:aa:a8:7c:5d</macAddress>
<channelID/>
<dynChannelID/>
<dateTime>2019-11-11T01:38:49+02:00</dateTime>
<activePostCount>0</activePostCount>
<eventType>videoloss</eventType>
<eventState>inactive</eventState>
<eventDescription>videoloss alarm</eventDescription>
<channelName/>

and got error:

hikvision.py", line 553, in process_stream
echid = int(echid.text)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

start discovering this code from hikvision.py

echid = tree.find(self.element_query(idtype))
if echid is not None:
try:
# Need to make sure this is actually a number
echid = int(echid.text)
break
except ValueError:
# Field must not be an integer
pass

and notice, that echid.text can be empty. In this case we get TypeError, not ValueError. I can add except TypeError also, or just change:

if echid is not None and echid.text is not None:

but i don't know, if it will be right way and didn't break functionality later.
What is the right way?
Thanks!

Listen for detection event and take photo.

How can I listen to the "motion detection" event, take a photo and capture it ?
In case I need to get a photo every time the "motion detection" event is activated.

thank you since now

Face detection in LIVE

Hi
The following is the code i used detect the FACE in LIVE environment. The error i am getting is
as follows:
cv2.error: /io/opencv/modules/imgproc/src/color.cpp:11111: error: (-215) scn == 3 || scn == 4 in function cvtColor

I tried with RTSP URL it is failing consistently with dis-connectivity of frames. Pls suggest

Source Code:

[](import`` cv2
import sys
import numpy as np
import pyhik.hikvision
camera = pyhik.hikvision.HikCamera('http://192.12.140.6', port=80, usr='admin', pwd='1234')
# could not use the camera object for face detection
cascPath = '/haarcascade_frontalface_default.xml'
faceCascade = cv2.CascadeClassifier(cascPath)
video_capture = cv2.VideoCapture('http://admin:[email protected]:80/videostream.cgi?.mjpg')
# tried with http://192.12.140.6:80/video_feed as well
while True:
ret, frame = video_capture.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags= cv2.CASCADE_SCALE_IMAGE
)

# Draw a rectangle around the faces
 for (x, y, w, h) in faces:
     cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

# Display the resulting frame
 cv2.imshow('Video', frame)

  if cv2.waitKey(1) & 0xFF == ord('q'):
    break


 video_capture.release()
 cv2.destroyAllWindows()](url)``

Alert Stream: enable expert mode

Hi mezz64,
First of all thanks for the work on this module.

I use it primarily as a binary sensor in home assistant, and see a use for creating (optionally) multiple motion sensors per camera if the configuration is set to "expert mode".

I believe the starting point to validate the camera capability using the /ISAPI/System/Video/inputs/channels/1/motionDetectionExt call to get marker XML <activeMode>expert</activeMode>
adding to the API for "extended motion".

Do you see value in investigating this path?

Regards

New gen Hikvision WIFI-Cam not usable with pyHik?

The problem

So far even with the help of the community it is not possible to integrate a current generation Hikvision WIFI-Cam with Home Assistant through the Hikvision-Integration.
The camera itself is properly configured based on the recommendations with base/digest-Support for all authentication-methods, CGI-Integration enabled (even if not need), motion detection-functions enabled with "Notify to Surveillance Station" (with defined zones) and a proper operator-account "hassio-mgmt" with more than needed rights (for test purposes). The password itself is 16 characters long (maximum of supported length of the cam).
When i restart Home Assistant i can see on the cameras webinterface, that the hassio_mgmt-Useraccount is properly connected (see attached screenshots, the IP of homeassistant is the 192.168.150.10), but there are no binary sensors getting created.

Environment

  • Home Assistant Core release with the issue: 0.112.4
  • Hikcam DS-2CV2046G0-IDW camera firmware: 5.5.132 200132 (Newest Acusense Camera with Object Recognition)
  • Last working Home Assistant Core release (if known): never
  • Operating environment (OS/Container/Supervised/Core): Hassio in VM
  • Integration causing this issue: hikvision
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/hikvision/
  • Home Assistant and the Camera reside in different subnets (192.168.150.0/24 and 192.168.160.0/24), which are bidirectionally routed inbetween (without any port blocks at the moment)

Problem-relevant configuration.yaml

binary_sensor:
- platform: hikvision
    name: hikcamfront
    host: 192.168.160.200
    port: 80
    ssl: false
    username: hassio_mgmt
    password: <PW>

Traceback/Error logs

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 446, in _make_request
    assert_header_parsing(httplib_response.msg)
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/response.py", line 71, in assert_header_parsing
    raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
urllib3.exceptions.HeaderParsingError: [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''
[2020-07-18]05:11:10 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:10 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:11 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:11 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:12 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:12 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:15 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:27 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:28 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:28 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:28 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:29 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'
2020-07-18 05:11:32 ERROR (Thread-5) [pyhik.hikvision] Problem finding attribute: 'duration'

Additional information

NVR IO ports no channelID

Unsure which devices this affects, but I have it on the DS-9016HFI-ST (Running V3.4.5 build 170518)

channeIlD is not used on the IO ports, reading through the spec (HIKVISION ISAPI_2.6-IPMD Service.pdf) that tag is only used on camera events.

We should be easily able to deal with it by using the inputIOPortID tag or dynInputIOPortID if channelID is still none.

I would think putting this in under line 548 of hikvision.py would fix it.


        if echid is None:
            # channelID doesnt exist for io ports so we use inputIOPortID instead
            echid = tree.find(
                self.element_query('inputIOPortID'))
        if echid is None:
            echid = tree.find(
                self.element_query('dynInputIOPortID'))

binary_sensors not being updated

Unfortunately I have recently stopped receiveiving updates for any binary_sensors in HomeASsistant. last_tripped_time is always of the last boot time. I've added logging as follows:

  logs:
   pyhik.hikvision: debug
   homeassistant.components.binary_sensor.hikvision: debug

I don't see anything particularly wrong except maybe for last two lines (not sure if this is an expenses behaviour):

2019-11-14 16:03:07 DEBUG (SyncWorker_5) [pyhik.hikvision] pyHik 0.2.4 initializing new hikvision device at: http://192.168.2.200
2019-11-14 16:03:07 DEBUG (SyncWorker_5) [pyhik.hikvision] Using Namespace: http://www.isapi.org/ver20/XMLSchema
2019-11-14 16:03:07 DEBUG (SyncWorker_13) [pyhik.hikvision] pyHik 0.2.4 initializing new hikvision device at: http://192.168.1.200
2019-11-14 16:03:07 DEBUG (SyncWorker_13) [pyhik.hikvision] Using Namespace: http://www.isapi.org/ver20/XMLSchema
2019-11-14 16:03:07 DEBUG (SyncWorker_5) [pyhik.hikvision] Processed 48373635-3035-3034-3032-1868cb846fe1 as NVR Device.
2019-11-14 16:03:07 DEBUG (SyncWorker_5) [pyhik.hikvision] Found events: {'tamperdetection': [1, 2, 3, 4, 5], 'videoloss': [1, 2, 4, 5, 6], 'linedetection': [1, 2, 3, 4, 5], 'diskfull': [0], 'diskerror': [0], 'illaccess': [0], 'recordingfailure': [0]}
2019-11-14 16:03:07 DEBUG (SyncWorker_5) [pyhik.hikvision] Initialized Dictionary: {'Tamper Detection': [[False, 1, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733207)], [False, 2, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733218)], [False, 3, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733223)], [False, 4, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733227)], [False, 5, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733232)]], 'Video Loss': [[False, 1, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733238)], [False, 2, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733243)], [False, 4, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733248)], [False, 5, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733252)], [False, 6, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733257)]], 'Line Crossing': [[False, 1, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733262)], [False, 2, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733267)], [False, 3, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733272)], [False, 4, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733276)], [False, 5, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733280)]], 'Disk Full': [[False, 0, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733286)]], 'Disk Error': [[False, 0, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733292)]], 'Illegal Access': [[False, 0, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733298)]], 'Recording Failure': [[False, 0, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 733304)]]}
2019-11-14 16:03:07 DEBUG (SyncWorker_13) [pyhik.hikvision] Processed 48373635-3035-3033-3638-1868cb846fbf as NVR Device.
2019-11-14 16:03:07 DEBUG (SyncWorker_13) [pyhik.hikvision] Found events: {'tamperdetection': [1, 2, 3, 4, 5], 'linedetection': [1, 2, 3, 4, 5], 'diskfull': [0], 'diskerror': [0], 'illaccess': [0]}
2019-11-14 16:03:07 DEBUG (SyncWorker_13) [pyhik.hikvision] Initialized Dictionary: {'Tamper Detection': [[False, 1, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767031)], [False, 2, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767042)], [False, 3, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767048)], [False, 4, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767052)], [False, 5, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767057)]], 'Line Crossing': [[False, 1, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767063)], [False, 2, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767068)], [False, 3, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767072)], [False, 4, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767077)], [False, 5, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767081)]], 'Disk Full': [[False, 0, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767087)]], 'Disk Error': [[False, 0, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767092)]], 'Illegal Access': [[False, 0, 0, datetime.datetime(2019, 11, 14, 16, 3, 7, 767098)]]}
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Tamper Detection 1: off>> on 48373635-3035-3034-3032-1868cb846fe1.Tamper Detection.1
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Tamper Detection 2: off>> on 48373635-3035-3034-3032-1868cb846fe1.Tamper Detection.2
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Tamper Detection 3: off>> on 48373635-3035-3034-3032-1868cb846fe1.Tamper Detection.3
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 1: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.1
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Tamper Detection 4: off>> on 48373635-3035-3034-3032-1868cb846fe1.Tamper Detection.4
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 2: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.2
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Tamper Detection 5: off>> on 48373635-3035-3034-3032-1868cb846fe1.Tamper Detection.5
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 3: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.3
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Video Loss 1: off>> on 48373635-3035-3034-3032-1868cb846fe1.Video Loss.1
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 4: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.4
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Video Loss 2: off>> on 48373635-3035-3034-3032-1868cb846fe1.Video Loss.2
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 5: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.5
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Video Loss 4: off>> on 48373635-3035-3034-3032-1868cb846fe1.Video Loss.4
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Line Crossing 1: off>> on 48373635-3035-3033-3638-1868cb846fbf.Line Crossing.1
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Video Loss 5: off>> on 48373635-3035-3034-3032-1868cb846fe1.Video Loss.5
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Line Crossing 2: off>> on 48373635-3035-3033-3638-1868cb846fbf.Line Crossing.2
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Video Loss 6: off>> on 48373635-3035-3034-3032-1868cb846fe1.Video Loss.6
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Line Crossing 3: off>> on 48373635-3035-3033-3638-1868cb846fbf.Line Crossing.3
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Line Crossing 4: off>> on 48373635-3035-3033-3638-1868cb846fbf.Line Crossing.4
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Line Crossing 1: off>> on 48373635-3035-3034-3032-1868cb846fe1.Line Crossing.1
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Line Crossing 5: off>> on 48373635-3035-3033-3638-1868cb846fbf.Line Crossing.5
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Line Crossing 2: off>> on 48373635-3035-3034-3032-1868cb846fe1.Line Crossing.2
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Disk Full 0: off>> on 48373635-3035-3033-3638-1868cb846fbf.Disk Full.0
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Line Crossing 3: off>> on 48373635-3035-3034-3032-1868cb846fe1.Line Crossing.3
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Line Crossing 4: off>> on 48373635-3035-3034-3032-1868cb846fe1.Line Crossing.4
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Disk Error 0: off>> on 48373635-3035-3033-3638-1868cb846fbf.Disk Error.0
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Line Crossing 5: off>> on 48373635-3035-3034-3032-1868cb846fe1.Line Crossing.5
2019-11-14 16:03:08 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Illegal Access 0: off>> on 48373635-3035-3033-3638-1868cb846fbf.Illegal Access.0
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Disk Full 0: off>> on 48373635-3035-3034-3032-1868cb846fe1.Disk Full.0
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Disk Error 0: off>> on 48373635-3035-3034-3032-1868cb846fe1.Disk Error.0
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Illegal Access 0: off>> on 48373635-3035-3034-3032-1868cb846fe1.Illegal Access.0
2019-11-14 16:03:08 DEBUG (SyncWorker_5) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Neptune NVR Recording Failure 0: off>> on 48373635-3035-3034-3032-1868cb846fe1.Recording Failure.0
2019-11-14 16:03:12 DEBUG (Thread-6) [pyhik.hikvision] Stream Thread Started: Neptune NVR, 48373635-3035-3034-3032-1868cb846fe1
2019-11-14 16:03:12 DEBUG (Thread-7) [pyhik.hikvision] Stream Thread Started: Saturn NVR, 48373635-3035-3033-3638-1868cb846fbf
2019-11-14 16:03:12 DEBUG (Thread-6) [pyhik.hikvision] Neptune NVR Connection Successful.
2019-11-14 16:03:12 DEBUG (Thread-7) [pyhik.hikvision] Saturn NVR Connection Successful.
....................................

2019-11-14 16:08:12 DEBUG (Thread-9) [pyhik.hikvision] Neptune NVR Watchdog expired. Resetting connection.
2019-11-14 16:08:12 DEBUG (Thread-10) [pyhik.hikvision] Saturn NVR Watchdog expired. Resetting connection.

I do have Notify Surveillance Center permission enabled.

AlertStream: No Element Found

I am using this via HomeAssistant v0.58.1, which I believe is using pyHik 0.1.4.

My new Camera, DS-2CD2H35FWD-IZS gives this error in the HomeAssistant logs:

Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/site-packages/pyhik/hikvision.py", line 378, in alert_stream
    tree = ET.fromstring(parse_string)
  File "/usr/local/lib/python3.6/xml/etree/ElementTree.py", line 1315, in XML
    return parser.close()
  File "<string>", line None
xml.etree.ElementTree.ParseError: no element found: line 1, column 430

I ran curl against the alertStream url and this is what I see:

D:\curl>curl -u user:pass -N http://[redacted]/ISAPI/Event/notification/alertStream
--boundary
Content-Type: application/xml; charset="UTF-8"
Content-Length: 516

<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>[redacted]</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>[redacted]</macAddress>
<channelID>1</channelID>
<dateTime>2017-12-01T09:01:18-6:00</dateTime>
<activePostCount>0</activePostCount>
<eventType>videoloss</eventType>
<eventState>inactive</eventState>
<eventDescription>videoloss alarm</eventDescription>
<channelName>Driveway</channelName>
</EventNotificationAlert>

I am not certain this message is the one that causes the exception. I can let it run a while and verify all the messages I get are formatted the same.

Separate, but related to the same area of code, I notice you only process a message once you reach a new boundary. On this camera, I noticed that an event comes in, and will sit for a few seconds because it waits for the boundary of another message comes in. The boundary is the start of the new message, not the end of a message. Wouldn't this cause delays in the processing of messages?

Would getting the Content-Length, then reading that many bytes instead be more "instant"?

triggering manual recording

http://down.dipol.com.pl/Cctv/-Hikvision-/isapi/HIKVISION%20ISAPI_2.0-RaCM%20Service.pdf

7.4.1 /ISAPI/ContentMgmt/record/control/manual/start/tracks/
This resource is used to manually Start the recording track, regardless of recording mode.
To Enable or Disable (i.e. permanent Stop) the track, the configuration interface should be used to update the track configuration object to set the enable/disable value accordingly.

7.4.2 /ISAPI/ContentMgmt/record/control/manual/stop/tracks/

hikvision.py reference api document

Hi there,

From hikvision.py got two pdf api documentation.

Now couldn't access this pdf, pls may i ask you where can i found those two api documentation, thanks.

No attribute error

My HASS server died a few months ago and I finally replaced it with a Raspberry Pi 3. I got everything up and running except for pyHik. I used my exact same YAML configuration that was working fine up until my server died. Error log below seems to indicate an issue with finding the event. Not sure if pyHik has been updated and broke something for my cameras, or if I'm just forgetting something. Everything looks correct to me in my config.

#Hikvision Setup
binary_sensor:
  - platform: hikvision
    name: Porch
    host: 192.168.1.41
    port: 8889
    username: removed
    password: removed

  - platform: hikvision
    name: Driveway
    host: 192.168.1.40
    port: 8888
    username: removed
    password: removed

Log:

2017-06-24 11:07:23 DEBUG (Thread-4) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.40
2017-06-24 11:07:23 DEBUG (Thread-9) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.41
2017-06-24 11:07:23 DEBUG (Thread-9) [pyhik.hikvision] Using alternate deviceInfo URL.
2017-06-24 11:07:23 DEBUG (Thread-4) [pyhik.hikvision] Using alternate deviceInfo URL.
2017-06-24 11:07:23 DEBUG (Thread-9) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver10/XMLSchema
2017-06-24 11:07:23 DEBUG (Thread-4) [pyhik.hikvision] Using Namespace: http://www.std-cgi.com/ver10/XMLSchema
2017-06-24 11:07:23 DEBUG (Thread-9) [pyhik.hikvision] Using alternate triggers URL.
2017-06-24 11:07:23 DEBUG (Thread-4) [pyhik.hikvision] Using alternate triggers URL.
2017-06-24 11:07:23 ERROR (Thread-9) [pyhik.hikvision] There was a problem finding an element: 'NoneType' object has no attribute 'text'
2017-06-24 11:07:23 DEBUG (Thread-9) [pyhik.hikvision] No Events available in dictionary.
2017-06-24 11:07:23 ERROR (Thread-4) [pyhik.hikvision] There was a problem finding an element: 'NoneType' object has no attribute 'text'
2017-06-24 11:07:23 DEBUG (Thread-4) [pyhik.hikvision] No Events available in dictionary.
2017-06-24 11:07:23 DEBUG (Thread-13) [pyhik.hikvision] Stream Thread Started: Front Door, fb5d3746-9a2b-4dc7-881f-b0d4e8e93094
2017-06-24 11:07:23 DEBUG (Thread-12) [pyhik.hikvision] Stream Thread Started: Driveway 8888, a5d8c037-c3da-4081-8320-cb3fed37af8c
2017-06-24 11:07:23 DEBUG (Thread-12) [pyhik.hikvision] Driveway 8888 Connection Successful.
2017-06-24 11:07:23 DEBUG (Thread-13) [pyhik.hikvision] Front Door Connection Successful.

192.168.1.40 /events/triggers

<?xml version="1.0" encoding="UTF-8"?>
-<EventTriggerList xmlns="http://www.std-cgi.com/ver10/XMLSchema" version="1.0">
-<EventTrigger xmlns="http://www.std-cgi.com/ver10/XMLSchema" version="1.0">
<id>1</id>
<eventType>VMD</eventType>
<eventDescription>VMD Event trigger Information</eventDescription>
-<EventTriggerNotificationList xmlns="http://www.std-cgi.com/ver10/XMLSchema" version="1.0">
-<EventTriggerNotification>
<id>3</id>
<notificationMethod>HTTP</notificationMethod>
<notificationRecurrence>beginning</notificationRecurrence>
</EventTriggerNotification>
</EventTriggerNotificationList>
</EventTrigger>
<EventTrigger xmlns="http://www.std-cgi.com/ver10/XMLSchema" version="1.0"> </EventTrigger>
<EventTrigger xmlns="http://www.std-cgi.com/ver10/XMLSchema" version="1.0"> </EventTrigger>
</EventTriggerList>

192.168.1.41 /event/triggers

  <?xml version="1.0" encoding="UTF-8" ?> 
- <EventTriggerList version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
- <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
  <id>1</id> 
  <eventType>VMD</eventType> 
  <eventDescription>VMD Event trigger Information</eventDescription> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
- <EventTriggerNotification>
  <id>3</id> 
  <notificationMethod>HTTP</notificationMethod> 
  <notificationRecurrence>beginning</notificationRecurrence> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
  <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema" /> 
  <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema" /> 
  </EventTriggerList>

Tamper events from Hikvision camera not recognised

I am using a variety of Hikvision IP cameras, and want to use 'Video Tampering' events to trigger Home assistant automations. The cameras are already set up to generate 'Intrusion Detection' (on the camera GUI) events, which map to 'Field Detection' events (within pyHik), which is all working correctly.

However, the 'Video Tampering' has been more troublesome to get working. Having configured the cameras to 'Notify Surveillance Center' when video tampering occurs, using curl to examine the event triggers shows that a 'tamperdetection' event type now exists:

# curl --anyauth --user operator:password http://192.168.0.125/ISAPI/Event/triggers
---------------------------
<EventTrigger>
<id>tamper-1</id>
<eventType>tamperdetection</eventType>
<eventDescription>shelteralarm Event trigger Information</eventDescription>
<videoInputChannelID>1</videoInputChannelID>
<dynVideoInputChannelID>1</dynVideoInputChannelID>
<EventTriggerNotificationList>
<EventTriggerNotification>
<id>center</id>
<notificationMethod>center</notificationMethod>
<notificationRecurrence>beginning</notificationRecurrence>
</EventTriggerNotification>
</EventTriggerNotificationList>
</EventTrigger>
---------------------------

This 'tamperdetection' eventType in the event triggers is sucessfully recognised by phHik as the logfile contains:

---------------------------
2019-10-23 11:14:34 DEBUG (SyncWorker_3) [pyhik.hikvision] Initialized Dictionary: {'Tamper Detection': [[False, 1, 0, datetime.datetime(2019, 10, 23, 11, 14, 34, 152343)]], 'Field Detection': [[False, 1, 0, datetime.datetime(2019, 10, 23, 11, 14, 34, 152347)]]}
---------------------------

However, monitoring the event stream shows that when the camera lens is obscured the generated event is of eventType 'shelteralarm' xml is:

# curl --anyauth --user operator:password http://192.168.0.125/ISAPI/Event/notification/alertStream
---------------------------
<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>192.168.0.125</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>b4:a3:82:2b:66:a0</macAddress>
<channelID>1</channelID>
<dateTime>2019-10-23T11:17:13+00:00</dateTime>
<activePostCount>82</activePostCount>
<eventType>shelteralarm</eventType>
<eventState>active</eventState>
<eventDescription>shelteralarm alarm</eventDescription>
<channelName></channelName>
</EventNotificationAlert>
---------------------------

SENSOR_MAP, in pyhik.constants, maps the 'shelteralarm' event to 'Shelter Alarm', which does not appear in the Dictionary of monitored event. No action is taken and the event is silently discarded.

I have had a read through the hikvision API documentation (HIKVISION ISAPI_2.0-IPMD Service.pdf) and am a little confused by the description of the 'Tamper Detection' and 'Shelter Alarm'; they seem to be one and the same, by two different names?

To resolve the issue on my system I have modified the SENSOR_MAP entry for 'shelteralarm' events (line 33 of pyhik.constants) so that it maps to 'Tamper Detection' instead of 'Shelter Alarm'.

ie. Change:
Line 33 from:
'shelteralarm': 'Shelter Alarm',
to:
'shelteralarm': 'Tamper Detection',

I don't know enough about the range of Hikvision, and other, cameras to know whether this change is appropriate, or whether it would break other installations. Currently I have tested this 'fix' on a DS-2CD2335FWD-I, but later today I will try is with a pair of DS-2CD2125FWD-I cameras.

namespace for EventTriggerList differs from DeviceInfo one

Hi, I may have a weird hikvision dvr, but it uses different XML namespace in the EventTriggerList than it uses in DeviceInfo, so it cannot be properly queried.

(unimportant/personal data deleted)

โ‚ฌ curl http://@redacted/ISAPI/System/deviceInfo --digest 
<?xml version="1.0" encoding="UTF-8" ?>
<DeviceInfo version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<deviceName>Embedded Net DVR</deviceName>
<model>iDS-7204HUHI-K1/4S</model>
<firmwareVersion>V4.20.000</firmwareVersion>
<firmwareReleasedDate>build 181129</firmwareReleasedDate>
<hardwareVersion>0xc3520</hardwareVersion>
</DeviceInfo>

However, note that a slightly different namespace is used in the next response.

โ‚ฌ curl http://@redacted/ISAPI/Event/triggers --digest    
<?xml version="1.0" encoding="UTF-8" ?>
<EventTriggerList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/mmmm/XMLSchema">
<id>IO-1</id>
<eventType>IO</eventType>
<inputIOPortID>1</inputIOPortID>
<EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/mmmm/XMLSchema">
</EventTriggerNotificationList>
</EventTrigger>
<EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/mmmm/XMLSchema">
<id>IO-2</id>
<eventType>IO</eventType>
<inputIOPortID>2</inputIOPortID>
<EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/mmmm/XMLSchema">
</EventTriggerNotificationList>
</EventTrigger>
...

I have no idea why is this. When using the mmmm schema, it works.

compatible firmware

Thank you for contributing phHik. When using homeassistant, I ran into the log filling up with the error

16-12-27 20:53:30 pyhik.hikvision: Problem finding attribute: list index out of range

My experience with hikvision firmware leads me to believe this a firmware related problem.
I am documenting my experiences to save other people some head scratching:

hikvision firmware V5.2.0 build 140721 (works)
hikvision firmware V5.3.0 build 150327 ( list index out of range)
hikvision firmware V5.3.0 build 150327 ( list index out of range)

updated this same camera to 5.4.0 build 160530 (works)

hikvision firmware V5.3.0 build 150513 ( list index out of range)
hikvision firmware v5.3.3 build 151019 (works)

Looks like 5.3.0 has a problem, firmwares below and above that seem to work fine. The first solution for problems might be to upgrade the firmware on the camera.

@boverby

Erro 401 Unauthorised.

Hello,

I am trying to add my Hikvision binary sensor to my Home Assistant instance and I am getting this 401 error. When I open the same URL in a browser and use the same user/pwd, I can get device info just fine. Here is the log output ( I edited hikvision.py script to print more):

2018-01-21 10:35:12 INFO (MainThread) [homeassistant.loader] Loaded binary_sensor.hikvision from homeassistant.components.binary_sensor.hikvision
2018-01-21 10:35:13 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.hikvision
2018-01-21 10:35:13 DEBUG (Thread-11) [pyhik.hikvision] pyHik 0.1.7 initializing new hikvision device at: http://192.168.1.14
2018-01-21 10:35:13 DEBUG (Thread-11) [pyhik.hikvision] Auth info "hass" "PASSWORD"
2018-01-21 10:35:13 DEBUG (Thread-11) [pyhik.hikvision] Unable to fetch device info. Got code 401
2018-01-21 10:35:13 DEBUG (Thread-11) [pyhik.hikvision] URL: "http://192.168.1.14:80/ISAPI/System/deviceInfo"
2018-01-21 10:35:13 DEBUG (Thread-11) [pyhik.hikvision] Entire response: "

<title>Document Error: Unauthorized</title>

Access Error: 401 -- Unauthorized

Authentication Error

2018-01-21 10:35:13 ERROR (Thread-11) [homeassistant.components.binary_sensor.hikvision] Hikvision event stream has no data, unable to setup 2018-01-21 10:35:15 DEBUG (Thread-12) [pyhik.hikvision] Stream Thread Started: None, None 2018-01-21 10:35:15 WARNING (Thread-12) [pyhik.hikvision] None Connection Failed. Waiting 10s. Err: Connection unsucessful.

DS-2CD2442FWD-IW V5.5.0 build 170725

DS-KB6403-WIP Doorbell - binary_sensor discovered in HA, but motion is never detected

I've finally managed to connect to my Hikvision doorbell and have the sensor show up in HA.
It needs to use port 80 (whereas all my other HK cams need port 8000)
But motion is never detected.

I'm getting this in my HA logs:

2019-11-29 13:11:11 DEBUG (SyncWorker_0) [homeassistant.components.hikvision.binary_sensor] Entity: Doorbell - Motion, Options - Ignore: None, Delay: None

Nothing else...
What can I try please?

There was a problem: 'NoneType' object has no attribute 'text'

Hi,

I updated my Hikvision NVR firmware and now the XML response namespace is different http://www.isapi.org/ver20/XMLSchema instead of http://www.hikvision.com/ver20/XMLSchema

I created a pull request to fix this here

2020-09-02 08:37:00 DEBUG (SyncWorker_21) [pyhik.hikvision] pyHik 0.2.7 initializing new hikvision device at: http://192.168.1.64
2020-09-02 08:37:00 DEBUG (SyncWorker_21) [pyhik.hikvision] Basic authentication failed. Using digest.
2020-09-02 08:37:00 DEBUG (SyncWorker_21) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver20/XMLSchema
2020-09-02 08:37:00 DEBUG (SyncWorker_21) [pyhik.hikvision] Processed 48433334-3438-3632-3937-5803fb2309a7 as CAM Device.
2020-09-02 08:37:00 DEBUG (SyncWorker_21) [pyhik.hikvision] Found events: {}
2020-09-02 08:37:00 DEBUG (SyncWorker_21) [pyhik.hikvision] No Events available in dictionary.
2020-09-02 08:37:00 ERROR (SyncWorker_21) [pyhik.hikvision] Entire response: <?xml version="1.0" encoding="UTF-8" ?>
<MotionDetection version="2.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
<enabled>true</enabled>
<enableHighlight>true</enableHighlight>
<samplingInterval>5</samplingInterval>
<startTriggerTime>1000</startTriggerTime>
<endTriggerTime>1000</endTriggerTime>
<regionType>grid</regionType>
<Grid>
<rowGranularity>18</rowGranularity>
<columnGranularity>22</columnGranularity>
</Grid>
<MotionDetectionLayout version="2.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
<sensitivityLevel>60</sensitivityLevel>
<layout>
<gridMap>00000000000000000000000000000000f80000ff0000ff8000ffc000fffc01fffc01fffc01fffc01fffc01fffc01fffc01fffc01fffc</gridMap>
</layout>
<targetType></targetType>
</MotionDetectionLayout>
</MotionDetection>

2020-09-02 08:37:00 ERROR (SyncWorker_21) [pyhik.hikvision] There was a problem: 'NoneType' object has no attribute 'text'

NVR DS-7108N-SN/P - No Events / NVR Connection Failed

Just found this great module, but not having any luck getting it working with my NVR.

The URL /ISAPI/Event/notification/alertStream is returning 404 on my device.

17-05-05 00:47:11 DEBUG (Thread-7) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.10.21
17-05-05 00:47:11 DEBUG (Thread-7) [pyhik.hikvision] Using Namespace: http://www.isapi.org/ver20/XMLSchema
17-05-05 00:47:11 DEBUG (Thread-7) [pyhik.hikvision] Processed 48353836-3332-3131-3830-2857beef23b4 as NVR Device.
17-05-05 00:47:11 DEBUG (Thread-7) [pyhik.hikvision] Found events: {}
17-05-05 00:47:11 DEBUG (Thread-7) [pyhik.hikvision] No Events available in dictionary.
17-05-05 00:47:26 DEBUG (Thread-16) [pyhik.hikvision] Stream Thread Started: NVR, 48353836-3332-3131-3830-2857beef23b4
17-05-05 00:47:26 WARNING (Thread-16) [pyhik.hikvision] NVR Connection Failed. Waiting 10s. Err: Connection unsucessful.

http://x.x.x.x/ISAPI/System/deviceInfo

  <?xml version="1.0" encoding="UTF-8" ?> 
- <DeviceInfo version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <deviceName>NVR</deviceName> 
  <deviceID>48353836-3332-3131-3830-2857beef23b4</deviceID> 
  <model>DS-7108N-SN/P</model> 
  <serialNumber>DS-7108N-SN/P0820160328AARR586321180WCVU</serialNumber> 
  <macAddress>28:57:be:ef:23:b4</macAddress> 
  <firmwareVersion>V3.0.13</firmwareVersion> 
  <firmwareReleasedDate>build 150503</firmwareReleasedDate> 
  <encoderVersion>V5.0</encoderVersion> 
  <encoderReleasedDate>build 150413</encoderReleasedDate> 
  <deviceType>IPC</deviceType> 
  <telecontrolID>255</telecontrolID> 
  </DeviceInfo>

http://x.x.x.x/ISAPI/Event/triggers

<?xml version="1.0" encoding="UTF-8" ?> 
- <EventTriggerList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>VMD-1</id> 
  <eventType>VMD</eventType> 
  <dynVideoInputChannelID>1</dynVideoInputChannelID> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>record-1</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>1</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-2</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>2</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-3</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>3</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-4</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>4</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-5</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>5</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-6</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>6</dynVideoInputID> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>VMD-2</id> 
  <eventType>VMD</eventType> 
  <dynVideoInputChannelID>2</dynVideoInputChannelID> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>record-1</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>1</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-2</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>2</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-3</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>3</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-4</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>4</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-5</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>5</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-6</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>6</dynVideoInputID> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>VMD-3</id> 
  <eventType>VMD</eventType> 
  <dynVideoInputChannelID>3</dynVideoInputChannelID> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>record-1</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>1</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-2</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>2</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-3</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>3</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-4</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>4</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-5</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>5</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-6</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>6</dynVideoInputID> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>VMD-4</id> 
  <eventType>VMD</eventType> 
  <dynVideoInputChannelID>4</dynVideoInputChannelID> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>record-1</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>1</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-2</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>2</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-3</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>3</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-4</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>4</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-5</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>5</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-6</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>6</dynVideoInputID> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>VMD-5</id> 
  <eventType>VMD</eventType> 
  <dynVideoInputChannelID>5</dynVideoInputChannelID> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>record-1</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>1</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-2</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>2</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-3</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>3</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-4</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>4</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-5</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>5</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-6</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>6</dynVideoInputID> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>VMD-6</id> 
  <eventType>VMD</eventType> 
  <dynVideoInputChannelID>6</dynVideoInputChannelID> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>record-1</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>1</dynVideoInputID> 
  </EventTriggerNotification>
- <EventTriggerNotification>
  <id>record-6</id> 
  <notificationMethod>record</notificationMethod> 
  <dynVideoInputID>6</dynVideoInputID> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>videoloss-1</id> 
  <eventType>videoloss</eventType> 
  <dynVideoInputChannelID>1</dynVideoInputChannelID> 
  <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema" /> 
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>videoloss-2</id> 
  <eventType>videoloss</eventType> 
  <dynVideoInputChannelID>2</dynVideoInputChannelID> 
  <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema" /> 
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>videoloss-3</id> 
  <eventType>videoloss</eventType> 
  <dynVideoInputChannelID>3</dynVideoInputChannelID> 
  <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema" /> 
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>videoloss-4</id> 
  <eventType>videoloss</eventType> 
  <dynVideoInputChannelID>4</dynVideoInputChannelID> 
  <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema" /> 
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>videoloss-5</id> 
  <eventType>videoloss</eventType> 
  <dynVideoInputChannelID>5</dynVideoInputChannelID> 
  <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema" /> 
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>videoloss-6</id> 
  <eventType>videoloss</eventType> 
  <dynVideoInputChannelID>6</dynVideoInputChannelID> 
  <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema" /> 
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>diskfull</id> 
  <eventType>diskfull</eventType> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>email</id> 
  <notificationMethod>email</notificationMethod> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>diskerror</id> 
  <eventType>diskerror</eventType> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>email</id> 
  <notificationMethod>email</notificationMethod> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>nicbroken</id> 
  <eventType>nicbroken</eventType> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>email</id> 
  <notificationMethod>email</notificationMethod> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>ipconflict</id> 
  <eventType>ipconflict</eventType> 
  <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema" /> 
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>illaccess</id> 
  <eventType>illaccess</eventType> 
  <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema" /> 
  </EventTrigger>
- <EventTrigger version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <id>recordingfailure</id> 
  <eventType>recordingfailure</eventType> 
- <EventTriggerNotificationList version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
- <EventTriggerNotification>
  <id>email</id> 
  <notificationMethod>email</notificationMethod> 
  </EventTriggerNotification>
  </EventTriggerNotificationList>
  </EventTrigger>
  </EventTriggerList>

http://x.x.x.x/ISAPI/Event/capabilities

  <?xml version="1.0" encoding="UTF-8" ?> 
- <EventCap version="1.0" xmlns="http://www.isapi.org/ver20/XMLSchema">
  <isSupportHDFull>true</isSupportHDFull> 
  <isSupportHDError>true</isSupportHDError> 
  <isSupportNicBroken>true</isSupportNicBroken> 
  <isSupportIpConflict>true</isSupportIpConflict> 
  <isSupportIllAccess>true</isSupportIllAccess> 
  <isSupportViException>false</isSupportViException> 
  <isSupportViMismatch>false</isSupportViMismatch> 
  <isSupportRecordException>true</isSupportRecordException> 
  <isSupportRaidException>false</isSupportRaidException> 
  <isSupportSmartDetection>true</isSupportSmartDetection> 
  <isSupportPoePowerException>false</isSupportPoePowerException> 
  </EventCap>

Accessing Alarm trigger of camera in python code

Hi,
I connected camera to embedded device for doing image processing, I want to know when has no motion detection triggered by camera, then I stop my processing, Is it possible to access alarm triggers in python code?

Track events not shown in triggers XML endpoint

Some newer devices don't seem to have the ISAPI triggers endpoint that returns all camera trigger options, instead only responding to the non-ISAPI endpoint which only lists basic events.

An option should be added to allow the user to pass in a manually defined dictionary of events they would like to track and process those items from the alertStream without caring if they exist in the trigger XML.

Basic authentication failed. Using digest.

Hi,
I do face error
[pyhik.hikvision] pyHik 0.2.5 initializing new hikvision device at: http://10.0.1.200
[pyhik.hikvision] Basic authentication failed. Using digest.
[pyhik.hikvision] Authentication failed

under HA 0.105.2 with configuration

`binary_sensor:

  • platform: hikvision
    host: 10.0.1.200
    port: 80
    ssl: false
    username: user
    password: pwd`

while camera HIKVISION DS-2CD2032F-I (V5.4.5 build 170123, latest) is fully accessible under those credentials and rstp video also in browser, ISAPI xml as well. Any ideas what to try?

Binary Sensors not being triggered

Good day,

I have an DS-7608NI-K2/8P NVR with 5 cameras attached to it. I am able to see all sensors appear in homeassistant (strangely enough even the one I've removed previously) however none of them appear to be triggering any events. When I've enabled debug I can see that all callbacks are being setup properly but homeassistant loses connection to the NVR?

2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.200
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver20/XMLSchema
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Processed 48373635-3035-3033-3638-1868cb846fbf as NVR Device.
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Found events: {'videoloss': [1, 2, 3, 4, 5], 'fielddetection': [1, 2, 3, 4, 5], 'VMD': [3], 'tamperdetection': [1, 2, 3, 4, 5]}
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Initialized Dictionary: {'Tamper Detection': [[False, 1, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346371)], [False, 2, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346373)], [False, 3, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346376)], [False, 4, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346378)], [False, 5, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346379)]], 'Field Detection': [[False, 1, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346358)], [False, 2, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346360)], [False, 3, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346362)], [False, 4, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346364)], [False, 5, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346366)]], 'Video Loss': [[False, 1, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346342)], [False, 2, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346348)], [False, 3, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346350)], [False, 4, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346353)], [False, 5, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346355)]], 'Motion': [[False, 3, 0, datetime.datetime(2017, 7, 27, 11, 16, 20, 346369)]]}
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Tamper_Detection_1, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 1: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.1
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Tamper_Detection_2, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 2: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.2
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Tamper_Detection_3, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 3: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.3
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Tamper_Detection_4, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 4: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.4
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Tamper_Detection_5, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Tamper Detection 5: off>> on 48373635-3035-3033-3638-1868cb846fbf.Tamper Detection.5
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Field_Detection_1, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Field Detection 1: off>> on 48373635-3035-3033-3638-1868cb846fbf.Field Detection.1
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Field_Detection_2, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Field Detection 2: off>> on 48373635-3035-3033-3638-1868cb846fbf.Field Detection.2
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Field_Detection_3, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Field Detection 3: off>> on 48373635-3035-3033-3638-1868cb846fbf.Field Detection.3
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Field_Detection_4, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Field Detection 4: off>> on 48373635-3035-3033-3638-1868cb846fbf.Field Detection.4
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Field_Detection_5, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Field Detection 5: off>> on 48373635-3035-3033-3638-1868cb846fbf.Field Detection.5
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Video_Loss_1, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Video Loss 1: off>> on 48373635-3035-3033-3638-1868cb846fbf.Video Loss.1
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Video_Loss_2, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Video Loss 2: off>> on 48373635-3035-3033-3638-1868cb846fbf.Video Loss.2
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Video_Loss_3, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Video Loss 3: off>> on 48373635-3035-3033-3638-1868cb846fbf.Video Loss.3
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Video_Loss_4, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Video Loss 4: off>> on 48373635-3035-3033-3638-1868cb846fbf.Video Loss.4
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Video_Loss_5, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Video Loss 5: off>> on 48373635-3035-3033-3638-1868cb846fbf.Video Loss.5
2017-07-27 11:16:20 DEBUG (Thread-21) [homeassistant.components.binary_sensor.hikvision] Entity: Saturn NVR - Motion_3, Options - Ignore: None, Delay: None
2017-07-27 11:16:20 DEBUG (Thread-21) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Saturn NVR Motion 3: off>> on 48373635-3035-3033-3638-1868cb846fbf.Motion.3
2017-07-27 11:16:25 DEBUG (Thread-25) [pyhik.hikvision] Stream Thread Started: Saturn NVR, 48373635-3035-3033-3638-1868cb846fbf
2017-07-27 11:16:25 WARNING (Thread-25) [pyhik.hikvision] Saturn NVR Connection Failed. Waiting 10s. Err: Connection unsucessful.

Alarm IO Channel for NVR

The channel suffix for alarm IO is always 0.

There is code that looks for a node dynVideoInputChannelID or videoInputChannelID. Either it needs to also include a check for dynInputIOPortID, or the cast 'id' to int needs to strip the "eventType-" prefix from the id before attempting to cast to int.

Here is an example:

    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>IO-501</id>
        <eventType>IO</eventType>
        <dynInputIOPortID>501</dynInputIOPortID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
            <EventTriggerNotification>
                <id>record-5</id>
                <notificationMethod>record</notificationMethod>
                <dynVideoInputID>5</dynVideoInputID>
            </EventTriggerNotification>
            <EventTriggerNotification>
                <id>center</id>
                <notificationMethod>center</notificationMethod>
            </EventTriggerNotification>
        </EventTriggerNotificationList>
    </EventTrigger>

gives

binary_sensor.nvr_io_0

expecting

binary_sensor_nvr_io_501

invalid syntax

I am really interested in your project. I replaced my credentials in the example but python3 gave an error message: SyntaxError: invalid syntax
:
import pyhik.hikvision

camera = pyhik.hikvision.HikCamera('http://X.X.X.X', port=80, user='admin', pass='1234')

What shall I do?

Hikvison IO sensor.

Using this in Home-Assistant wont give me a sensor for alarm in from my Hikvision DS-2CD2135FWD-IS.
Firmware in camera: V5.4.5 170124

Acusense camera

When used with newer hik acusense camera, apparently it uses the VCA hence more false alarm despite the camera ability to detect human and vehicle

How to enable any kind of debug?

Would you be so kind and update the wiki or documentation about how to enable enough debug to be able to determine why the lib is not working (in my case I try to register for "fielddetection" events from a NVR but get no events ) as expected? I tried setting debug level using:
_LOGGING.setLevel(logging.DEBUG)
but this had no effect at all.

XML error on DS-7204HUHI

Hi I have a DS-7204HUHI and when I run the script (basic_usage.py) I get the following:

Motion Dectect State: None

I debug the problem and could find the following.
The device info XML is the following:

XXX XXXXXXXXXXXXXXXXX DS-7204HUHI-K1 DS-7204HUHI-K10420180912CCWRC49953259WCVU XXXXXXXXXXXX V4.21.000 build 190722 V5.0 build 190716 IPC 255 0x20c3500

Which sets the namespace to "http://www.hikvision.com/ver20/XMLSchema", but the event trigger is as follow:

IO-1 IO 1 IO-2 IO 2 ...

Note that here the first namespace matches the one in the device info, but not the rest, the ones in the EventTrigger are "http://www.hikvision.com/ver20/mmmm/XMLSchema", there is an extra mmmm/ in it.
If I comment the line (hikvision.py):

self.namespace = nmsp if nmsp.startswith('http') else XML_NAMESPACE

and set XML_NAMESPACE = http://www.hikvision.com/ver20/mmmm/XMLSchema

Then I get a proper output:

{'Motion': [[False, 1, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 2, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 3, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 4, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)]], 'Field Detection': [[False, 1, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 2, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 3, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 4, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)]], 'Line Crossing': [[False, 1, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 2, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 3, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 4, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)]], 'Scene Change Detection': [[False, 1, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 2, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 3, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)], [False, 4, 0, datetime.datetime(2020, 4, 2, 23, 11, 7, 10110)]]}
Motion Dectect State: True

Is there a way to remove this mmmm from the XML my device sends? Or perhaps a fix in this script that would allow my cameras to work?
I would like to use my cameras events on Home Assistant, but I can't because of this... :(
Thank you very much in advance.

Using LTS NVR with pyHik

I'm running HA 0.39.3.
LTS (Hikvision) CMIP3022W IP camera - working great.
LTS (Hikvision) LTN8716T-HT NVR errors with 'Problem finding attribute: list index out of range' error.

Re-Branded Hik - Different URL

I have several re-branded Hikvision cameras as well which aren't working. Looks like the triggers.xml has a different path on those models. To access the triggers.xml the URL is:

http://XXX.XXX.XXX.XXX/Event/triggers

Based on the code here at GitHub you have the URL hardcoded. Looks like we need to add a second URL possibility to check so that these re-branded models will be detected.

Additionally these cameras have a different <notificationMethod>. Instead of center they use:

- <EventTriggerNotification>
    <id>3</id> 
    <notificationMethod>HTTP</notificationMethod> 
    <notificationRecurrence>beginning</notificationRecurrence> 
  </EventTriggerNotification>

(Originally posted to: https://community.home-assistant.io/t/hikvision-event-stream-sensors/6789/71)

Multiple Cameras

pyHik appears unable to handle multiple Hikvision cameras simultaneously. Individually tested each with pyHik without issue. When adding them both to configuration.yaml, however, only one is displayed in states.

configuration.yaml:

#Hikvision Setup
binary_sensor:
  - platform: hikvision
    name: Porch
    host: 192.168.1.41
    port: 8889
    username: removed
    password: removed

  - platform: hikvision
    name: Driveway
    host: 192.168.1.40
    port: 8888
    username: removed
    password: removed

Log:

17-04-02 11:10:28 INFO (MainThread) [homeassistant.loader] Loaded binary_sensor.hikvision from homeassistant.components.binary_sensor.hikvision
17-04-02 11:10:28 INFO (MainThread) [homeassistant.bootstrap] Setting up binary_sensor
17-04-02 11:10:28 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.hikvision
17-04-02 11:10:28 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.hikvision
17-04-02 11:10:28 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.41
17-04-02 11:10:28 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.40
17-04-02 11:10:29 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [pyhik.hikvision] Using alternate deviceInfo URL.
17-04-02 11:10:29 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [pyhik.hikvision] Using alternate deviceInfo URL.
17-04-02 11:10:29 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [pyhik.hikvision] Auto Namespace Result: http://www.hikvision.com/ver10/XMLSchema
17-04-02 11:10:29 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver10/XMLSchema
17-04-02 11:10:29 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [pyhik.hikvision] Auto Namespace Result: http://www.std-cgi.com/ver10/XMLSchema
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [pyhik.hikvision] Using Namespace: http://www.std-cgi.com/ver10/XMLSchema
17-04-02 11:10:29 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [pyhik.hikvision] Using alternate triggers URL.
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [pyhik.hikvision] Using alternate triggers URL.
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [pyhik.hikvision] Processed CAM Device.
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [pyhik.hikvision] Found events: {'VMD': [1]}
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [pyhik.hikvision] Processed CAM Device.
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [pyhik.hikvision] Found events: {'VMD': [1]}
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [pyhik.hikvision] Initialized Dictionary: {'Motion': [[False, 1, 0, datetime.datetime(2017, 4, 2, 11, 10, 30, 377829)]]}
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [pyhik.hikvision] Initialized Dictionary: {'Motion': [[False, 1, 0, datetime.datetime(2017, 4, 2, 11, 10, 30, 362229)]]}
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [homeassistant.components.binary_sensor.hikvision] Entity: Driveway - Motion, Options - Ignore: None, Delay: None
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_4) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Driveway Motion: off>> on 88.Motion.1
17-04-02 11:10:30 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.driveway_motion, old_state=None, new_state=<state binary_sensor.driveway_motion=off; last_tripped_time=2017-04-02T04:10:30.377829-07:00, friendly_name=Driveway Motion, device_class=motion @ 2017-04-02T11:10:30.455829-07:00>>
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [homeassistant.components.binary_sensor.hikvision] Entity: Porch - Motion, Options - Ignore: None, Delay: None
17-04-02 11:10:30 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_8) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Porch Motion: off>> on 88.Motion.1
17-04-02 11:10:30 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=binary_sensor>

/ISAPI/Event/triggers returning device error

I have a new AcuSense 8MP Turret (DS-2CD2386G2-ISU/SL). Firmware V5.5.131 (build 200220).

When I try to request /ISAPI/Event/triggers, I get a device error code. I can access triggersCap and other endpoints. It's just this one that seems bad. Any ideas?

<?xml version="1.0" encoding="UTF-8"?>
<ResponseStatus xmlns="http://www.hikvision.com/ver20/XMLSchema" version="2.0">
  <requestURL>/ISAPI/Event/triggers</requestURL>
  <statusCode>3</statusCode>
  <statusString>Device Error</statusString>
  <subStatusCode>deviceError</subStatusCode>
</ResponseStatus>

How can I get messages about the movement?

Hello, sorry for such a simple question.
How can I get messages about the movement?
What do you need to add to this code?

import pyhik.hikvision
camera = pyhik.hikvision.HikCamera('http://192.168.X.X', port=80, usr='admin', pwd='admin')

DS-7608NI-E2 / A - Not working

Using the latest version 0.1.3 i just get:

2017-07-26 23:14:25 WARNING (Thread-12) [pyhik.hikvision] None Connection Failed. Waiting 10s. Err: Connection unsucessful.
Exception in thread Thread-12:
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/deps/pyhik/hikvision.py", line 358, in alert_stream
    raise ValueError('Connection unsucessful.')
ValueError: Connection unsucessful.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/home/homeassistant/.homeassistant/deps/pyhik/hikvision.py", line 410, in alert_stream
    self.watchdog.stop()
  File "/home/homeassistant/.homeassistant/deps/pyhik/watchdog.py", line 36, in stop
    self._timer.cancel()
AttributeError: 'Watchdog' object has no attribute '_timer'

Using a plain original DS-7608NI-E2 (V3.4.92 build 170228) with DS-2CD2142FWD-IS / DS-2CD2142FWD-I cameras, getting the above error no matter if i connect to the NVR or the cameras directly.

http://x.x.x.x/ISAPI/System/deviceInfo

<?xml version="1.0" encoding="UTF-8" ?>
<DeviceInfo version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
    <deviceName>Network Video Recorder</deviceName>
    <deviceID>48353633-3339-3230-3434-2857be9b7a78</deviceID>
    <model>DS-7608NI-E2/A</model>
    <serialNumber>DS-7608NI-E2/A0820151226AARR534392044WCVU</serialNumber>
    <macAddress>28:57:be:9b:7a:78</macAddress>
    <firmwareVersion>V3.4.92</firmwareVersion>
    <firmwareReleasedDate>build 170228</firmwareReleasedDate>
    <encoderVersion>V5.0</encoderVersion>
    <encoderReleasedDate>build 170228</encoderReleasedDate>
    <deviceType>IPC</deviceType>
    <telecontrolID>255</telecontrolID>
</DeviceInfo>

http://x.x.x.x/ISAPI/Event/triggers

<?xml version="1.0" encoding="UTF-8" ?>
<EventTriggerList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>IO-1</id>
        <eventType>IO</eventType>
        <inputIOPortID>1</inputIOPortID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>IO-2</id>
        <eventType>IO</eventType>
        <inputIOPortID>2</inputIOPortID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>IO-3</id>
        <eventType>IO</eventType>
        <inputIOPortID>3</inputIOPortID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>IO-4</id>
        <eventType>IO</eventType>
        <inputIOPortID>4</inputIOPortID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>IO-101</id>
        <eventType>IO</eventType>
        <dynInputIOPortID>101</dynInputIOPortID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>VMD-1</id>
        <eventType>VMD</eventType>
        <dynVideoInputChannelID>1</dynVideoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
            <EventTriggerNotification>
                <id>record-1</id>
                <notificationMethod>record</notificationMethod>
                <dynVideoInputID>1</dynVideoInputID>
            </EventTriggerNotification>
            <EventTriggerNotification>
                <id>center</id>
                <notificationMethod>center</notificationMethod>
            </EventTriggerNotification>
        </EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>VMD-2</id>
        <eventType>VMD</eventType>
        <dynVideoInputChannelID>2</dynVideoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
            <EventTriggerNotification>
                <id>record-2</id>
                <notificationMethod>record</notificationMethod>
                <dynVideoInputID>2</dynVideoInputID>
            </EventTriggerNotification>
            <EventTriggerNotification>
                <id>center</id>
                <notificationMethod>center</notificationMethod>
            </EventTriggerNotification>
        </EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>tamper-1</id>
        <eventType>tamperdetection</eventType>
        <dynVideoInputChannelID>1</dynVideoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>tamper-2</id>
        <eventType>tamperdetection</eventType>
        <dynVideoInputChannelID>2</dynVideoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>videoloss-1</id>
        <eventType>videoloss</eventType>
        <dynVideoInputChannelID>1</dynVideoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>videoloss-2</id>
        <eventType>videoloss</eventType>
        <dynVideoInputChannelID>2</dynVideoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>fielddetection-1</id>
        <eventType>fielddetection</eventType>
        <videoInputChannelID>1</videoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
            <EventTriggerNotification>
                <id>record-1</id>
                <notificationMethod>record</notificationMethod>
                <dynVideoInputID>1</dynVideoInputID>
            </EventTriggerNotification>
        </EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>fielddetection-2</id>
        <eventType>fielddetection</eventType>
        <videoInputChannelID>2</videoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
            <EventTriggerNotification>
                <id>record-2</id>
                <notificationMethod>record</notificationMethod>
                <dynVideoInputID>2</dynVideoInputID>
            </EventTriggerNotification>
        </EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>linedetection-1</id>
        <eventType>linedetection</eventType>
        <videoInputChannelID>1</videoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
            <EventTriggerNotification>
                <id>record-1</id>
                <notificationMethod>record</notificationMethod>
                <dynVideoInputID>1</dynVideoInputID>
            </EventTriggerNotification>
        </EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>linedetection-2</id>
        <eventType>linedetection</eventType>
        <videoInputChannelID>2</videoInputChannelID>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
            <EventTriggerNotification>
                <id>record-2</id>
                <notificationMethod>record</notificationMethod>
                <dynVideoInputID>2</dynVideoInputID>
            </EventTriggerNotification>
        </EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>diskfull</id>
        <eventType>diskfull</eventType>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>diskerror</id>
        <eventType>diskerror</eventType>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>nicbroken</id>
        <eventType>nicbroken</eventType>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>ipconflict</id>
        <eventType>ipconflict</eventType>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
            <EventTriggerNotification>
                <id>beep</id>
                <notificationMethod>beep</notificationMethod>
            </EventTriggerNotification>
        </EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>illaccess</id>
        <eventType>illaccess</eventType>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"></EventTriggerNotificationList>
    </EventTrigger>
    <EventTrigger version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <id>recordingfailure</id>
        <eventType>recordingfailure</eventType>
        <EventTriggerNotificationList version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
            <EventTriggerNotification>
                <id>beep</id>
                <notificationMethod>beep</notificationMethod>
            </EventTriggerNotification>
        </EventTriggerNotificationList>
    </EventTrigger>
</EventTriggerList>

Sending a GET request to http://xxxx/ISAPI/Event/notification/alertStream just never returns anything (it keeps waiting for a response) when testing with postman, sending an invalid request like PUT to it returns

<?xml version="1.0" encoding="UTF-8" ?>
<ResponseStatus version="1.0" xmlns="urn:psialliance-org">
    <requestURL>/ISAPI/Event/notification/alertStream</requestURL>
    <statusCode>4</statusCode>
    <statusString>Invalid Operation</statusString>
    <subStatusCode>methodNotAllowed</subStatusCode>
</ResponseStatus>

so the url does exist.

HA Switch

Sorry for probably being offtopic

Have you considered merging hikvision and hikvisioncam in HA ?

Hard drive errors

This API is unable to get errors/events related to HARD DRIVE/DISK

DVR is sending that event on iVMS but that error/event is not obtained by this API.

ISAPI 'Invalid Operation' Response

This is almost certainly an issue with my device and not pyHik, but I thought I'd open a thread about it.

I'm playing around with possibly adding support for the Hikvision DS-KB6003-WIP Doorbell cam to pyHik, and hopefully catching the doorbell event. However, I've noticed some stability issues with the alertStream on my device.

Sometimes the /ISAPI/Event/notification/alertStream endpoint returns a healthy response that looks like this:

<EventNotificationAlert version="1.0" xmlns="urn:psialliance-org">
    <ipAddress>192.168.1.100</ipAddress>
    <portNo>80</portNo>
    <protocol>HTTP</protocol>
    <macAddress>*****************</macAddress>
    <dateTime>2018-01-31T07:21:21-05:00</dateTime>
    <activePostCount>1</activePostCount>
    <eventType>other</eventType>
    <eventDescription>Heartbeat</eventDescription>
    <eventState>inactive</eventState>
    <Extensions version="1.0" xmlns="urn:psialliance-org">
        <serialNumber>****************************************</serialNumber>
    </Extensions>
</EventNotificationAlert>

but then occasionally it will only send this response in a HTTP 403 error (which of course pyHik doesn't like):

<?xml version="1.0" encoding="UTF-8" ?>
<ResponseStatus version="1.0" xmlns="urn:psialliance-org">
    <requestURL>/ISAPI/Event/notification/alertStream</requestURL>
    <statusCode>4</statusCode>
    <statusString>Invalid Operation</statusString>
    <subStatusCode>invalidOperation</subStatusCode>
</ResponseStatus>

Once it starts sending invalidOperation responses, it will only return those responses for some undefined amount of time until it eventually starts working again (I haven't timed it). It seems completely random. I have saved the HTTP request in Postman (so not even using Python/pyHik at this point) and can verify that I observe the same behavior there as well, so I think this is a server (device) issue.

The API documentation isn't too helpful about this message. I don't think it's an authentication issue since I'm sending the same basic auth credentials with every request, and it's a 403 (forbidden) not a 401 (unauthorized).

I'm just mostly wondering if @mezz64 you have seen anything like this in your testing with your devices. I am thinking about trying to reach out to Hikvision to see if I can get an explanation... barring any magic solution I would probably have to add some sort of retry logic to handle this in order to add support for this device, unless my device is defective or this is fixed in a future firmware update.

Unable to get motion events from Hikvision doorbell camera

I have 4 POE cameras, and one wireless camera (Doorbell Camera) I believe the model is DS-KB6003-WIP. There are a lot of rebranded versions of this camera. I am unable to get motion events from the doorbell camera, but have no issues with getting motion events from my POE cameras. All Cameras are connected to my NVR.

The only difference in my config between the NVR and the doorbell cameras is that I use the NVR IP and high ports for the events (65002, 03, etc). For the wireless doorbell camera I dont have that option.

I'm connecting with port 80, username and password.

I'm using the most current version on Home Assistant (87.1), but it has never worked for me.

Edit: I forgot to add that the binary sensor does get created, it just never reports motion. The camera does have the notify survelnce center checked

SENSOR MAP key lookup.

It seems that Hikvision might not be totally consistent with XML values in regards to letter case. I had a lot of Disk Error in my HA log - these went away when I fixed all key lookup to be lowercase.

Accept self signed certs

With the recent addition of alexa camera streaming needing https, when I set my Hikvision up to use ssl, my binary_sensors go to unknown. I have been told that the integration needs the ability to accept self signed certs. I have no knowledge other than what I have been told. Just respectfully asking if this is an option.

XML parse errors

I have a Hikvision DS-2CD2045FWD-I cam with firmware V5.6.0 build 190507. I'm getting XML parse errors. The cam is hardwired using a powerline connection. The connection is pretty stable providing ~ 75Mbit/s. I'm also using Hikvision's iVMS-4500 app on my Android smartphone. That way I can compare results. During testing I'm receiving all motion triggers on the phone and also pyHik receives them but generates lots of XML parse errors.

binary sensor stop reporting requiring hass reboot

hi , my DS-2CD2432F-IW binary sensor stop working after a day and some time after few triggers and needs HASS restart. the camera still trigger the cross line detection as i set the audible warning too. the only way to fix this is by rebooting HASS. im using latest HASS.IO. I didnt see any error from HASS log. if u search hass forum at least there is another user having same prob.

status_code 404 errors on firmware 5.5.3

I just updated my 2CD2042 to firmware 5.5.3 and started to get these errors. Everything was working fine before the update. Here are the logs:

2018-12-14 15:15:34 DEBUG (SyncWorker_13) [pyhik.hikvision] pyHik 0.1.8 initializing new hikvision device at: http://192.168.2.94
2018-12-14 15:15:34 DEBUG (SyncWorker_1) [pyhik.hikvision] pyHik 0.1.8 initializing new hikvision device at: http://192.168.2.91
2018-12-14 15:15:34 DEBUG (SyncWorker_28) [pyhik.hikvision] pyHik 0.1.8 initializing new hikvision device at: http://192.168.2.92
2018-12-14 15:15:34 DEBUG (SyncWorker_13) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver20/XMLSchema
2018-12-14 15:15:34 DEBUG (SyncWorker_1) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver20/XMLSchema
2018-12-14 15:15:34 DEBUG (SyncWorker_28) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver20/XMLSchema
2018-12-14 15:15:34 DEBUG (SyncWorker_16) [pyhik.hikvision] pyHik 0.1.8 initializing new hikvision device at: http://192.168.2.93
2018-12-14 15:15:34 DEBUG (SyncWorker_13) [pyhik.hikvision] Processed e6708000-3e8d-11b5-83fb-a4143765f6eb as CAM Device.
2018-12-14 15:15:34 DEBUG (SyncWorker_13) [pyhik.hikvision] Found events: {'VMD': [1], 'linedetection': [1], 'fielddetection': [1], 'facedetection': [1]}
2018-12-14 15:15:34 DEBUG (SyncWorker_13) [pyhik.hikvision] Initialized Dictionary: {'Motion': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 238246)]], 'Line Crossing': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 238250)]], 'Field Detection': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 238252)]], 'Face Detection': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 238254)]]}
2018-12-14 15:15:34 DEBUG (SyncWorker_1) [pyhik.hikvision] Processed 29324000-f3e7-11b4-839c-a4143748e024 as CAM Device.
2018-12-14 15:15:34 DEBUG (SyncWorker_16) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver20/XMLSchema
2018-12-14 15:15:34 DEBUG (SyncWorker_1) [pyhik.hikvision] Found events: {'VMD': [1], 'linedetection': [1], 'fielddetection': [1], 'facedetection': [1]}
2018-12-14 15:15:34 DEBUG (SyncWorker_1) [pyhik.hikvision] Initialized Dictionary: {'Motion': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 244125)]], 'Line Crossing': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 244130)]], 'Field Detection': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 244132)]], 'Face Detection': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 244133)]]}
2018-12-14 15:15:34 DEBUG (SyncWorker_16) [pyhik.hikvision] Processed 29324000-f3e7-11b4-839c-a4143748e036 as CAM Device.
2018-12-14 15:15:34 DEBUG (SyncWorker_16) [pyhik.hikvision] Found events: {'VMD': [1], 'linedetection': [1], 'fielddetection': [1], 'facedetection': [1]}
2018-12-14 15:15:34 DEBUG (SyncWorker_16) [pyhik.hikvision] Initialized Dictionary: {'Motion': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 254264)]], 'Line Crossing': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 254267)]], 'Field Detection': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 254269)]], 'Face Detection': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 254271)]]}
2018-12-14 15:15:34 DEBUG (SyncWorker_28) [pyhik.hikvision] Processed 29324000-f3e7-11b4-839c-a4143748e06a as CAM Device.
2018-12-14 15:15:34 DEBUG (SyncWorker_28) [pyhik.hikvision] Found events: {'VMD': [1], 'linedetection': [1], 'fielddetection': [1], 'facedetection': [1]}
2018-12-14 15:15:34 DEBUG (SyncWorker_28) [pyhik.hikvision] Initialized Dictionary: {'Motion': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 268003)]], 'Line Crossing': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 268006)]], 'Field Detection': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 268007)]], 'Face Detection': [[False, 1, 0, datetime.datetime(2018, 12, 14, 15, 15, 34, 268008)]]}
2018-12-14 15:15:34 DEBUG (SyncWorker_28) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Backyard Motion: off>> on 29324000-f3e7-11b4-839c-a4143748e06a.Motion.1
2018-12-14 15:15:34 DEBUG (SyncWorker_1) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Porch Motion: off>> on 29324000-f3e7-11b4-839c-a4143748e024.Motion.1
2018-12-14 15:15:34 DEBUG (SyncWorker_28) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Backyard Line Crossing: off>> on 29324000-f3e7-11b4-839c-a4143748e06a.Line Crossing.1
2018-12-14 15:15:34 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Driveway Motion: off>> on e6708000-3e8d-11b5-83fb-a4143765f6eb.Motion.1
2018-12-14 15:15:34 DEBUG (SyncWorker_1) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Porch Line Crossing: off>> on 29324000-f3e7-11b4-839c-a4143748e024.Line Crossing.1
2018-12-14 15:15:34 DEBUG (SyncWorker_16) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Patio Motion: off>> on 29324000-f3e7-11b4-839c-a4143748e036.Motion.1
2018-12-14 15:15:34 DEBUG (SyncWorker_28) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Backyard Field Detection: off>> on 29324000-f3e7-11b4-839c-a4143748e06a.Field Detection.1
2018-12-14 15:15:34 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Driveway Line Crossing: off>> on e6708000-3e8d-11b5-83fb-a4143765f6eb.Line Crossing.1
2018-12-14 15:15:34 DEBUG (SyncWorker_1) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Porch Field Detection: off>> on 29324000-f3e7-11b4-839c-a4143748e024.Field Detection.1
2018-12-14 15:15:34 DEBUG (SyncWorker_16) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Patio Line Crossing: off>> on 29324000-f3e7-11b4-839c-a4143748e036.Line Crossing.1
2018-12-14 15:15:34 DEBUG (SyncWorker_28) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Backyard Face Detection: off>> on 29324000-f3e7-11b4-839c-a4143748e06a.Face Detection.1
2018-12-14 15:15:34 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Driveway Field Detection: off>> on e6708000-3e8d-11b5-83fb-a4143765f6eb.Field Detection.1
2018-12-14 15:15:34 DEBUG (SyncWorker_1) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Porch Face Detection: off>> on 29324000-f3e7-11b4-839c-a4143748e024.Face Detection.1
2018-12-14 15:15:34 DEBUG (SyncWorker_16) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Patio Field Detection: off>> on 29324000-f3e7-11b4-839c-a4143748e036.Field Detection.1
2018-12-14 15:15:34 DEBUG (SyncWorker_13) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Driveway Face Detection: off>> on e6708000-3e8d-11b5-83fb-a4143765f6eb.Face Detection.1
2018-12-14 15:15:34 DEBUG (SyncWorker_16) [pyhik.hikvision] Added update callback to <bound method HikvisionBinarySensor._update_callback of <Entity Patio Face Detection: off>> on 29324000-f3e7-11b4-839c-a4143748e036.Face Detection.1
2018-12-14 15:15:50 ERROR (SyncWorker_18) [hikvision.api] status_code 404
2018-12-14 15:15:50 ERROR (SyncWorker_6) [hikvision.api] status_code 404
2018-12-14 15:15:50 ERROR (SyncWorker_18) [hikvision.api] There was an error connecting to http://192.168.2.92/MotionDetection/1/
2018-12-14 15:15:50 ERROR (SyncWorker_17) [hikvision.api] status_code 404
2018-12-14 15:15:50 ERROR (SyncWorker_18) [hikvision.api] status_code 404
2018-12-14 15:15:50 ERROR (SyncWorker_6) [hikvision.api] There was an error connecting to http://192.168.2.91/MotionDetection/1/
2018-12-14 15:15:50 ERROR (SyncWorker_6) [hikvision.api] status_code 404
2018-12-14 15:15:50 ERROR (SyncWorker_22) [hikvision.api] status_code 404
2018-12-14 15:15:50 ERROR (SyncWorker_17) [hikvision.api] There was an error connecting to http://192.168.2.94/MotionDetection/1/
2018-12-14 15:15:50 ERROR (SyncWorker_17) [hikvision.api] status_code 404
2018-12-14 15:15:50 ERROR (SyncWorker_22) [hikvision.api] There was an error connecting to http://192.168.2.93/MotionDetection/1/
2018-12-14 15:15:51 ERROR (SyncWorker_22) [hikvision.api] status_code 404
2018-12-14 15:16:17 DEBUG (Thread-5) [pyhik.hikvision] Stream Thread Started: Hikvision2, 29324000-f3e7-11b4-839c-a4143748e06a
2018-12-14 15:16:17 DEBUG (Thread-6) [pyhik.hikvision] Stream Thread Started: IP CAMERA, 29324000-f3e7-11b4-839c-a4143748e036
2018-12-14 15:16:17 DEBUG (Thread-4) [pyhik.hikvision] Stream Thread Started: IP CAMERA, 29324000-f3e7-11b4-839c-a4143748e024
2018-12-14 15:16:17 DEBUG (Thread-3) [pyhik.hikvision] Stream Thread Started: IP CAMERA, e6708000-3e8d-11b5-83fb-a4143765f6eb
2018-12-14 15:16:17 DEBUG (Thread-5) [pyhik.hikvision] Hikvision2 Connection Successful.
2018-12-14 15:16:17 DEBUG (Thread-6) [pyhik.hikvision] IP CAMERA Connection Successful.
2018-12-14 15:16:17 DEBUG (Thread-4) [pyhik.hikvision] IP CAMERA Connection Successful.
2018-12-14 15:16:17 DEBUG (Thread-3) [pyhik.hikvision] IP CAMERA Connection Successful.
2018-12-14 15:16:21 ERROR (SyncWorker_0) [hikvision.api] There was an error connecting to http://192.168.2.94/MotionDetection/1/
2018-12-14 15:16:21 ERROR (SyncWorker_0) [hikvision.api] status_code 404
2018-12-14 15:16:21 ERROR (SyncWorker_22) [hikvision.api] There was an error connecting to http://192.168.2.93/MotionDetection/1/
2018-12-14 15:16:21 ERROR (SyncWorker_22) [hikvision.api] status_code 404
2018-12-14 15:16:21 ERROR (SyncWorker_6) [hikvision.api] There was an error connecting to http://192.168.2.92/MotionDetection/1/
2018-12-14 15:16:21 ERROR (SyncWorker_6) [hikvision.api] status_code 404
2018-12-14 15:16:21 ERROR (SyncWorker_34) [hikvision.api] There was an error connecting to http://192.168.2.91/MotionDetection/1/
2018-12-14 15:16:21 ERROR (SyncWorker_34) [hikvision.api] status_code 404

Restarting Alert Stream on Connection Loss or Timeout

Hi,
Was having a lot of problems with reconnecting cameras' alert streams after network disconnects or camera restarts and started looking into the watchdog mechanism.
Problem is the current implementation of the watchdog mechanism:

  1. Will only reset the connection if the stream iterator is still active, meaning the camera is still sending some data over the connection but not parsed as Video Loss KA message
  2. OR, will reset the connection if the for line in stream.iter_lines(): loop is broken - which from experience never happens on connection loss or break. Or might happen after a very long time.

It would be preferable to use the python requests timeout param such as:
stream = self.hik_request.get(url, stream=True, timeout=60.0)

and then capture the resulting exception:
except requests.exceptions.ConnectionError as err:

The nice thing about timeout is that its also a read timeout - for stream requests, the number of seconds that the client will wait between bytes sent from the server. See more here

(also see this stack overflow question)

I've been testing the above change in my fork and it looks to be more robust than the watchdog (which I think is now redundant).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.