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.

Just wanted to provide an update, i found when i had multiple lines configured and a few of them would get triggered very closely together eg. driving down a driveway. The rule above would miss the line crossing as LastEventData was being updated so fast. Here’s my work around which has been working flawlessly now:

rule "FrontYard-R0: Front Yard Linecrossing - Turn On Depending on What line is Crossed"
when
    Item CAMERA_FrontYard_LastEventData changed
then
   var xml = CAMERA_FrontYard_LastEventData.state.toString

    if(xml.contains("<regionID>1</regionID>") && xml.contains("<eventType>linedetection</eventType>") && xml.contains("<eventState>active</eventState>")) {            //DRIVEWAY: PERSON
        CAMERA_FrontYard_LineCrossing_1.sendCommand(ON)
    }else if(xml.contains("<regionID>2</regionID>") && xml.contains("<eventType>linedetection</eventType>") && xml.contains("<eventState>active</eventState>")) {      //ROAD: Vehicle Counter
        CAMERA_FrontYard_LineCrossing_2.sendCommand(ON)
    }else if(xml.contains("<regionID>3</regionID>") && xml.contains("<eventType>linedetection</eventType>") && xml.contains("<eventState>active</eventState>")) {      //DRIVEWAY: VEHICLE
        CAMERA_FrontYard_LineCrossing_3.sendCommand(ON)
    }else if(xml.contains("<regionID>4</regionID>") && xml.contains("<eventType>linedetection</eventType>") && xml.contains("<eventState>active</eventState>")) {      //Road: BUS
        CAMERA_FrontYard_LineCrossing_4.sendCommand(ON)
    }
end

PS: I upgraded to Hikvision DS-2CD2347G2-LU cameras which support multiplelines without the hack, plus acusense. The acusense for Vehicle / Person detection is night and day from my old G1 cameras. Highly recommend an upgrade if you want to use linecrossing for Vehicle or Person detection rules.

I think you will find this is due to the rule being triggered by changed to ON this means the item MUST go to another state like OFF before going to ON again. If the state is already ON and any line is crossed, yes it would be missed.

See here:
Rules - Introduction | openHAB

You could choose a more suitable trigger perhaps received command ON and use the origial rule.

This would lower the CPU usage as your rule would be triggering way more often as even the CPU load changing in some cameras will be creating an event. Better to only trigger and check when a line is actually crossed.

Of course I could be wrong, but I highly doubt the data is changing too fast, I suspect it is due to the above. I use the trigger that was first suggested as I use it to trigger a recording and I dont want multiple recordings for the same space in time, so understanding the triggers that can be chosen from, PLUS also learn to watch the EVENTS using the developer sidebar as this will show you the events that are used to trigger the rules from and you can see what is happening.