Hikvision Cameras with motion sensor enabled

[quote=“wilme2, post:7, topic:197072”]Is there a certain firmware or model line of Hikvision needed for the motion detection to work?
I thought I had been over all the Hikvision settings, and never found a way to have the camera call an HTTP to queue the motion detection
[/quote]

As far as I know Hikvisions don’t send an http on motion. They do update a running log of motion detected but you need program/app to snif this and act accordingly. Blue iris will do this along with the Hikvision NVR and probley others. The http link posted above seems right for a camera stream but has nothing to do with using the built in motion detection on the camera as far as I know.

I don’t see any mention of this being a DVR function, but I just pulled up the plug-in and it looks specific to a couple of cameras. Cameras with built-in PIR detectors. So this post is real confusing unless you know that


Description: Plugin for Hikvision IP cameras. For UI7 only. Supported camera models : - DS-2CD2Q10FD-IW - Hikvision Mini PT - DS-2CD1410F-IW - Hikvision IR Cube NOTE: This is an ALPHA version!

I don’t see any mention of this being a DVR function, but I just pulled up the plug-in and it looks specific to a couple of cameras. Cameras with built-in PIR detectors. So this post is real confusing unless you know that


Description: Plugin for Hikvision IP cameras. For UI7 only. Supported camera models : - DS-2CD2Q10FD-IW - Hikvision Mini PT - DS-2CD1410F-IW - Hikvision IR Cube NOTE: This is an ALPHA version!

So this plugin will read the stream and look for that PIR trigger. I do use once of these cameras on the front porch for two way audio, but I do not use the PIR due to false triggers. But it is a good way to double up PIR and Motion to maybe make less falses. A single PIR is just not made to be very accurate outdoors.

Worked for me
in ui5.

You had this plugin before it was out?

Hi. Very happy with my current Vera Plus + Hikvision + GoControl door/window sensor. The DVR software triggers line crossing alarms in my perimeter to my Vera Plus via the gocontrol sensor. The VeraPlus is able to blink my lights or enable strobe alarms depending on room location and time of day. Then I use my DVR to send me pictures via email so i know when the kids arrive from school using the same line crossing trigger.

Initially, I was able to link my cctv dvr thru the http link in reply #5. Had alot of dropped/skipped frames so i was better live viewing it through the hikvision mobile app. Still trying to figure out a good use for this. If I use this to save pictures, i’m not sure if i will overfill my veraplus memory or if it is saved in the cloud.

I was able to recently connect, by wire, my spare GoControl door/window sensor to the analog alarm output of the dvr. The magnetic door sensor has provisions to connect a wire. I enabled and configured my DVR’s line crossing feature to send an email and enable alarm output when triggered. Then I created a scene in Vera that when the window sensor closes it triggers certain activities. The line crossing feature is alot better than the motion detection as i rarely (almost none) false alarms.

I think the dvr is also capable of sending an http alarm (instead of connecting a door/window sensor by wire) but i do not know how to configure it in the hikvision dvr and in the vera plus

The I_HikvisonIPCamera.xml contains the data to let work a Hikvision IP camera except the Motion Detect function,
which was not working.
But


Looking at Function startStreaming() ; (from I_HikvisionIPCamera.xml)
The part ‘/ISAPI/Event/notification/alertStream’ filters the data stream from the Hik Camera and puts
the results in the file “/tmp/HilkvisionOutput_devno.txt”

This file contains series of

x.x.x.64 80 HTTP x:x:x:x:74:fc 1 2017-10-16T13:18:39+01:00 0 videoloss inactive videoloss alarm --boundary Content-Type: application/xml; charset="UTF-8" Content-Length: 480 x.x.x.64 80 HTTP x:x:x:x:74:fc 1 2017-10-16T13:21:25+01:00 39 VMD active Motion alarm --boundary Content-Type: application/xml; charset="UTF-8" Content-Length: 517

(about three blocks per second.)

The eventType VMD occurs always when the camera detects Motion.
EventType VDM can come together with eventType fielddetection, linedetection or shelteralarm
EventType videoloss is given when there is no Motion
Each eventType is counted exept videoloss which counts always 0

File “/tmp/HilkvisionOutput_Devno.txt” is processed in the function getStreamEvents()

Change from the function getStreamEvents()
the line

	if newEvent:find("<eventDescription>PIR alarm</eventDescription>")
