Can I get the state of a camera output (used for holding a gate open) and then CURL a command to close it?

Joined
Apr 2, 2021
Messages
3
Reaction score
1
Location
UK
The alarm out on our NVR is wired back into the NVR where it controls a camera (down by our gate). The camera then holds the gate open when the alarm out it ON, and releases the gate when it is OFF. I want to automate the closing of the gate every night (so that if someone has held the gate open during the day, for a delivery say, and forgotten, the gates will still close at midnight).

The alarm scheduling doesn't achieve this - or at least I can't work out how to achieve this. If you can think of a way of using the built in scheduling to do it then great - let me know!

My alternative was to try to control the gate cam via an HTTP call - and I found this thread: HTTP commands for Hikvision

When I send this command to my gate camera:
HTML:
http://[Username]:[Password]@[IP_Address]/IO/outputs/1/
I get this XML back:
XML:
<IOOutputPort xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
  <id>1</id>
  <PowerOnState>
    <defaultState>low</defaultState>
    <outputState>pulse</outputState>
    <pulseDuration>5000</pulseDuration>
  </PowerOnState>
</IOOutputPort>
I now think I need to make two versions of this, one for ON and one for OFF (probably low and high) and use Curl to post them to camera - however, when I set the gates to open and send this command I get the same XML back (I'm expecting to see low change to high).

Maybe it's just a single five second pulse that puts our gates into hold open mode? If so then can I get the state of the gates? I think I should be able to because when I look at the Alarm Out controls in IVMS-4200 the button shows when it is ON or OFF.

My other idea is to use some PC/Mac automation software to actually look at the screen and click on the button if it is on (I found a Java tool that might allow this to be automated at midnight)

Equipment (as reported by SADP Tool):
NVR: DS-7616NI-K2/16P
Camera: DS-2CD2346G2-ISU/SL
 
Last edited:

venturis

Getting the hang of it
Joined
Aug 8, 2016
Messages
157
Reaction score
98
Location
Australia
Some degree of programmable automation of external devices from a Hikvision NVR is something I'd dearly like to see in some future release.

My lack of programming skill led me to use some readily available off the shelf hardware to do some simple home automation.

In my case I used Tuya Smart compatible devices to interface my NVR to external lighting which is triggered by Smart Events set up on my cameras.

By modifying a Tuya compatible wireless door sensor I was able to connect the NVR relay output across the door sensor's magnetic reed switch which now acts is the door sensor's trigger.

The door sensor is programmed within the Tuya app (Grid Connect in my case) so specific lights switch on/off based on some simple rules. The rules can be time on delays, time off delays, time based duration, sunrise and sunset to name a few, all of which can be overridden by other devices within the same group.

The best part is that the automation works independently of any computers. Of course it relies on a Wifi network being available.

I replaced an outdoor PIR light sensor and now use my Hikvision IP cam and Smart Events to switch security lights on/off and can override the lights or turn them off completely based on programmed rules.

I believe you could do something similar with your gate controller. In the same way my lights are switched ON/OFF you could open/close the gate and also specify a time after which the gate closes if it is open.
 
Last edited:
Joined
Apr 2, 2021
Messages
3
Reaction score
1
Location
UK
Some degree of programmable automation of external devices from a Hikvision NVR is something I'd dearly like to see in some future release.

My lack of programming skill led me to use some readily available off the shelf hardware to do some simple home automation.
Thanks for your detailed reply. I did actually get my intended solution working. I'll post it below, but your solution is very interesting and possibly useful.
 
Joined
Apr 2, 2021
Messages
3
Reaction score
1
Location
UK
With a bit of help from a friend I got it working! First thing was to hunt down some documentation, which was actually very tricky. I've hosted it on my Google Drive:
Then I found the section about Outputs and first tested that I was interfacing with the right part of the camera connected to the gate. Indeed when I sent this to the camera:
http://xxx.xxx.x.xx/IO/outputs/1/status

I got back this XML:
XML:
<IOPortStatus xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
  <ioPortID>1</ioPortID>
  <ioPortType>output</ioPortType>
  <ioState>inactive</ioState>
</IOPortStatus>
And if I did the same thing whilst the gate was being held open by the camera it would say active in iostate.

So now it was just a case of working out what XML I needed to trigger the activity, and where to PUT it. First thing was adjusting the Camera's settings. I logged into the Camera via its IP address in Chrome and used the Administrator username and password. I then went here:

Configuration - Network - Advanced Settings - Integration Protocol

and ticked Enable Hikvision-CGI and also set the Hikvision-CGI Authentication to digest/basic (this enables the user of the Administrator login via the URL in the CURL command, coming next.

I then made two XML files and put them in my home directory. One for OPEN and another for CLOSE. This is what they look like:
XML:
<IOPortData xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
  <outputState>high</outputState>
</IOPortData>
This is the open.xml, the close version has low as the outputState.

Finally I put the CURL command into a BASH script. Again one each for open and close. Here is open.bash
#!/bin/bash
curl -X PUT -H "Content-Type: text/xml" -d @/users/glennbroadway/open.xml "http://[username]:[password]@xxx.xxx.x.xx/IO/outputs/1/trigger"


In the terminal I can now type ./open.bash and the gates are held open.

My plan is to automate the process each night, to ensure the gates close if they have been latched open during the day. I might set my mac to wake up, run the command using Automator and then go back to sleep. Or I might set up a Raspberry Pi to do the same thing (that way I can connect a physical button to the Pi with an LED indicator.)

I do have remote access to my NVR and one of the INPUTs on the NVR is wired to this camera. So with a bit more digging I should be able to find out how to trigger that from a CURL also. This would allow me to set up a shortcut button on iOS or similar, which would be great. If anyone has any tips on that please do let me know.

Thanks!




 
Top