Dahua day/night switch utility - DahuaSunriseSunset

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,666
Reaction score
14,005
Location
USA
Well in my experience the autoFocus command worked reliably with only one request.

The adjustFocus command is the unreliable one. This command requires both zoom and focus values. I settled on repeating it 5 times, waiting one second between each request. The 5th repeat may optionally be replaced by an autoFocus command.

So, these are the 4 possible courses of action which the DahuaSunriseSunset app may take for handling zoom and focus:

A) 1x autoFocus command
B) 5x adjustFocus commands, 1 second sleep between
C) 4x adjustFocus commands followed by 1x autoFocus command, 1 second sleep between
D) Do nothing.

Different numbers of repeats may work too. Those are just what I determined to be reliable for the camera models I tested against.
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
these are the 4 possible courses of action which the DahuaSunriseSunset app may take for handling zoom and focus
Perfect. I'll give these starting points a try with my Dahua api cameras:
(2) IPC-HDW5231R-ZE
(2) IPC-HDW2231R-ZS
 
Last edited:

hamsoplo

Getting the hang of it
Joined
Jun 8, 2014
Messages
144
Reaction score
55
Well in my experience the autoFocus command worked reliably with only one request.

The adjustFocus command is the unreliable one. This command requires both zoom and focus values. I settled on repeating it 5 times, waiting one second between each request. The 5th repeat may optionally be replaced by an autoFocus command.

So, these are the 4 possible courses of action which the DahuaSunriseSunset app may take for handling zoom and focus:

A) 1x autoFocus command
B) 5x adjustFocus commands, 1 second sleep between
C) 4x adjustFocus commands followed by 1x autoFocus command, 1 second sleep between
D) Do nothing.

Different numbers of repeats may work too. Those are just what I determined to be reliable for the camera models I tested against.
Is it possible to make this program continuously send zoom/focus commands every minute or so for cameras that lose focus by themselves?
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
So, these are the 4 possible courses of action which the DahuaSunriseSunset app may take for handling zoom and focus:

A) 1x autoFocus command
B) 5x adjustFocus commands, 1 second sleep between
C) 4x adjustFocus commands followed by 1x autoFocus command, 1 second sleep between
D) Do nothing.

Different numbers of repeats may work too. Those are just what I determined to be reliable for the camera models I tested against.
I've completed my testing and have settled on course 'B'. I had to experiment with the sleep duration and settled on 4 seconds. Anything less resulted in at least one of four out-of-focus cameras.

In case this helps anyone else, here's a few details about my approach...

1. To reduce the script run time, I settled on using master sleep duration. In a loop, I execute 1 adjustFocus command for each camera, then the sleep command, then repeat 4 more times. (I used the same Day Zoom, Day Focus, Night Zoom, Night Focus values that I configured into the DahauSunriseSunset tool.)

2. I added a commandline argument to optionally send the following 'zero-zero' command BEFORE executing method B. It proved handy in development when I was experimenting with shorter sleep durations (<3 seconds). These frequently left one or more of my cameras 'locked in' with a blurry image. When things were totally messed-up, starting at 'zero-zero' then executing method 'B' so far has worked every time.

Code:
/cgi-bin/devVideoInput.cgi?action=adjustFocus&focus=0&zoom=0
Thanks again bp2008!
 
Last edited:

BHj

n3wb
Joined
Jan 27, 2019
Messages
10
Reaction score
8
Location
Finland
Hi guys.

I have a Dahua DH-SD49225T-HN. I wanted to get better control over the IR leds, and did not really like having to mess around with the day and night mode. I am not sure if this will help you, but I experimented a bit and found the following things to work for my purpose. These are not documented in any doc I have seen, so thought I'd post here;

Set the IR leds to OFF
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Off

For the IR leds to be on, the camera has to be in B/W mode. This can be forced with
/cgi-bin/configManager.cgi?action=setConfig&VideoInDayNight[0][0].Mode=BlackWhite

..then the leds can be manually controlled with
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Manual&Lighting[0][0].FarLight[0].Light=50&Lighting[0][0].NearLight[0].Light=50

The SD49555 tas 6 IR leds, where nearlight (2leds) and farlight (4 leds) can be controlled separately. It seems that it might not be a good idea to use more than 100 in total.

IR has 2 auto modes
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Auto
and
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=ZoomPrio

Color mode back to Auto goes by
/cgi-bin/configManager.cgi?action=setConfig&VideoInDayNight[0][0].Mode=Brightness

May sometimes make sense to force to color via
/cgi-bin/configManager.cgi?action=setConfig&VideoInDayNight[0][0].Mode=Color
 
Last edited:

WoodenTop

n3wb
Joined
Dec 14, 2018
Messages
13
Reaction score
11
Location
UK
Also have a SD49225T-HN and I'm unable to fetch the focus/zoom settings using the tool (nothing happens and the fields stay blank). Log gives iasyncresult errors. The sunrise sunset switching works fine but I'd like to be able tockeep the two different focus settings for day/night.
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
Set the IR leds to OFF
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Off
Thanks @BHj! ... I’d love to hear how you discovered this ‘Lighting’ command. It's not in the API (v1.67), and I personally had no luck looking for it.