in
	if newEvent:find("<eventType>VMD</eventType>") 

then the Motion detection works fine.

It is now possible to programm when a eventType VDM expands with eventType linedetection (closer approach from the intuder)
Log those events with a timelabel or use them in MultiString or MultiSwitch app and you you are well documented.

You can see the eventTypes and counts using a Putty session and executing the command:

curl -s http://username:passw@camip/ISAPI/Event/notification/alertStream |
awk -F ‘[<|>]’ ‘//{if ($3 != “videoloss”){print $3}} //{if ($3 != 0){print $3}};’

Regards

loukt
Vera Plus
Firmware 1.7.3232

[quote=“loukt, post:14, topic:197072”]The I_HikvisonIPCamera.xml contains the data to let work a Hikvision IP camera except the Motion Detect function,
which was not working.
But
[/quote]

Just wanted to say thanks for putting this together, and to the original contributors. Using the troubleshooting curl command line you specified with my LaView LV-PB932F4 (rebranded Hikvision bullet cams), I was able to discern that my ‘eventType’ was ‘linedetection’ and get the motion sensing working.

For anyone else trying to use this plugin, it absolutely does NOT work well with UI5, the APIs for device creation are all wrong (though it has some code commented out you can hack through). I also found this code does not work well for hard-wired POE cameras like I have, even ignoring the hard-coded model #s in the source code.

I’ve stripped the code down to ignore the model, and only focused on getting the linedetection search working for my cameras (no wifi setup, no audio sensor, no PTZ, etc), so this may not work for anyone else, but after days of getting this working properly I figured the least I could do was contribute back in case it helps anyone else. The polling getStreamEvents() function was brutal to get working with multiple cameras (it kept crashing my VeraPlus Lua loop), which is where I spent most of my time debugging and modifying the code to streamline it (I’m filtering down to just get the eventType fields, not the whole alertStream).

I’d recommend adding the cameras via the ‘Add Device’->Generic IP Cam->Manual process, and then simply add change the Impl File (to the attachment below after uploading it to the Vera) manually after the camera device is created. I struggled trying to get things working using the original thread directions (via the Create Device in Apps) and it would cause my VeraPlus UI7 to constantly crash (I think it was related to the Streaming functions wreaking havoc for some reason).

Also, I cannot get video streaming to work through my LaView NVR. It defaults to video emulation mode, leveraging the ‘/ISAPI/Streaming/channels/101/picture’ URL for each camera, and because I’m using an NVR with the ‘Virtual Host’ option, there doesn’t appear to be a way to give it an RTSP stream that it would be happy with. Oh well, at least I can see the images, and leverage the linedetection logic!

I have a Laview NVR. To get full streaming (will only work with the mobile app) you need to change the streaming option to
rtsp,rtsp,:8554/PSIA/streaming/channels/101
the next camera would be 102 etc
hope that helps

[quote=“jimmyz, post:16, topic:197072”]I have a Laview NVR. To get full streaming (will only work with the mobile app) you need to change the streaming option to
rtsp,rtsp,:8554/PSIA/streaming/channels/101
the next camera would be 102 etc
hope that helps[/quote]

Thanks Jimmyz. I assume this means you haven’t put the port in the ‘IP’ field already? Since I’m using the Virtual Host option on my DVR, everything I’ve read suggesting using the IP as x.x.x.x:65001 for the first camera, x.x.x.x:65002 for the second camera, etc for the IP address. So I don’t think this would allow me to specify the Streams option using the :8554 in the URL as you’ve done? At least it doesn’t seem to work for me.

Maybe you simply specify the x.x.x.x in the IP address, and then for all the URLs for access, you put the :6500X in the URL field as well?

Here are my settings- I added the nvr per the first post using this:
rtsp://user:pass@IPADDRESSOFNVR:8554/PSIA/streaming/channels/101
you do not have to use the virtual host option this way- just change cameras, camera 1=101; camera 2=201 etc

[quote=“jimmyz, post:18, topic:197072”]Here are my settings- I added the nvr per the first post using this:
rtsp://user:pass@192.168.2.30:8554/PSIA/streaming/channels/101
you do not have to use the virtual host option this way[/quote]
Makes sense. Sadly that will not work with the motion/line-detection stuff, as you need to leverage direct access to the camera to access the alertStream (which is why I’m using the Virtual Host option).

