Switch Dahua Day/Night Profile via IPC HTTP API

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
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

Last edited by a moderator:

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
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:

psycik

Getting the hang of it
Joined
Dec 9, 2015
Messages
222
Reaction score
41
Location
Wellington, New Zealand
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.
 

psycik

Getting the hang of it
Joined
Dec 9, 2015
Messages
222
Reaction score
41
Location
Wellington, New Zealand
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
 

psycik

Getting the hang of it
Joined
Dec 9, 2015
Messages
222
Reaction score
41
Location
Wellington, New Zealand
I don't think the event handler has Disk errors. On seems to be video based events. You'll have to look for another Api call, or pull the events from the log.
 

Spooling

Getting the hang of it
Joined
Sep 26, 2015
Messages
158
Reaction score
48
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.
 
Joined
Apr 29, 2016
Messages
1
Reaction score
0
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
 

DavidDavid

Getting comfortable
Joined
Jan 29, 2017
Messages
605
Reaction score
267
Location
Ohio
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....
 

DarkHelmet

Getting the hang of it
Joined
Feb 26, 2017
Messages
167
Reaction score
66
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.
 

Dragon

Getting the hang of it
Joined
Mar 19, 2016
Messages
68
Reaction score
30
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:

ewc1111

Getting the hang of it
Joined
Jun 3, 2017
Messages
54
Reaction score
30
Location
Germany
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:

Dragon

Getting the hang of it
Joined
Mar 19, 2016
Messages
68
Reaction score
30
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.
 

Dragon

Getting the hang of it
Joined
Mar 19, 2016
Messages
68
Reaction score
30
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:

ewc1111

Getting the hang of it
Joined
Jun 3, 2017
Messages
54
Reaction score
30
Location
Germany
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. :)
 

TVT73

Pulling my weight
Joined
Aug 29, 2016
Messages
406
Reaction score
108
Location
Germany
Does someone have the API for NVR´s ? The IPC API seems to be different.
 

psycik

Getting the hang of it
Joined
Dec 9, 2015
Messages
222
Reaction score
41
Location
Wellington, New Zealand
Does someone have the API for NVR´s ? The IPC API seems to be different.
I think it's the same
GET_URL = 'http://{0}/cgi-bin/configManager.cgi?action=getConfig&name=VideoInOptions[{1}].NightOptions'

But instead of only being one night option, there's 1 per channel.
 
Top