I recently bought a SD49425XB and managed to get the auto tracking firmware put on this and everything seems to be working perfectly. One thing I thought would be good was to set up auto tracking for my alarms and have my alarm do a tour through my presets in the evening. It seems, however that the "timed task" functionality prevents the auto tracking from working correctly!
I've written a little Python script (that you can run on a server, or your PC) which actually uses the Dahua API to set the presets based on your settings at a specific interval and during specific times of day. This means you retain the auto tracking feature, because it's the same as simply selecting a preset in the web interface.
I've tested this on the SD49425XB, but this should work on ANY Dahua NVR / PTZ.
I've written a little Python script (that you can run on a server, or your PC) which actually uses the Dahua API to set the presets based on your settings at a specific interval and during specific times of day. This means you retain the auto tracking feature, because it's the same as simply selecting a preset in the web interface.
I've tested this on the SD49425XB, but this should work on ANY Dahua NVR / PTZ.
Python:
import requests
import time as t
from requests.auth import HTTPDigestAuth
from datetime import datetime, time
# Dont edit this unless you know what you're doing
BASE_URL="http://{}/cgi-bin/ptz.cgi?action=start&channel={}&code=GotoPreset&arg1=0&arg2={}&arg3=0"
# Set this to the IP of your NVR
DAHUA_NVR_IP=""
# Set this to the channel number which you want to tour
DAHUA_NVR_SELECTED_CHANNEL=1
# The time which this tour will be active
TOUR_START_TIME = time(00,00)
# The end time of this tour
TOUR_END_TIME = time(6,30)
# The list of presets and times to stay in this preset
TOUR_LIST = [
{
"preset": 1,
"delay": 10
},
{
"preset": 3,
"delay": 10
},
{
"preset": 4,
"delay": 10
},
]
# Your NVR username
DAHUA_NVR_USERNAME=""
# Your NVR password
DAHUA_NVR_PASSWORD=""
def is_time_between(begin_time, end_time, check_time=None):
# If check time is not given, default to current UTC time
check_time = check_time or datetime.utcnow().time()
if begin_time < end_time:
return check_time >= begin_time and check_time <= end_time
else: # crosses midnight
return check_time >= begin_time or check_time <= end_time
run_number = 0
while True:
if is_time_between(TOUR_START_TIME, TOUR_END_TIME):
print("We are in the tour time period.. Beginning to set preset...")
next_preset = TOUR_LIST[run_number % len(TOUR_LIST)]
requests.get(
BASE_URL.format(DAHUA_NVR_IP, DAHUA_NVR_SELECTED_CHANNEL, next_preset['preset']),
auth=HTTPDigestAuth(DAHUA_NVR_USERNAME, DAHUA_NVR_PASSWORD)
)
print(f"Preset has been set to {next_preset['preset']}.. Now waiting for {next_preset['delay']}...")
t.sleep(next_preset['delay'])
run_number = run_number+1
else:
print("Not currently in defined run period.. Will wait for 10 minutes and check again...")
t.sleep(600)