Your post did get me to thinking however, so I went back and reworked the code to not expect the port # in the IP address, which lets me use the 8554 port for the streaming interface like you did, AND I added a new variable to hold the alertStream URL in it (with the appropriate 6500X port # for the Virtual Host of the camera). Works like a champ.

I also discovered my curl | grep pattern was sadly delaying the notification cycle, since it’s buffering between the two commands, so I reverted back to the original method of dumping the complete (and verbose) output of the curl command. There’s still a bit of a delay between when the Hikvision reports the linedetection event in the alertStream, and everything triggers (via Scenes or whatnot), but I guess it’s liveable.

Now if only the ‘Record Video’ trigger would work with the rtsp stream on these cameras (at least we can capture images with them via Scenes).

great- can you post your new code- I would love to try it out thanks in advance

Sure, glad to.

Be sure to specify JUST the IP address of the NVR in the IP address of the camera (this would be the fourth camera, for instance): /ISAPI/Streaming/channels/401/picture

And then the Streams variable like so: rtsp,rtsp,:8554/Streaming/channels/402

This adds a new ‘alertURL’ variable to the camera, which allows you to exactly specify the URL to get the alertStream. If you’re using the Virtual Host option, you should specify the port # of your camera in the first part of the URL like so : :65004/ISAPI/Event/notification/alertStream

Few things you’ll need to ensure:

[ol][li]You have the Virtual Host option turned on for your NVR[/li]
[li]Your username/password is the same on the NVR as your cameras (the admin user may not work well, you may need to add a new user with appropriate permissions)[/li]
[li]You probably will need to change your substream for each camera to MPEG to make the streaming work properly in the mobile app (H.264 which is the default, and does not seem to work for Vera). This is why I specified ‘402’ above, vs ‘401’ which is the main stream.[/li]
[li]This code is specifically written to expect the Line Detection capability to be pre-configured on the camera. You’ll want to do this through the NVR itself for each camera you plan to connect to[/li][/ol]

What’s going on here is we’re actually leveraging the NVR to get the images and video, but then directly accessing the cameras to get access to the alertStream linedetection notifications.

Be careful using this, if you don’t know what you’re up to, you could get into a Luup-reboot-loop and have a tough time getting out of it. (No warranties provided obviously). I’m actually doing this on my LaView NVR/camera setup, which is rebranded Hikvision. Other than the annoying alert-delay things seem to be mostly working.

Hope that helps.

[quote=“bwillette, post:21, topic:197072”]Sure, glad to.

Be sure to specify JUST the IP address of the NVR in the IP address of the camera, and use the port number in the URL like so (this would be the fourth camera, for instance): /ISAPI/Streaming/channels/401/picture

And then the Streams variable like so: rtsp,rtsp,:8554/Streaming/channels/402

This adds a new ‘alertURL’ variable to the camera, which allows you to exactly specify the URL to get the alertStream. If you’re using the Virtual Host option, you should specify the port # of your camera in the first part of the URL like so : :65004/ISAPI/Event/notification/alertStream

Few things you’ll need to ensure:

[ol][li]You have the Virtual Host option turned on for your NVR[/li]
[li]Your username/password is the same on the NVR as your cameras (the admin user may not work well, you may need to add a new user with appropriate permissions)[/li]
[li]You probably will need to change your substream for each camera to MPEG to make the streaming work properly in the mobile app (H.264 which is the default does not seem to work for Vera). This is why I specified ‘402’ above, vs ‘401’ which is the main stream.[/li]
[li]This code is specifically written to expect the Line Detection capability to be pre-configured on the camera. You’ll want to do this through the NVR itself for each camera you plan to connect to[/li][/ol]

What’s going on here is we’re actually leveraging the NVR to get the images and video, but then directly accessing the cameras to get access to the alertStream linedetection notifications.

Be careful using this, if you don’t know what you’re up to, you could get into a Luup-reboot-loop and have a tough time getting out of it. (No warranties provided obviously). I’m actually doing this on my LaView NVR/camera setup, which is rebranded Hikvision. Other than the annoying alert-delay things seem to be mostly working.

Hope that helps.[/quote]

Digging up an old thread.

I just bought my first Hikvision IP camera a
DS-2CD2045FWD-I

