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?
 
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?
I'd be curious if anyone has figured this out for newer Dahua models. I am working on automating day/night from the Habitat home automation system. Older Dahua's work fine (I have 3 of them), newer ones I am struggling to figure it out! I'll post back here if I figure it out.
 
This thread may have some useful information to help with your issue. There is also other info that could be useful and can be located using the site's search function.


Using a C7 Hubitat hub for all camera day/night mode switching. Works perfectly. Have expanded the system to include the use of LUX in place of the Hubitat generated sunrise/set time with a time offset.
 
  • Like
Reactions: Anthony Wise
I'd be curious if anyone has figured this out for newer Dahua models. I am working on automating day/night from the Habitat home automation system. Older Dahua's work fine (I have 3 of them), newer ones I am struggling to figure it out! I'll post back here if I figure it out.
Ok, so got it figured out, at least for me. I am sure there is a better/designed way to do this but this is what seems to work for me. I have it seems 3 different 'generations' of camera (I am guessing different API versions). Some are pretty old and some I purchased within a year or so. The later ones have the 'modern' looking interface that no longer required IE.

So here goes what works for me based on model of camera:

OLDEST Models

This was well documented here and elsewhere. Basically the following works for these:

http://<id>:>password>@<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[0].NightOptions.SwitchMode=<mode> where <mode> was 1 for NIGHT and 0 for DAY.

A few years OLD Models

Again, this was documented out there BUT initially did not work for me. The trick was to set the schedule in the UI to be 'Full Time'. Then the setting below is available and settable. I had it set to 'schedule' and the variable was NOT available to set.

http://<id>:>password>@<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=<mode> where <mode> was 1 for NIGHT and 0 for DAY

1736819153990.png

NEWEST Models

So none of the above worked on the two newer models I have. After some 'wiresharking' (is that a word) and API reading, I ended up getting this to work:

http://<id>:>password>@<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][<month>]=00:00:00-24:00:00%20<Mode> where <month> is the 'month count-1' -- so Jan is 0, Feb 1, etc ... and <mode> is a string for the profile name. IN my case 'Night' and 'Day'.

This is interesting as I could not find a simple way to just set the 'active profile' (like the older models). So instead, I set the schedule for that moth to always be whatever profile I wanted. That seems to trigger a switch to that profile. So end result is the same. If anyone knows of a direct 'set active profile' setting please share!

Again, a few things I needed to get this to work:
  • Set a default schedule. If there is no schedule, the values are not available to set.
  • The schedule is per month, so the setting varies in the second index of the TimeSectionV2 array.
 

Attachments

  • 1736819457718.png
    1736819457718.png
    127 KB · Views: 0
This thread may have some useful information to help with your issue. There is also other info that could be useful and can be located using the site's search function.


Using a C7 Hubitat hub for all camera day/night mode switching. Works perfectly. Have expanded the system to include the use of LUX in place of the Hubitat generated sunrise/set time with a time offset.
Ha, of course -- just as I figure it out. Yep, that is exactly what I also found for my newer CAMS. Nice -- and thanks for the info.
 
# Dahua DVR Snapshot Issue

## Description
I am trying to capture a snapshot from my Dahua DVR using a Node.js project, but I am encountering a 401 Unauthorized error despite using the correct credentials.

## Project Details
I am using Node.js with Axios to send requests to the Dahua DVR API. The goal is to retrieve a snapshot from the DVR.

## API Endpoint
Code:
http://admin:abc12345@192.168.0.109/cgi-bin/snapshot.cgi?channel=1
When accessed via a browser, the URL prompts for credentials and works as expected. However, in my Node.js application, it returns a 401 Unauthorized error.

## Current Behavior
Receiving a 401 Unauthorized error when sending a GET request to the API using Axios in Node.js.

## Node.js Code
JavaScript:
const axios = require('axios');
const fs = require('fs');

const url = "http://admin:abc12345@192.168.0.109/cgi-bin/snapshot.cgi?channel=1";

axios({
  method: 'get',
  url: url,
  responseType: 'stream',
  auth: {
    username: 'admin',
    password: 'abc12345'
  }
})
.then(response => {
  response.data.pipe(fs.createWriteStream('snapshot.jpg'));
  console.log("Snapshot saved as snapshot.jpg");
})
.catch(error => {
  console.log("Error:", error.message);
});

## Troubleshooting Steps Taken
  • Verified credentials by logging in via the browser.
  • Ensured that the DVR’s HTTP Authentication settings are correctly configured.
  • Attempted using both Basic Authentication and Digest Authentication.
  • Checked the Security settings on the DVR but could not find specific HTTP Authentication options.
  • Verified that the API endpoint works directly in the browser but fails in Node.js.

## Expected Behavior
The API should return a snapshot image without authentication errors when accessed via Node.js.



Image


Image


Image


Image

## URL working on my Chrome but Node js not Working

Image

## this is my node js error
 
# Dahua DVR Snapshot Issue

## Description
I am trying to capture a snapshot from my Dahua DVR using a Node.js project, but I am encountering a 401 Unauthorized error despite using the correct credentials.

## Project Details
I am using Node.js with Axios to send requests to the Dahua DVR API. The goal is to retrieve a snapshot from the DVR.

## API Endpoint
Code:
http://admin:abc12345@192.168.0.109/cgi-bin/snapshot.cgi?channel=1
When accessed via a browser, the URL prompts for credentials and works as expected. However, in my Node.js application, it returns a 401 Unauthorized error.

## Current Behavior
Receiving a 401 Unauthorized error when sending a GET request to the API using Axios in Node.js.

## Node.js Code
JavaScript:
const axios = require('axios');
const fs = require('fs');

const url = "http://admin:abc12345@192.168.0.109/cgi-bin/snapshot.cgi?channel=1";

axios({
  method: 'get',
  url: url,
  responseType: 'stream',
  auth: {
    username: 'admin',
    password: 'abc12345'
  }
})
.then(response => {
  response.data.pipe(fs.createWriteStream('snapshot.jpg'));
  console.log("Snapshot saved as snapshot.jpg");
})
.catch(error => {
  console.log("Error:", error.message);
});

## Troubleshooting Steps Taken
  • Verified credentials by logging in via the browser.
  • Ensured that the DVR’s HTTP Authentication settings are correctly configured.
  • Attempted using both Basic Authentication and Digest Authentication.
  • Checked the Security settings on the DVR but could not find specific HTTP Authentication options.
  • Verified that the API endpoint works directly in the browser but fails in Node.js.

## Expected Behavior
The API should return a snapshot image without authentication errors when accessed via Node.js.



Image


Image


Image


Image

## URL working on my Chrome but Node js not Working

Image

## this is my node js error