Switch Dahua Day/Night Profile via IPC HTTP API

In the original post, Nayr said the last number in the command means:
2 means set to "Full Time" "Night"
1 means set to "Full Time" "Day"

In my camera, IPC-HFW8232E-Z, the numbers mean something different:
2 means Profile Management set to "Normal".
1 means set to "Full Time" "Night"
0 means set to "Full Time" "Day"

So you may need to try different numbers with your camera, then check what the effects are in the web UI. Or you can try different web UI settings and see how they change the numbers output by this command:
Code:
http://username:password@IP-ADDRESS/cgi-bin/configManager.cgi?action=getConfig&name=VideoInMode

Also, if you have access to the 'curl' unix command, you can run these API commands in any type of script by calling curl as follows:
Code:
curl --digest "http://username:password@IP-ADDRESS/cgi-bin/configManager.cgi?action=setConfig&VideoInMode%5B0%5D.Config%5B0%5D=2"

Add -v (verbose) parameter to look for errors in the camera response.

For Windows users, someone wrote a windows service to toggle day/night profile on the camera.

For windows 10, you can install the Linux subsystem for windows, then just use curl from a Linux prompt. Works just the same as running a native Linux system.
 
For windows 10, you can install the Linux subsystem for windows, then just use curl from a Linux prompt. Works just the same as running a native Linux system.
You can skip loading linux and get the windows version of CURL. It would save you a few hundred megabytes of system space.
 
LOL Darkflame, I like your avatar!

Do you know if Alarm Out can be triggered by API?
You could try something like this.

Dahua API v1.56, page 52: SetAlarmOutConfig

http://<ip>/cgi-bin/configManager.cgi?action=setConfig&AlarmOut[port].Mode=<paramValue>

-port = Alarm out port index starts at 0
-paramValue: 0=auto, 1=force on, 2=close alarm

Kevin
 
Just thought I would add the Dahua HTTP API for IPC (V1.67) to this thread for reference.
 

Attachments

In case this helps anyone, I ended up rolling my own day/night script in Windows that looks up the sunrise/sunset times using the API available at "api.sunrise-sunset.org" and creating/updating a pair of scheduled tasks at the appropriate time of day.

The commands I use to switch profiles vary - the newer and older Dahuas have slightly different URLs:

Old, like my IPC-HFW4300s models:
curl -s --globoff --basic --user %username%:%oldpass% "[0].NightOptions.SwitchMode=%mode%"

New, like the SD49225 or also on Amcrest cameras:
curl -s --globoff --digest --user %username%:%newpass% "[%channel%].Config[0]=%mode%"

The %mode% variable is 0 for day on both the old and new. For night, use 1 for the new cameras and 3 for the old.

For %channel% it'll be zero all the time unless you're setting the mode on a second camera for a model like IPC-HDBW4231F-E2-M which has 2 cameras in one body. It's just the camera number, starting with zero. I didn't bother customizing that for the old models; I just use zero all the time anyway so why bother.

Note that the authentication is "basic" for the old models, "digest" for the new ones.
 
  • Like
Reactions: International784
FYI, now that I finally got around to looking at a newer version of the API (version 2.89) I noticed a couple of things:
1) "VideoInMode" is not listed in the document... at all. Weird. It still works on my 2.x firmware Dahua cameras, but the API doesn't mention it
2) "VideoInOptions" has a section, but it points out that "It’s not recommended to use the CGI command from “ video in options ” ; It’s now recommended to use the commands in 5.1 – 5.7"

That said, my previous post from 4.5 years ago still seems to be true, although whether it'll work with newer Dahua cameras on the 3.x firmware, no idea yet. If anyone else has an idea of what the official, recommended way is to use the API to switch a camera between day/night/normal/auto/timer that'd be good info. I think the day/night script that's available here uses those same API commands so if there's a different/better way of doing it, that might be worth updating as well?