I’ve installed the Hikvision IP Camera(ALPHA) plugin and I have uploaded @Sorin I_HikvisionIPCamera.xml file to Vera.

I have managed to add the camera OK in to Vera, following these instructions here and using the I_HikvisionIPCamera.xml file instead.

image

I have enabled basic on the WEB Authentication in the cameras settings.

I can run this command in curl in a CMD prompt and it lists the alertstream information OK.

curl -s http://user:password@192.168.0.15/ISAPI/Event/notification/alertStream

<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>192.168.0.15</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>xx:xx:xx:xx:xx:xx</macAddress>
<channelID>1</channelID>
<dateTime>2020-05-18T14:10:03+00:00</dateTime>
<activePostCount>19</activePostCount>
<eventType>VMD</eventType>
<eventState>active</eventState>
<eventDescription>Motion alarm</eventDescription>
<channelName></channelName>
<Extensions version="1.0" xmlns="urn:psialliance-org">
<serialNumber xmlns="urn:selfextension:psiaext-ver10-xsd">DS-2CD2045FWD-xxxxxxxxxxxxxxxxxxxxxxxx</serialNumber>
<eventPush xmlns="urn:selfextension:psiaext-ver10-xsd">IO&amp;&amp;DS-2CD2045FWD-xxxxxxxxxxxxxxxxxxxxxxxx,2020-05-18T14:10:03+00:00,1.0</eventPush>

Following @loukt advise here, I had edited the I_HikvisionIPCamera.xml file and changed:

Change from the function getStreamEvents()
the line

      if newEvent:find("&lt;eventDescription>PIR alarm&lt;/eventDescription>")
   to
      if newEvent:find("&lt;eventType>VMD&lt;/eventType>")

However in Vera no new motion sensor device is being created.

If I look in the Vera log I can see this:

“not a Hikvision camera, nothing to do” and “Unsupported camera model nothing to do”

The file “/tmp/HilkvisionOutput_Devno.txt” in not being created on the Vera in the /tmp folder.

Anyone know how to fix it ?

Its a genuine EU camera purchased from an authorised dealer not off eBay or Amazon.

Many thanks

1 Like

OK I think I have it working now :grinning:

In the I_HikvisionIPCamera.xml file there is a section for the user name and password:

On Line #58 I put in my password for my camera.

Then on Line #751 I added my camera model number: DS%-2CD2045FWD%-I
I put the percent signs in like on the existing model numbers:

After Vera reloaded the engine a couple of times, I then had a new motion sensor device.

When I wave my hand in front of the camera the new motion sensor device trips and then shortly afterwards un-trips.

I can now see a file called HilkvisionOutput_445.txt in the /tmp folder on Vera.

445 being the device ID number of my camera device in Vera.

The other thing I did on the IP Camera’s settings in Network → Advanced Settings → Integration Protocol. Was enable “Enable Hikvision-CGI” with “digest/basic”.

However I am not 100% sure if that was required. I guess it would be if you have a PTZ camera as the implementation file has references to CGI commands.

This is excellent news.

I don’t currently have a Hikvision NVR but I plan to buy one and I was looking at purchasing a much more expensive model with Alarm Output ports and using a Fibaro Universal Binary sensor to create virtual motion sensor devices in Vera. That thread is here.

Looks like I might not need to do that now as this plug-in is working, so can probably buy a cheaper Hikvision NVR. That’s assuming Ezlo add support for Hikvision cameras and this plug-ins functionality on their new platform.

I’ve turned off Auto Archiving for the camera in Vera, ideally I don’t want the cameras video stream in Vera at all, its just the motion sensor device I wanted.

But I guess for this to work, the camera needs to be added in Vera.

image

This was the output in the Vera log when it actually created the new motion sensor device.

(Hikvision)::(Startup) : plugin rev 5, device #445-Back Garden CAM <0x77312520>
(Hikvision)::(CheckBasicCameraVariables) : Checking
 <0x77312520>
