Hikvision: Unlock extra line crossing alarms in your camera for free

I wanted to document what @Python discovered and posted some information on a few months ago as it allows you to unlock extra line crossing alarms and possibly other SMART alarm features from your cameras. To make firmware development easy, it is common for companies to write the firmware for all cameras once, and then use a model number to unlock certain features in the UI of the camera. So what this hack does is to bypass the cameras feature locks and tell the underlying engine to process extra line crossing alarms that are not normally offered in the budget line of cameras. Your budget camera can get extra features that the company has locked out and only gives the higher end models.

First use your cameras UI to setup a line crossing alarm that you wish to have, then request the cameras current settings with this on the linux terminal…

Note the 1 on the end of the URL for line 1.

curl http://cameraIP/ISAPI/Smart/LineDetection/1/lineitem/1 --digest -u admin:password

this will return data that looks like this

<?xml version="1.0" encoding="UTF-8"?>
<LineItem>
<id>1</id>
<enabled>false</enabled>
<sensitivityLevel>40</sensitivityLevel>
<directionSensitivity>left-right</directionSensitivity>
<CoordinatesList>
<Coordinates>
<positionX>5</positionX>
<positionY>356</positionY>
</Coordinates>
<Coordinates>
<positionX>188</positionX>
<positionY>486</positionY>
</Coordinates>
</CoordinatesList>
</LineItem>

Then you need to edit what is returned to have the details of the extra line crossing alarm that you wish to add and run it with this command. Note the id is now 2 and also the URL used has a 2 on the end.

curl -k -H 'Content-Type:application/xml' -X PUT -d "
<LineItem>
<id>2</id>
<enabled>false</enabled>
<sensitivityLevel>40</sensitivityLevel>
<directionSensitivity>left-right</directionSensitivity>
<CoordinatesList>
<Coordinates>
<positionX>5</positionX>
<positionY>356</positionY>
</Coordinates>
<Coordinates>
<positionX>188</positionX>
<positionY>486</positionY>
</Coordinates>
</CoordinatesList>
</LineItem>
" http://cameraIP/ISAPI/Smart/LineDetection/1/lineitem/2 --digest -u admin:password

If the command returns it was successful, you can then use the cameras UI to change the line to another location and SAVE it so that the camera has two different line alarms running even though you can not see the second one in the UI.

4 Likes

New feature being discussed on github to allow rules to work out which line number is crossed. See here

[ipcamera] Add channel to show adv event and object detection data · Issue #11391 · openhab/openhab-addons (github.com)

I have tested this on the latest firmware which can be found at the link in this post as Hikvision release builds that dont reach the download pages on their site. Just look in the download area at what model range the camera is in and then check the release notes for the firmware and it will have all supported models listed there.

Hikvision cameras need urgent firmware update - Off-Topic - openHAB Community

1 Like

New feature now added in a BETA version of the binding ready to get merged, see the github link above to find the jar if you wish to help with testing. @Python you requested this feature so if you can help test that would be great.

  1. uninstall the merged binding
  2. Drop the jar into the addons folder unzipped.
  3. install the telstick binding to provide the missing dependencies that may cause errors in the logs. Or you can install netty via the console.
  4. remove and re-add the camera things so that you can see the newly added channels.

An example rule on how to use this new feature…

rule "Backyard Line Crossed"
	when
	Item BackyardCam_LineCrossingAlarm changed to ON
	then
	var xml = BackyardCam_LastEventData.state.toString
		if(xml.contains("<regionID>1</regionID>")){			
			logInfo("Alarm", "Line 1 Crossed")
		}else if(xml.contains("<regionID>2</regionID>")){
			logInfo("Alarm", "Line 2 Crossed")
		}	
end
2 Likes

I have been out of town and will try it out this week and let you know!

Thank you very much for adding this feature!

I finally got around to testing and this works perfect! I made one change to make sure its line crossing if you have field detection in the same area as your line. Heres the code that works

rule "Backyard Line Crossed"
	when
	Item BackyardCam_LineCrossingAlarm changed to ON
	then
	var xml = BackyardCam_LastEventData.state.toString
		if(xml.contains("<regionID>1</regionID>") && xml.contains("<eventType>linedetection</eventType>")){			
			logInfo("Alarm", "Line 1 Crossed")
		}else if(xml.contains("<regionID>2</regionID>") && xml.contains("<eventType>linedetection</eventType>")){
			logInfo("Alarm", "Line 2 Crossed")
		}	
end
1 Like

That should not be necessary as the line crossing alarm won’t turn on until AFTER the last data channel has already been updated. If you found it was necessary can you provide the debug or trace log so it can be looked at? I guess it is possible for the camera to send two events in the same packet so seeing what the root cause is would then allow simple short rules to be done.

You are correct, when i was configuring the items/rules and watching the event logs and noticing the “Last Event Data” changing i wasn’t thinking that this rule would only get fired when LineCrossingAlarm would only fire when turned to ON. Disregard my rule above… it’s working great btw!

Thank you so much for this addition :smiley:

No problems, thanks for suggesting that I check out this method to get the info in the first place. Both Dahua and hikvision cameras have the new detailed info on the smart alarms so you can mix and match brands and barely learn the API to get rules running.