After experimenting today, here’s what I’ve learned for my Dahua varifocal cams (HDW2231R-ZS, HDW5231R-ZE).

GET
/cgi-bin/configManager.cgi?action=getConfig&name=Lighting
returns the following five settings:
table.Lighting[0][0].Correction=50
table.Lighting[0][0].MiddleLight[0].Angle=50
table.Lighting[0][0].MiddleLight[0].Light=50 <— Intensity
table.Lighting[0][0].Mode=Auto <— Mode
table.Lighting[0][0].Sensitive=3

The two bolded entries above correspond to the named controls in the NACL web plug-in.

IR Light Screenshot1.png

SET
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Auto —> SmartIR
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Manual —> Manual
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Off —> Off
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].MiddleLight[0].Light=50 —> Intensity

IR Light Screenshot2.png
 
Last edited:

Rockford622

Getting the hang of it
Joined
Feb 19, 2016
Messages
188
Reaction score
33
Thanks @BHj! ... I’d love to hear how you discovered this ‘Lighting’ command. It's not in the API (v1.67), and I personally had no luck looking for it.

After experimenting today, here’s what I’ve learned for my Dahua varifocal cams (HDW2231R-ZS, HDW5231R-ZE).

GET
/cgi-bin/configManager.cgi?action=getConfig&name=Lighting ... returns the following five settings:

table.Lighting[0][0].Correction=50
table.Lighting[0][0].MiddleLight[0].Angle=50
table.Lighting[0][0].MiddleLight[0].Light=50 <— Intensity
table.Lighting[0][0].Mode=Auto <— Mode
table.Lighting[0][0].Sensitive=3

The two bolded entries above correspond to the named controls in the NACL web plug-in.

View attachment 39442

SET
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Auto —> SmartIR
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Manual —> Manual
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Off —> Off
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].MiddleLight[0].Light=50 —> Intensity

View attachment 39443
Have you ever run across a way to read the status of the IR lights? I have a C# program running as a service I wrote, and use the same method that @bp2008 uses to calculate Sunrise and Sunset times, but that is not indicative of the camera's exact ambient light conditions. There is always a short period of time when my 2 -Z12 cameras have the wrong settings based on calculated sunrise and sunset times. Reading the IR lights status would be more accurate as to what settings the camera should use based on available light.
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
Reading the IR lights status would be more accurate as to what settings the camera should use based on available light.
This is a clever idea. I have not yet run across a way to read the status of the IR leds, but I’ll certainly keep it in mind while experimenting.
 
Joined
Aug 3, 2015
Messages
3,791
Reaction score
12,182
Location
Charlotte
Have you ever run across a way to read the status of the IR lights? I have a C# program running as a service I wrote, and use the same method that @bp2008 uses to calculate Sunrise and Sunset times, but that is not indicative of the camera's exact ambient light conditions. There is always a short period of time when my 2 -Z12 cameras have the wrong settings based on calculated sunrise and sunset times. Reading the IR lights status would be more accurate as to what settings the camera should use based on available light.
Believe it or don't, there's a subscription web service (Dark Sky API) to read the local ambient light status outdoors.
I saw this when configuring Home Assistant for sunrise/sunset, but didn't consider using it.
 
Last edited:

BHj

n3wb
Joined
Jan 27, 2019
Messages
10
Reaction score
8
Location
Finland
Thanks @BHj! ... I’d love to hear how you discovered this ‘Lighting’ command. It's not in the API (v1.67), and I personally had no luck looking for it.
Can't recall if it was using oldfashioned Wiresharking, or if I found those interpolating from the settings backup file. The settings backup file is essentially like an encoding of everything that can be set.
 

BHj

n3wb
Joined
Jan 27, 2019
Messages
10
Reaction score
8
Location
Finland
SET
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Auto —> SmartIR
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Manual —> Manual
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].Mode=Off —> Off
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].MiddleLight[0].Light=50 —> Intensity
In the DH-SD49225T-HN there are all in all 6 IR lights, of which the intensity for the 2 lowest ones are controlled via
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].NearLight[0].Light=xx
..and the 4 upper ones via
/cgi-bin/configManager.cgi?action=setConfig&Lighting[0][0].FarLight[0].Light=yy

The sum of xx and yy may never be more than 100 for some reason (set commands attempting that will fail), but can of course be lower, and if one is less the other can be more than 50 for more intensity on those lights.
 

BHj

n3wb
Joined
Jan 27, 2019
Messages
10
Reaction score
8
Location
Finland
This is a clever idea. I have not yet run across a way to read the status of the IR leds, but I’ll certainly keep it in mind while experimenting.
How about the /cgi-bin/configManager.cgi?action=getConfig&name=Lighting ?

I get (as example)

