Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tamper events from Hikvision camera not recognised #43

Closed
marshn opened this issue Oct 23, 2019 · 5 comments
Closed

Tamper events from Hikvision camera not recognised #43

marshn opened this issue Oct 23, 2019 · 5 comments

Comments

@marshn
Copy link

marshn commented Oct 23, 2019

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.

@mezz64
Copy link
Owner

mezz64 commented Oct 25, 2019

Your testing results are interesting and i'm curious to hear if you see the same behavior on your other cameras. Mine have the video tampering option as well so i'll try to find some time to enable and test and see if they exhibit the same behavior. If it's consistent I don't have a problem combining them.

@marshn
Copy link
Author

marshn commented Oct 30, 2019

The same 'fix' is working with the DS-2CD2125FWD-I cameras and a DS-2CD2T25FWD-I5, so there is at least come consistency.

@mezz64
Copy link
Owner

mezz64 commented Nov 16, 2019

I saw this same behavior on my own cams so I've merged in a fix and released a new version. A PR is pending to update the repository in HASS but you can manually specify 0.2.5 to check it now if you'd like.

@jeyrb
Copy link
Contributor

jeyrb commented Dec 27, 2019

I have something similar with a DS-2CD4A25FWD-IZS - it has a 'defocus' event which isn't listed in the pyhik constants dict, so HomeAssistant logs unknown event every time it happens. Think its intended by the vendor to be another tamper detection.

@mezz64
Copy link
Owner

mezz64 commented Apr 14, 2020

Closing since we've added the defocus event type into the dict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants