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…
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.
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.
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.
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.
uninstall the merged binding
Drop the jar into the addons folder unzipped.
install the telstick binding to provide the missing dependencies that may cause errors in the logs. Or you can install netty via the console.
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
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
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!
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.
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.
So, this will only work in combination with the OpenHAB binding or also in the camera itself?
I’m asking because I successfully followed the instructions, but when I cross the invisible line, it doesn’t trigger a line-crossing event in the camera. So, before I go on troubleshooting this, I wanted to check whether it is supposed to work in the first place.
Also, I wanted to mention that I read somewhere that the reason why certain models only have one line is that the CPU might otherwise be overwhelmed by calculations for too many lines so that alarms may become unreliable. If this is true, then I guess there is still a certain margin that might allow for one extra line, especially when you haven’t all smart events enabled. For example, I don’t have motion detection enabled, so I assume that I can safely add another line or two. But your mileage may vary, so I just wanted to mention this potential source of problems.