table.Lighting[0][0].Correction=50
table.Lighting[0][0].FarLight[0].Angle=0
table.Lighting[0][0].FarLight[0].Light=50
table.Lighting[0][0].MiddleLight[0].Light=0
table.Lighting[0][0].MiddleLight[1].Light=0
table.Lighting[0][0].Mode=Manual
table.Lighting[0][0].NearLight[0].Angle=0
table.Lighting[0][0].NearLight[0].Light=50
table.Lighting[0][0].NearLight[1].Light=0
table.Lighting[0][0].NearLight[100].Light=0
table.Lighting[0][0].Sensitive=3

but have not checked if the .Light values are set when the device is in auto mode... Sun is up now so can't check either at least right now.
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
The settings backup file is essentially like an encoding of everything that can be set.
Sweet! Thanks!!

For anyone interested in this topic, here's a way to parse the contents of the Dahua backup file into more human-readable format.
1. Open your Dahua camera in the NACL web plugin
2. Navigate to 'Import/Export' and create the backup file (like, DeviceConfig.backup)
3. Navigate to this file via Windows Explorer
4. Open the file in Windows Notepad
5. Select & copy all the text (Ctrl-A, Ctrl-C)
6. Open this website <JSON Formatter> (see image 1)
7. Paste the clipboard contents to the box labeled 'Option 1: Copy-paste your JSON string here'
8. Click the button 'FORMAT AS JSON IN NEW WINDOW'
9. Enjoy (see image 2)

PS - In step 7, I also tried "Option 2 (Or upload your JSON file)", but without success.

Image 1
JSON Formatter Input.com.png

Image 2
JSON Formatter Output.com.png
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
How about the /cgi-bin/configManager.cgi?action=getConfig&name=Lighting ?
I had the same thought and intended to experiment with this on my 2231 and 5231 cameras, but let it slip to the back burner... I'll try to play with it this weekend.
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
Believe it or don't, there's a subscription web service (Dark Sky API) to read the local ambient light status outdoors.
I am a frequent user of the darksky.net API and was a bit dismayed that I had somehow missed this :)

But unfortunately I cannot seem to find an ambient light status 'condition' listed in the current API documentation <here> ...
Can you take a look and let me know if perhaps I'm just overlooking it?
 
Last edited:
Joined
Aug 3, 2015
Messages
3,791
Reaction score
12,182
Location
Charlotte
I am a frequent user of the darksky.net API and was a bit dismayed that I had somehow missed this :)

But unfortunately I cannot seem to find an ambient light status 'condition' listed in the current API documentation <here> ...
Can you take a look and let me know if perhaps I'm just overlooking it?
I won't pay anyone for something I can do myself, more accurately. Built a couple of $20 ambient light sensors using the BH1750 module and Raspberry Pi Zero W. Used stock BH1750 code and a web.py wrapper to make it a self-contained web-server. Files are attached. I read these servers in HomeAssistant with a 'command line' sensor. The command is a simple 'curl http://192.168.1.xxx:8080' .

If you're a Home Assistant user, this is the configuration text from my configuration.yaml:
Code:
# Weather prediction
sensor:
#
# Ambient Light Sensor
#
  - platform: command_line
    name: Ambient Light 1
    scan_interval: 10
    unit_of_measurement: 'Lux'
    command: "curl http://192.168.1.nnn:8080/"
    command_timeout: 5
    value_template: '{{ value }}'
#
 

Attachments

Last edited:
As an Amazon Associate IPCamTalk earns from qualifying purchases.
Joined
Aug 3, 2015
Messages
3,791
Reaction score
12,182
Location
Charlotte
I am a frequent user of the darksky.net API and was a bit dismayed that I had somehow missed this :)

But unfortunately I cannot seem to find an ambient light status 'condition' listed in the current API documentation <here> ...
Can you take a look and let me know if perhaps I'm just overlooking it?
I probably mis-interpreted something someone else posted somewhere on the web, to be quite honest. :brainfart:
 

jaydeel

BIT Beta Team
Joined
Nov 9, 2016
Messages
1,126
Reaction score
1,237
Location
SF Bay Area
No problem... For others who might be interested in darksky.net, if you limit your API requests to once every 2 minutes (720x per day), it is totally free.

Several conditions it provides that I find useful are ‘cloudCover’, ‘precipIntensity’, ‘precipIntensityError’, ‘precipIntensityMax’, ’precipIntensityMaxTime’, and ‘precipProbability’. Storm watchers might like ‘nearestStormDistance’ and ‘nearestStormBearing’.

~~~~~
Pasted below is the pricing info from darksky.net.

Pricing is dead-simple.

  • The first 1,000 API requests you make every day are free of charge.
  • Every API request over the free daily limit costs $0.0001.
You are required to display the message “Powered by Dark Sky” that links to https://darksky.net/poweredby/ somewhere prominent in your app or service. If attribution isn't for you, email sales@darksky.net for details about white labeling.
 
Last edited:

luke duke

n3wb
Joined
Mar 10, 2016
Messages
14
Reaction score
16
Can someone help me figure this out?

I am using the utility, but it will only change my camera from day mode to night mode. It will not change it back to day mode at sunrise. If I reboot the camera, either manually or automatically, after sunrise it reboots with the correct settings (zoom/focus/day mode).
Dahua SunriseSunset settings.jpg
 
Top