Hikvision event stream sensors

Awesome. I’ll push it up to pypi and get a PR in to update the version requirement tomorrow.

I have a Hikvision camera rebadged and sold by ADI Technologies.

Model: 0E-13BF40
Firmware Version: V5.3.0 build 160329

I was hoping I’d still be able to use this binary_sensor component despite it not being a legitimate Hikvision camera. It doesn’t appear to be the case. I’m getting the

pyhik.hikvision: Problem finding attribute: list index out of range

error and was wondering if the solution would be as simple as that for drizzay’s problem.

Are you running the stable or dev branch of Home Assistant? The changes that fixed @drizzay problem (and hopefully yours) haven’t been merged into the stable branch yet.

If you are on stable give the dev branch a try to see if it fixes your problem. If you are on dev please post an XML sample from: http://yourcamip/ISAPI/Event/triggers and we’ll go from there.

Oh perfect! My schema also happens to be http://www.std-cgi.com/ver20/XMLSchema.

I’m running the stable branch: 0.35.3

Here is my schema.
triggers.xml (4.3 KB)

Your cameras should work fine after the next stable release. If you’d like to try now but don’t want to commit to running full blown dev you can edit the REQUIREMENTS line at the top of the hikvision.py file under the binary_sensors directory in your hass install to point to “0.0.7” to make it use the new library with the fix.

Awesome. Thanks for the help!

Hi,
Im running 0.35.3 and have two hikvision cameras (DS-2CD2532F-IWS).
I have set up binary_sensors for miton, line cross and intrution detection.
My problem is that these binary_sensors seems to stop responding efter a day more or less! I have not set up any delay on the sensors.
I cant seem to find anything in the default log either, which could explain this.

In addition, if I “hide” the sensors in 1 or more levels of group, these sensors will not respond at all. But that problem I believe has to do with HA and not the Hikvision implementation?

1 Like

@mezz64 - I’m running HA 0.39.3 with an LTS (Hikvision) CMIP3022W IP camera - working great. I also have an LTS NVR that I would like to add to HA, but no success. It is getting the ‘Problem finding attribute: list index out of range’ error. Enabled logger at debug level, but no further info. I have attached a trigger file in case this can be resolved. Thanks for any assistance!

dvr_triggers.xml (44.7 KB)

I was waiting for someone to try this with an NVR to see what would happen. I guess the answer is, things break. :slight_smile:

The trigger file will be useful, I think it may just be a matter of handling multiples properly. In any case can you open an issue on the pyHik github repository (https://github.com/mezz64/pyHik) so I can track this better? I’m finishing up a rewrite on my Emby library so I won’t be able to get to this right away, but am definitely interested in adding the functionality as long as you can support me with testing.

@mezz64 - Thanks for the reply. I’ll swing by github.
I can do any testing as needed.

ISSUE 1:

Trying to get this up and running for my official USA Hikvision 2032. Although I am normally using a custom port but I switched back to 80 for testing purposes. Even with Port 80 in use and several events enabled with ‘Notify Surveillance Center’ turned on (Motion, Tampering and Illegal Login) it looks like pyHik is seeing nothing as available.

Running HA 0.39.3 with pyHik 0.0.7

Triggers.xml: http://pastebin.com/q1mj37ce

Debug log:

17-03-08 20:18:08 INFO (MainThread) [homeassistant.loader] Loaded binary_sensor.hikvision from homeassistant.components.binary_sensor.hikvision
17-03-08 20:18:08 INFO (MainThread) [homeassistant.bootstrap] Setting up binary_sensor
17-03-08 20:18:08 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.hikvision
17-03-08 20:18:09 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x0265C3B0>_2) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.42
17-03-08 20:18:09 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x0265C3B0>_2) [pyhik.hikvision] Using Namespace: http://www.isapi.org/ver20/XMLSchema
17-03-08 20:18:09 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x0265C3B0>_2) [pyhik.hikvision] Found events: []
17-03-08 20:18:09 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x0265C3B0>_2) [pyhik.hikvision] No Events available in dictionary.
17-03-08 20:18:10 DEBUG (Thread-3) [pyhik.hikvision] Stream Thread Started: 1.42 8887 upstairs, 902392e3-750b-11b2-806f-8ce748cc8d91

Any thoughts?

EDIT:

ISSUE 2:

Another issue. I have several re-branded Hikvision cameras as well which aren’t working. I was not going to mention them until I knew why. 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 at GitHub you have the URL hardcoded. Looks like we need to add a second URL to check.

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

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

Would you prefer if I opened 2 issues on your GitHub with relevant logs?

I replied on github to your Issue 2. For Issue 1 please check against the latest dev. The latest pyHik library is a bit more robust (also works with NVR’s now too!) and may have fixed that problem.

If it persists go ahead and open another issue on my pyHik github repo and i’ll look into it some more.

Just coming back to say that I have since updated and the motion detection is now working. Thanks for your help!

It seems after the latest HA 0.49.1 urllib3 errors are caused by the hik binary sensor plugin:

hass[15336]: Traceback (most recent call last):
hass[15336]: File “/srv/homeassistant/lib/python3.4/site-packages/urllib3/connectionpool.py”, line 399, in _make_request
hass[15336]: assert_header_parsing(httplib_response.msg)
hass[15336]: File “/srv/homeassistant/lib/python3.4/site-packages/urllib3/util/response.py”, line 66, in assert_header_parsing
hass[15336]: raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
hass[15336]: urllib3.exceptions.HeaderParsingError: [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ‘’
hass[15336]: WARNING:urllib3.connectionpool:Failed to parse headers (url=http://10.0.1.203:80/ISAPI/Event/notification/alertStream): [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ‘’

hi , my DS-2CD2432F-IW binary sensor stop working after a day and needs 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

@kucau I replied to you on your github issue as well, but is your camera connection via wifi or wired? There have been others in the past that have had problems keeping the wifi connection reliable enough to sustain the event stream. If you are on wifi, maybe try running the camera wired for a few days to see if the issue persists.

@kartikkannan Unfortunately, the hikvision event stream doesn’t present a properly formatted response, leading to those errors. The library actually includes a logging exception line to hide nuisance log lines (like the ones you posted), but it seems to not be working in your case. You can try adding a log line in your configuration.yaml like the one below to hide them. They are harmless.

requests.packages.urllib3: critical
1 Like

Just wanted to follow up and say since updating my motion pyHik motion sensing is back as you expected. Thanks for the quick fix to my GitHub reported issue!

thanks. yeah. since i change to ethernet it is working flawlesss!

Man I wish something like this was available for my Dahua IP cameras. There’s an API for the Dahuas, but I don’t know where to start.

I added 2 Hikvision camera’s to Home Assistant.

It looks like 1 small network hickup causes HA to stop seeing Hikvision events.
Even when Milestone Xprotect is still sending me alerts from the same cameras.

I’m running Home Assistant 0.53.0
My cameras have wired connection.

Anyone else seeing these problems?