Switch Dahua Day/Night Profile via IPC HTTP API

nayr

IPCT Contributor
Jul 16, 2014
9,229
5,328
Denver, CO
took me a damn good while to figure this one out, so here it for anyone needing it in the future.. once again searches lead me nowhere so I had to resort to a bit of trial and error as the docs suggest this is not the way to accomplish this task.. but it is.

First setup your camera to be in Full Time profile for Day since you will be changing it externally now.

To switch to Day profile:
Code:
http://username:password@IP-ADDRESS/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1
To switch to Night profile:
Code:
http://username:password@IP-ADDRESS/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=2
Now I can have tailored configurations for day and night mode, then use my Automation system that actually calculates real sunrise/sunset based off lon/lat and has access to a few light sensors to trigger the switch when I want it to.
 

Attachments

  • Screen Shot 2016-02-16 at 4.18.33 AM.png
    Screen Shot 2016-02-16 at 4.18.33 AM.png
    33.4 KB · Views: 478
Last edited by a moderator:
and of course there is never any consistency, only my PTZ took those commands tonight.. my other 3 Dahua's (IPC) all stayed in day mode.. so if that dont work for you try:

Code:
DAY PROFILE - /cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[0].NightOptions.SwitchMode=0
NIGHT PROFILE - /cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[0].NightOptions.SwitchMode=3

and here is an example showing how I have it implemented using a Lua script on my Automation Server:
I am so damn happy with the results, night time quality is already dramatically better.. instead of trying to find a good compromise that works in day or night now I can dial er in.
 
Last edited by a moderator:
and of course there is never any consistency, only my PTZ took those commands tonight.. my other 3 Dahua's (IPC) all stayed in day mode.. so if that dont work for you try:

Code:
DAY PROFILE - /cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[0].NightOptions.SwitchMode=0
NIGHT PROFILE - /cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[0].NightOptions.SwitchMode=3

and here is an example showing how I have it implemented using a Lua script on my Automation Server: https://github.com/nayrnet/domoticz-scripts/blob/master/lua/script_time_ipc.lua

I am so damn happy with the results, night time quality is already dramatically better.. instead of trying to find a good compromise that works in day or night now I can dial er in.

ive done it by getting the sunrise sunset times and setting the sunrise sunset times on the camera as appropriate.
 
Hello,
I'm trying to develop a little nodeJS server as part of a bigger project.
I found your project online and used your code as basis.
The point is to get all the possible errors and failures like 'disk error','video loss',... but I can't find the solutions in the API responses.
Also you use a GET request: 'GET /cgi-bin/eventManager.cgi?action=attach&codes=[AlarmLocal,VideoMotion,VideoLoss,VideoBlind]' that isn't described in the API ,where did you find this?
Could you please help me out with this!

regards


ftp://ftp.wintel.fi/drivers/dahua/SDK-HTTP_ohjelmointi/DAHUA_IPC_HTTP_API_V1.00x.pdf
Section 6.6 on page 42 is the event handier
 
Wow, this is awesome! How difficult is this to trigger using blue iris? I have a blue iris schedule setup which is synced to sunrise/sunset times. It would be nice to be able to trigger the cameras to switch to day/night based on this same schedule.
 
  • Like
Reactions: drbenjamin
I tried to pull from the log but i have to fix the authentication first because it's full of loged in/out messages.
The V1.29 API does. section 6.6 is all about storage but I can't seem to get any response but the settings with a few different approaches
 
So, can anyone explain how to do this? I mean, I know he gave the line of code...but what do you do with that code? I've got Domoticz already set up...just trying to figure out how the hell to use it....
 
I tried to pull from the log but i have to fix the authentication first because it's full of loged in/out messages.
The V1.29 API does. section 6.6 is all about storage but I can't seem to get any response but the settings with a few different approaches
I was able to google up to api 1.56. see if its any different for you..

So, can anyone explain how to do this? I mean, I know he gave the line of code...but what do you do with that code? I've got Domoticz already set up...just trying to figure out how the hell to use it....
you need to add dummy hardware and dummy on/off switch (the brand you select doesnt matter) in domoticz. Then edit that switch and paste code into "on" and "off" actions. You'll need to experiment to find your config numbers. Mine were 0=day, 1=night, and 3=normal... different than what nayr posted.
 
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.
 
Last edited:
i'm playing with Domoticz with the Day /Night Profile and it works perfect with sunrise and sunset future.
is it possible to change the FPS settings also with http Api commands ? as an example : 25 FPS for Daytime and 15 FPS for night.
 
Last edited:
i'm playing with Domoticz with the Day /Night Profile and it works perfect with sunrise and sunset future.
is it possible to change the FPS settings also with http Api commands ? as an example : 25 FPS for Daytime and 15 FPS for night.

Looks like the camera won't save an FPS to the day/night profile, but you can change FPS via SetVideoEncodeConfig API command.

API details are here.
 
Hello Dragon, thank you for your help. This Api documentation I've already seen. But I am absolutely new in it. I have tried the following without success:

http://admin:passwort@xxx.xxx.xxx.xxx/cgi-bin/configManager.cgi?action=setConfig&VideoEncode[0].Encode[0].MainFormat[0].Video.FPS=15

did you give me an idea please what I do wrong ? Thank you ;-)

Try this:
Code:
http://admin:passwort@xxx.xxx.xxx.xxx/cgi-bin/configManager.cgi?action=setConfig&Encode[0].MainFormat[0].Video.FPS=15

It worked on my camera to set FPS to 15, but when I tried to set back to 10 it said OK but did nothing. So it may be bugged. Maybe you can work around the bug by setting additional options in the same URL (add something like &Encode[0].MainFormat[0].Video.GOP=10 to the end of the URL above and try adding additional options until it works - but it may never work since I'm just guessing at what the problem might be).
 
Last edited:
  • Like
Reactions: ewc1111
Hi Dragon, thank you very much for your help. I tried this and it works for me in Domoticz . so I can now configure 2 switches, one for the fps and a second for Gop. :)
 
Does someone have the API for NVR´s ? The IPC API seems to be different.