Switch Dahua Day/Night Profile via IPC HTTP API

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....
Ok I've figured it out now. In Domoticz go to Setup --> More Options --> Events

Then make a new Time event and input the code from @nayr's github. Then adjust what is needed for your specific situation like login's and IP addresses.

Thanks for this @nayr

Also the code from his second post seemed to work for me. I just made my one camera into night mode, then pasted the code into a browser to force it to day mode and checked it. Beats waiting for sunrise or sunset to come around to see what code will work for my cameras. But now tonight I"ll have to check to see if Domoticz is actually making it work.
 
For my Z5, this is what I see using "/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[0].NightOptions.SwitchMode=x"

1 = No profile management
2 = Schedule
3 = Full Time Night
4 = Normal
 
Last edited:
It really depends on what you're doing with it. I'm no photography expert by any means, but I have found with security cams you have to keep a tight leash on shutter speed and noise reduction to stop motion blur. Here is an example of what seems to work well for me at the moment.

My Z5 is used for LPR at 80-100ft with full zoom in (near zero ambient light at night):
Item: Day/Night
Shutter: 1/1000 / 1/1000
Aperture: 50/72
Backlight: HLC/HLC
3DNR: off/off
Gain: 0-50/0-40
Color: bw/bw

My Starlight varifocal turret is used for faces at ~10ft with full zoom out (fair amount of ambient light at night):
Item: Day/Night
Shutter: 1/1000 / 1/500
Aperture: auto/auto
Backlight: WDR/WDR
3DNR: off/5
Gain: 0-100/0-100
Color: color/bw

In general I start by minimizing shutter time and 3DNR, then I adjust aperture and gain to suit. Too slow on the shutter and/or too much 3DNR will result in motion blur. Dahua's default and auto settings are terrible in this regard. Also, with LPR the plates can be very reflective with IR, and gain has to be reduced to get the correct exposure (otherwise the letters/numbers get washed out). With the varifocal the auto aperture and gain seem to perform decent when there are spotty clouds etc, and at night so I just left those alone.
 
  • Like
Reactions: AndrewUrb
How about iris setting?
 
It depends on the cameras involved.

Like the OP of this thread, I've got a bunch of Dahua starlight cams. They all have similar html get commands based on the generic Dahua HTML API. First I had to go in to each cam and setup both day and night modes according to my previous post, and set them to either "day" or "night" ('manual' condition mode), instead of auto or scheduled. Once that was done, to get BI switching between day/night modes for each camera, I selected "Custom HTML" on the PTZ tab of the camera. Then I 'edit'ed, select the desired button for day mode (I chose 'IR off', but you can use whatever you like... Preset1 for example) and enter the HTML command in the 'url' box. Likewise I added the night mode command to 'IR off'. So for my Dahuas, the custom html PTZ urls I added to BI are precisely:

Dahua Starlight Day mode (BI IR off button):
/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=0

Dahua Starlight Night mode (BI IR on button):
/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1

One more if you want to switch your Dahua to 'normal' mode:
/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=2

...similarly I edited the "zoom in" custom html button for my lpr cam like this:

Dahua Starlight 'refocus' (BI zoom in button):
/cgi-bin/devVideoInput.cgi?action=adjustFocus&focus=0.074129&zoom=1.0

An academic example for some camera that is zoomed almost half way in:
/cgi-bin/devVideoInput.cgi?action=adjustFocus&focus=0.074129&zoom=0.45

I hope that made sense. If you have ever played with get commands in your browser, you'll notice the first part is missing from the above lines "http://user: password@ip". BI is smart enough to take care of the busy work for you (BI already got that info when you added the camera earlier). BI will do this for any cam, so just leave it out of your url entry.

For other cameras, many of them will have their specific get urls published somewhere online. For example these forums contain lots of discussion on get urls for Hikvision and Foscam, as well as Dahua. You'll need this info to do anything with BI custom html stuff.

You can do a lot of cool stuff with html get commands using this method in BI. With the Dahua API, you can do pretty much anything you could do from the camera webui... adjust shutter, aperture, schedules, network settings, take snapshots, download files... only thing I haven't seen done is adjusting IVS with html commands (easy enough to do manually in the webui, but it's in the API docs if anyone gets really feisty about automated IVS). Once those custom buttons are programmed, if you go to the camera's event schedule in BI, you can tell it to send any command at any time you like. This is where BI's handling of daylight savings and sunrise/sunset really comes in handy. You can even dig deeper and use scripts to fire multiple commands with the BI PTZ presets... referencing text files that are live updated by some other system/script/app. That's beyond the scope of this thread though.