(Hikvision)::(CheckBasicCameraVariables) : Debug mode disabled. <0x77312520>
(Hikvision)::(Reconfigure) : camera is activated <0x77312520>
(Hikvision)::(SetWifiValues) : WiFi disabled or not an Access Point <0x77312520>
(Hikvision)::(ConfigureStream) : start configuring stream <0x77312520>
(Hikvision)::(ConfigureStream) : not a Hikvision camera, nothing to do <0x77312520>
(Hikvision)::(ConfigureMotionSensor) : MSConfStage= <0x77312520>
Device_Variable::m_szValue_set device: 445 service: urn:micasaverde-com:serviceId:Camera1 variable: FirstRun was: EMPTY now: 0 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x77312520>
(Hikvision)::(ConfigureMotionSensor) : First run, creating motion sensor <0x77312520>
(Hikvision)::(GetMotionSensorID) : [1] Motion sensor doesn’t exist <0x77312520>
Device_Variable::m_szValue_set device: 445 service: urn:micasaverde-com:serviceId:Camera1 variable: MSConfStage was: EMPTY now: 3 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x77312520>
(Hikvision)::(ConfigureMotionSensor) : [1] Create the motion sensor <0x77312520>
Device_Variable::m_szValue_set device: 446 service: urn:micasaverde-com:serviceId:SecuritySensor1 variable: Armed was: EMPTY now: 1 #hooks: 0 upnp: 0 skip: 0 v:0x159d550/NONE duplicate:0 <0x77312520>
Device_Variable::m_szValue_set device: 446 service: urn:micasaverde-com:serviceId:SecuritySensor1 variable: IgnoreTripTime was: EMPTY now: 0 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x77312520>
UserData::CommitToDatabase data size 943324 943324 <0x77312520>
JobHandler_LuaUPnP::Reload: luup.reload Critical 0 m_bCriticalOnly 0 dirty data 0 running 1 <0x77312520>
JobHandler_LuaUPnP::Reload: luup.reload Critical 0 pending write, try again later <0x77312520>
(Hikvision)::(Startup) : Startup OK! <0x77312520>

Interestingly it still stated:

(ConfigureStream) : not a Hikvision camera, nothing to do <0x77312520>

OK there is one problem, in the UI7 web GUI I cannot click on the button to Arm/Disarm the sensor. It doesn’t work when pressing the button.

image

However if I go in to the devices Advanced → Variables

And manually edit the “Armed” variable from 0 to 1 then it does work and the sensor then becomes armed OK.

image

Looking in the cameras motion sensor device, under Advanced → Params

The “impl_file” field was blank and had nothing in it. So I entered in I_MotionSensor1.xml and reloaded the LUUP engine.

image

However its still not working, I cannot arm/disarm the motion sensor device by clicking on the buttons in the GUI.

I then looked at some real Z-Wave motion sensor devices in Vera and they didn’t have anything in the “impl_file” field either so maybe that’s normal.

So not sure how to fix this currently.

UPDATE:

I think this is a bug with the Hikvision plug-in ? Not being able to change the motion sensor Armed/Disarmed state using the buttons in the GUI.

Messing around and testing lots of different things, on the motion sensor device if I remove its altid value (camera_445_motion_sensor) and remove its id_parent value (445) and ensure in the impl_file field I have I_MotionSensor1.xml

And then reload the engine, then the button starts working to turn on Armed/Disarmed OK, but obviously the link to the camera is lost.

So if I then add back in the altid and id_parent values the button stops working again.

Specifically it seems to be when I add back in the id_parent number that the button stops working again.

I’ve managed to get the button working and motion sensor tripping, with no id_parent value defined at all (field either empty or with 0), but with the altid field value defined, that seems to be enough to link it up to the camera again.

So now the motion sensor tripped / un-tripped is working and now I can also arm/disarm the sensor using the button in the GUI.

I_MotionSensor1.zip (352 Bytes)


UPDATE - More than one Hikvision Camera

Had a hell of job getting two Hikvision cameras working on my Vera Plus.

In the end I’ve had to use the stripped down I_HikvisionIPCamera.xml file by @bwillette however his line for just filtering the eventType only rather than the whole alertstream was not working, nothing was being populated in the txt file in the Vera tmp folder. I had to comment his line out on line 184 and put the original line back in on line 183.

Also he was looking for eventType “line crossing” on line 228

if newEvent:find("&lt;eventType>linedetection&lt;/eventType>") then

I’ve changed that line back to VMD for motion detection.

if newEvent:find("&lt;eventType>VMD&lt;/eventType>") then

These xml files were on the old forum and they have not be carried over to this new forum. So I am uploading bwillette’s file with my changes mentioned above. Stripped-I_HikvisionIPCamera.zip (5.5 KB)