Hikvision Separate Day/Night settings

mlapaglia

Getting comfortable
Joined
Apr 6, 2016
Messages
849
Reaction score
506
so for LPR on Hikvision you need to set the gain low at night because it tries to compensate for the 1/1000 shutter speed they are running at. In order to manually control the gain on Hikvision I have to set the day/night mode from "Automatic" (based on daylight) to "Day" (always in day mode), "Night (always in night mode), or "Scheduled" where I have to set the time to switch from day to night.

Is there a way to run a script that will send a HTTP message to the camera to do this? I can make something that fetches the day's sunrise/sunset and push the setting to the camera manually.
 

mlapaglia

Getting comfortable
Joined
Apr 6, 2016
Messages
849
Reaction score
506
Nevermind I figured it out. Just do a PUT request to
Code:
http://<username>:<password>@<ipaddress>:<port>/ISAPI/Image/channels/1
with the following in the body:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<ImageChannel version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
    <IrcutFilter version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
        <IrcutFilterType>night</IrcutFilterType>
    </IrcutFilter>
</ImageChannel>
Going to run this on a little raspberry pi that will check the daily sunrise/sunset and issue the command to toggle the camera into the desired mode. Shame Hikvision has such crappy software.
 

mlapaglia

Getting comfortable
Joined
Apr 6, 2016
Messages
849
Reaction score
506
I made a short script to do this for me. put this first block into scheduler.py
Code:
import requests
import json
import time
import subprocess
from dateutil import tz
from datetime import datetime

longitude = ''
latitude = ''
timezone = '' #America/New_York
ips = [] #['192.168.1.4:65010', '192.168.1.4:65009']
user = ''
password = ''
nightOrDayPath = '' #/home/pi/setNightDay.py

r = requests.get('http://api.sunrise-sunset.org/json?lat=' + latitude + '&lng=' + longitude + '&date=today')
json = json.loads(r.content)

from_zone = tz.gettz('UTC')
to_zone = tz.gettz(timezone)

utcSunset = datetime.strptime(time.strftime("%Y-%m-%d") + " " + json['results']['sunset'], '%Y-%m-%d %I:%M:%S %p')
utcSunset = utcSunset.replace(tzinfo=from_zone)
utcSunrise = datetime.strptime(time.strftime("%Y-%m-%d") + " " + json['results']['sunrise'], '%Y-%m-%d %I:%M:%S %p')
utcSunrise = utcSunrise.replace(tzinfo=from_zone)
sunset = utcSunset.astimezone(to_zone)
sunrise = utcSunrise.astimezone(to_zone)

print "sunrise is " + sunrise.strftime('%H:%M %p')
print "sunset is " +  sunset.strftime('%H:%M %p')

for ip in ips:
        dayCommand = 'python ' + nightOrDayPath + ' --ip ' + ip + ' --user ' + user + ' --password ' + password + ' --dayornight day | at ' + sunrise.strftime('%H:%M');
        nightCommand = 'python ' + nightOrDayPath + ' --ip ' + ip + ' --user ' + user + ' --password ' + password + ' --dayornight night | at ' + sunset.strftime('%H:%M');

        subprocess.call(dayCommand, shell=True)
        subprocess.call(nightCommand, shell=True)

print 'tasks are scheduled'
Create a cron job that will execute scheduler.py after midnight each day.

Put the second block in setNightDay.py
Code:
#!/usr/bin/env python
import requests
from requests.auth import HTTPBasicAuth
import sys
import argparse

parser = argparse.ArgumentParser(description='Set day and night status on Hikvision cameras.')
parser.add_argument('--ip', help='IP address and port to send command to')
parser.add_argument('--user', help='Hikvision username')
parser.add_argument('--password', help='Hikvision password')
parser.add_argument('--dayornight', help='night or day', choices=['night', 'day'])

args=parser.parse_args()

xml = '<ImageChannel version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"><IrcutFilter version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema"><IrcutFilterType>' + args.dayornight + '</IrcutFilterType></IrcutFilter></Im$
requests.put('http://' + args.ip + '/ISAPI/Image/channels/1', data=xml, auth=HTTPBasicAuth(args.user, args.password));
 

Dragon

Getting the hang of it
Joined
Mar 19, 2016
Messages
68
Reaction score
30
Cool solution but I think the IrcutFilter setting only controls whether the camera is in B&W or color mode (IR cut filter on for color, off for B&W). You aren't changing the camera to its Day or Night profile which each have other parameters associated with them like shutter speed, brightness, backlight, etc. Maybe IR cut is all you need for your purposes but if you need to switch between Day and Night profile, I wrote a method here.
 

mlapaglia

Getting comfortable
Joined
Apr 6, 2016
Messages
849
Reaction score
506
sorry i never responded to this. setting the ir cut filter field sets it into night mode also.

1612882458187.png

1612882480714.png
 
Top