Kevin
 
Last edited:
Unfortunately I'm am still unable to find a NVR API. If I need to switch the config settings of NVR 5x or 4x 4ks2 Series nothing happens. Focus is possible with &channel=X but the missing channel option is a problem. So please, if someone has the ability to provide us the http API for nvrs it would be really helpful.

Or does someone has used the config switch from http?
 
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.
I saw it, but it was not visible to me where you use the channel option. So that means, that inside [] of VideoInOptions we choose the channel number from 1-x? and 0=direct use without NVR?

So this should be working for channel 1 switching to day config?:
/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[1].Config[1]=0 #day config
 
Code:
* Connected to 192.168.10.5 (192.168.10.5) port 80 (#0)
* Server auth using Digest with user 'admin'
> GET /cgi-bin/configManager.cgi?action=setConfig&VideoInMode[1].Config[1]=0 HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 192.168.10.5
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< WWW-Authenticate: Digest realm="Login to XXX", qop="auth", nonce="XXX", opaque="XXX"
< Connection: close
< CONTENT-LENGTH: 0
<
* Closing connection 0
* Issue another request to this URL: 'http://192.168.10.5/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[1].Config[1]=0'
* Hostname was found in DNS cache
*   Trying 192.168.10.5...
* Connected to 192.168.10.5 (192.168.10.5) port 80 (#1)
* Server auth using Digest with user 'admin'
> GET /cgi-bin/configManager.cgi?action=setConfig&VideoInMode[1].Config[1]=0 HTTP/1.1
> Authorization: Digest username="XXX", realm="Login to XXX", nonce="211735594", uri="/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[1].Config[1]=0", cnonce="XXX=", nc=00000001, qop=auth, response="XXX", opaque="XXX"
> User-Agent: curl/7.38.0
> Host: 192.168.10.5
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-type: text/plain;charset=utf-8
< CONNECTION: close
< CONTENT-LENGTH: 4
<
OK
* Closing connection 1
Still no switching. I can chose what I want inside []
 
I did missunderstand your hint. With your api request you will receive all possible configs and settings for "NightOptions" and so on. . But am I blind? I still see no value for the config or which parameter allows switching the config.
Where did you find your command?
Code:
http://192.168.10.5/cgi-bin/configManager.cgi?action=getConfig&name=VideoInOptions[1]
Code:
> User-Agent: curl/7.38.0
> Host: 192.168.10.5
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-type: text/plain;charset=utf-8
< CONNECTION: close
< CONTENT-LENGTH: 2819
<
table.VideoInOptions[1].AntiFlicker=0
table.VideoInOptions[1].AutoSyncPhase=false
table.VideoInOptions[1].Backlight=0
table.VideoInOptions[1].BacklightRegion[0]=3096
table.VideoInOptions[1].BacklightRegion[1]=3096
table.VideoInOptions[1].BacklightRegion[2]=5096
table.VideoInOptions[1].BacklightRegion[3]=5096
table.VideoInOptions[1].ColorTemperatureLevel=100
table.VideoInOptions[1].DayNightColor=1
table.VideoInOptions[1].DayNightSensitivity=2
table.VideoInOptions[1].DayNightSwitchDelay=6
table.VideoInOptions[1].DoubleExposure=0
table.VideoInOptions[1].DuskOptions.ExternalSyncPhase=125
table.VideoInOptions[1].ExposureIris=50
table.VideoInOptions[1].ExposureMode=0
table.VideoInOptions[1].ExposureSpeed=0
table.VideoInOptions[1].ExposureValue1=0
table.VideoInOptions[1].ExposureValue2=40
table.VideoInOptions[1].ExternalSync=0
table.VideoInOptions[1].ExternalSyncPhase=125
table.VideoInOptions[1].FlashControl.Mode=0
table.VideoInOptions[1].FlashControl.Pole=0
table.VideoInOptions[1].FlashControl.PreValue=40
table.VideoInOptions[1].FlashControl.Value=0
table.VideoInOptions[1].Flip=false
table.VideoInOptions[1].FocusMode=0
table.VideoInOptions[1].FocusRect[0]=0
table.VideoInOptions[1].FocusRect[1]=0
table.VideoInOptions[1].FocusRect[2]=8191
table.VideoInOptions[1].FocusRect[3]=8191
table.VideoInOptions[1].Gain=50
table.VideoInOptions[1].GainAuto=true
table.VideoInOptions[1].GainBlue=50
table.VideoInOptions[1].GainGreen=50
table.VideoInOptions[1].GainMax=50
table.VideoInOptions[1].GainMin=0
table.VideoInOptions[1].GainRed=50
table.VideoInOptions[1].GlareInhibition=0
table.VideoInOptions[1].InfraRed=false
table.VideoInOptions[1].InfraRedLevel=0
table.VideoInOptions[1].IrisAuto=true
table.VideoInOptions[1].IrisAutoSensitivity=50
table.VideoInOptions[1].Mirror=false
table.VideoInOptions[1].NightOptions.AntiFlicker=0
table.VideoInOptions[1].NightOptions.Backlight=0
table.VideoInOptions[1].NightOptions.BacklightRegion[0]=3096
table.VideoInOptions[1].NightOptions.BacklightRegion[1]=3096
table.VideoInOptions[1].NightOptions.BacklightRegion[2]=5096
table.VideoInOptions[1].NightOptions.BacklightRegion[3]=5096
table.VideoInOptions[1].NightOptions.BrightnessThreshold=50
table.VideoInOptions[1].NightOptions.DayNightColor=1
table.VideoInOptions[1].NightOptions.DayNightSensitivity=2
table.VideoInOptions[1].NightOptions.DayNightSwitchDelay=6
table.VideoInOptions[1].NightOptions.ExposureIris=50
table.VideoInOptions[1].NightOptions.ExposureMode=0
table.VideoInOptions[1].NightOptions.ExposureSpeed=0
table.VideoInOptions[1].NightOptions.ExposureValue1=0
table.VideoInOptions[1].NightOptions.ExposureValue2=40
table.VideoInOptions[1].NightOptions.ExternalSyncPhase=125
table.VideoInOptions[1].NightOptions.Flip=false
table.VideoInOptions[1].NightOptions.Gain=50
table.VideoInOptions[1].NightOptions.GainAuto=true
table.VideoInOptions[1].NightOptions.GainBlue=50
table.VideoInOptions[1].NightOptions.GainGreen=50
table.VideoInOptions[1].NightOptions.GainMax=50
table.VideoInOptions[1].NightOptions.GainMin=0
table.VideoInOptions[1].NightOptions.GainRed=50
table.VideoInOptions[1].NightOptions.GlareInhibition=0
table.VideoInOptions[1].NightOptions.InfraRed=false
table.VideoInOptions[1].NightOptions.InfraRedLevel=0
table.VideoInOptions[1].NightOptions.IrisAuto=true
table.VideoInOptions[1].NightOptions.IrisAutoSensitivity=50
table.VideoInOptions[1].NightOptions.Mirror=false
table.VideoInOptions[1].NightOptions.Profile=3
table.VideoInOptions[1].NightOptions.ReferenceLevel=50
table.VideoInOptions[1].NightOptions.Rotate90=0
table.VideoInOptions[1].NightOptions.SmartIRExposure=false
table.VideoInOptions[1].NightOptions.SunriseHour=0
table.VideoInOptions[1].NightOptions.SunriseMinute=0
table.VideoInOptions[1].NightOptions.SunriseSecond=0
table.VideoInOptions[1].NightOptions.SunsetHour=23
table.VideoInOptions[1].NightOptions.SunsetMinute=59
table.VideoInOptions[1].NightOptions.SunsetSecond=59
table.VideoInOptions[1].NightOptions.SwitchMode=0
table.VideoInOptions[1].NightOptions.TemporaryConfigs.AntiFlicker=0
table.VideoInOptions[1].NightOptions.TemporaryConfigs.ExposureMode=0
table.VideoInOptions[1].NightOptions.TemporaryConfigs.ExposureValue1=0.100000
table.VideoInOptions[1].NightOptions.TemporaryConfigs.ExposureValue2=80
table.VideoInOptions[1].NightOptions.TemporaryConfigs.GainMax=50
table.VideoInOptions[1].NightOptions.TemporaryConfigs.GainMin=10
table.VideoInOptions[1].NightOptions.WhiteBalance=Auto
table.VideoInOptions[1].NightOptions.WideDynamicRange=0
table.VideoInOptions[1].NightOptions.WideDynamicRangeMode=0
table.VideoInOptions[1].NormalOptions.AntiFlicker=0
table.VideoInOptions[1].NormalOptions.Backlight=0
table.VideoInOptions[1].NormalOptions.BacklightRegion[0]=3096
table.VideoInOptions[1].NormalOptions.BacklightRegion[1]=3096
table.VideoInOptions[1].NormalOptions.BacklightRegion[2]=5096
table.VideoInOptions[1].NormalOptions.BacklightRegion[3]=5096
table.VideoInOptions[1].NormalOptions.BrightnessThreshold=50
table.VideoInOptions[1].NormalOptions.DayNightColor=1
table.VideoInOptions[1].NormalOptions.DayNightSensitivity=2
table.VideoInOptions[1].NormalOptions.DayNightSwitchDelay=6
table.VideoInOptions[1].NormalOptions.ExposureIris=50
table.VideoInOptions[1].NormalOptions.ExposureMode=0
table.VideoInOptions[1].NormalOptions.ExposureSpeed=0
table.VideoInOptions[1].NormalOptions.ExposureValue1=0
table.VideoInOptions[1].NormalOptions.ExposureValue2=40
table.VideoInOptions[1].NormalOptions.ExternalSyncPhase=125
table.VideoInOptions[1].NormalOptions.Flip=false
table.VideoInOptions[1].NormalOptions.Gain=50
table.VideoInOptions[1].NormalOptions.GainAuto=true
table.VideoInOptions[1].NormalOptions.GainBlue=50
table.VideoInOptions[1].NormalOptions.GainGreen=50
table.VideoInOptions[1].NormalOptions.GainMax=50
table.VideoInOptions[1].NormalOptions.GainMin=0
table.VideoInOptions[1].NormalOptions.GainRed=50
table.VideoInOptions[1].NormalOptions.GlareInhibition=0
table.VideoInOptions[1].NormalOptions.InfraRed=false
table.VideoInOptions[1].NormalOptions.InfraRedLevel=0
table.VideoInOptions[1].NormalOptions.IrisAuto=true
table.VideoInOptions[1].NormalOptions.IrisAutoSensitivity=50
table.VideoInOptions[1].NormalOptions.Mirror=false
table.VideoInOptions[1].NormalOptions.Profile=0
table.VideoInOptions[1].NormalOptions.ReferenceLevel=50
table.VideoInOptions[1].NormalOptions.Rotate90=0
table.VideoInOptions[1].NormalOptions.SmartIRExposure=false
table.VideoInOptions[1].NormalOptions.SunriseHour=0
table.VideoInOptions[1].NormalOptions.SunriseMinute=0
table.VideoInOptions[1].NormalOptions.SunriseSecond=0
table.VideoInOptions[1].NormalOptions.SunsetHour=23
table.VideoInOptions[1].NormalOptions.SunsetMinute=59
table.VideoInOptions[1].NormalOptions.SunsetSecond=59
table.VideoInOptions[1].NormalOptions.SwitchMode=0
table.VideoInOptions[1].NormalOptions.TemporaryConfigs.AntiFlicker=0
table.VideoInOptions[1].NormalOptions.TemporaryConfigs.ExposureMode=0
table.VideoInOptions[1].NormalOptions.TemporaryConfigs.ExposureValue1=0.100000
table.VideoInOptions[1].NormalOptions.TemporaryConfigs.ExposureValue2=80
table.VideoInOptions[1].NormalOptions.TemporaryConfigs.GainMax=50
table.VideoInOptions[1].NormalOptions.TemporaryConfigs.GainMin=10
table.VideoInOptions[1].NormalOptions.WhiteBalance=Auto
table.VideoInOptions[1].NormalOptions.WideDynamicRange=0
table.VideoInOptions[1].NormalOptions.WideDynamicRangeMode=0
table.VideoInOptions[1].ReferenceLevel=50
table.VideoInOptions[1].ReferenceLevelEnable=false
table.VideoInOptions[1].Rotate90=0
table.VideoInOptions[1].SignalFormat=Inside
table.VideoInOptions[1].SmartIRExposure=false
table.VideoInOptions[1].Snapshot.ColorTemperatureLevel=50
table.VideoInOptions[1].Snapshot.ExposureSpeed=0
table.VideoInOptions[1].Snapshot.ExposureValue1=0
table.VideoInOptions[1].Snapshot.ExposureValue2=40
table.VideoInOptions[1].Snapshot.Gain=50
table.VideoInOptions[1].Snapshot.GainAuto=true
table.VideoInOptions[1].Snapshot.GainBlue=50
table.VideoInOptions[1].Snapshot.GainGreen=50
table.VideoInOptions[1].Snapshot.GainRed=50
table.VideoInOptions[1].Snapshot.WhiteBalance=Disable
table.VideoInOptions[1].SwitchMode=0
table.VideoInOptions[1].TemporaryConfigs.AntiFlicker=0
table.VideoInOptions[1].TemporaryConfigs.ExposureMode=0
table.VideoInOptions[1].TemporaryConfigs.ExposureValue1=0.100000
table.VideoInOptions[1].TemporaryConfigs.ExposureValue2=80
table.VideoInOptions[1].TemporaryConfigs.GainMax=50
table.VideoInOptions[1].TemporaryConfigs.GainMin=10
table.VideoInOptions[1].WhiteBalance=Auto
table.VideoInOptions[1].WideDynamicRange=0
table.VideoInOptions[1].WideDynamicRangeMode=0

* Closing connection 1
with this command
Code:
/cgi-bin/configManager.cgi?action=getConfig&name=VideoInMode[1]
I receive
Code:
table.VideoInMode[1].Config[0]=0
table.VideoInMode[1].Mode=0
table.VideoInMode[1].TimeSection[0][0]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[0][1]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[0][2]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[0][3]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[0][4]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[0][5]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[1][0]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[1][1]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[1][2]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[1][3]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[1][4]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[1][5]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[2][0]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[2][1]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[2][2]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[2][3]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[2][4]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[2][5]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[3][0]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[3][1]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[3][2]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[3][3]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[3][4]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[3][5]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[4][0]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[4][1]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[4][2]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[4][3]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[4][4]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[4][5]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[5][0]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[5][1]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[5][2]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[5][3]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[5][4]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[5][5]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[6][0]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[6][1]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[6][2]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[6][3]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[6][4]=0 00:00:00-23:59:59
table.VideoInMode[1].TimeSection[6][5]=0 00:00:00-23:59:59
* Closing connection 1
 
Is it just me or does the day/night profile settings get mixed up when using the api like this?
 
I played around with Config[0]=1 and also with Mode=1. My NVR is still on config files "config1".
I am sure on the 4xxx-x-4ks2 models we have a big profile problem. Playing with on cam day/night mixed with config 1-3 from nvr causes undefined states.

@ZyBeR Do you use an nvr or only a cam?

@Buttan Butt
dzVents uses the same line for ipc only. No NVR Channel select options.
openURL(camLogin..'@'..hostName..'.'..CAM_DOMAIN..'/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[0].NightOptions.SwitchMode='..newValue)
 
So you use no NVR and/or the cams are not connected to the internal nvr poe switch. For POE NVr´s its not possible to communicate directly to the cams. They use a different subnet like 10.0.x.x
 
I'm doing the same with HomeAssistant. I'm also using the cam IVS tripswires as HomeAssistant sensors. What other ways do you use the cams with HomeAssistant?
Interesting! I'm just switching profiles. How do you setup IVS-sensors in HA?
 
Interesting! I'm just switching profiles. How do you setup IVS-sensors in HA?

Original script: https://i.botox.bz/watch.py

Thread discussing it: Trigger blue iris with IVS?

My modified script: dahua-watch/watch.py at master · johnnyletrois/dahua-watch · GitHub

Send a MQTT message with the python script, have HomeAssistant subscribe to the MQTT topic, and connect that to a binary_sensor in HomeAssistant.

I don't really know what I'm doing, but I managed to make it work. Someone who knows python could easily turn the python script into a HomeAssistant component, which would be awesome.