DAHUA - Auto tracking & time task

nr2005

n3wb
Apr 14, 2021
6
9
uk
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.

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)
 
Thanks I have a 49425 ( in a box ) lol.....
Andy refurb. Has auto track....
i'm not a coder. but I appreciate your effort to get this wrinkle figured out.
it's Genius.... :)
 
Thanks I have a 49425 ( in a box ) lol.....
Andy refurb. Has auto track....
i'm not a coder. but I appreciate your effort to get this wrinkle figured out.
it's Genius.... :)

Definitely loving the cam so far. I’m certainly not a “CCTC connoisseur”, but I’d definitely say it’s on the better end of cams I’ve seen.

Once I have a little bit more time, I’ll make this in to something a little less complex to get up and running, for non-coders. Just wanted to share the work-in-progress solution that I’ve come up with. I’d have thought auto tracking + tours would be a fairly common ask, so I’m surprised it doesn’t work in the official firmware!
 
Yes @looney2ns , my PTZ sits largely in one position looking out at the rear parking lot.
If I am onsite, I may swing it around to zoom in on the pond or the gazebo to see if the door is latched, or zoom into a plate. But it's been relegated to " Goose shit patrol" because it's a Jidetech with a poor user interface and it's best use is a Static camera.
I think If I put my 49425 PTZ up, i may screw it to the Giant oak tree for License plate capture at the intersection, with the option to swing around and peek at my Pontoon boat.