Dahua day/night switch utility - DahuaSunriseSunset

omg, I was making it more complicated than that - got to open my eyes.
 
  • Like
Reactions: sebastiantombs
I am running a cam with firmware from 2021-07-09 and its API for setting sunrise and sunset is working fine.

View attachment 110032

I am not using the DahuaSunriseSunset service. Instead I am having Blue Iris send the http requests using its own scheduler.

It is a little hacky to set up in Blue Iris because you can't simply schedule a custom HTTP request. But you can modify PTZ presets in Blue Iris to send custom HTTP requests, and you can schedule calls to those presets to happen at times relative to sunrise and sunset.

The procedure is:

1. In Blue Iris, go to Camera Properties > PTZ/Control tab.
2. Enable PTZ control (if your cam doesn't have motorized pan/tilt/zoom then just pick "Dahua New V5" from the dropdown).
3. Click Edit presets.
4. Type Day Profile into the description of one of the presets.
5. Click "On call" button, then add a "Web request or MQTT" action.
6. Configure the URL as user:password@192.168.0.1/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=0, replacing user, password, and 192.168.0.1 with your own camera credentials and address.
7. Repeat steps 4-6 on a different preset, but with the description Night Profile and change the 0 at the end of the URL to 1 like this: user:password@192.168.0.1/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1

View attachment 110037

Finally you can proceed to scheduling calls to your presets:

8. Go to camera properties > Schedule tab > Events schedule.

Add each event at the desired time:

View attachment 110038

In this example, I configured it so the camera goes to Day mode 1 hour before sunrise. I configured this weeks ago and Blue Iris has automatically adjusted the exact scheduled time as the sunrise time changes daily.

View attachment 110039
This is an amazing idea. Is there a risk to having the username and password sent in clear text like that? Someone snooping the network or something? I suppose if there is a VLAN or separate network it might be okay?
 
This is an amazing idea. Is there a risk to having the username and password sent in clear text like that? Someone snooping the network or something? I suppose if there is a VLAN or separate network it might be okay?

No, it isn't sent to the camera the way it is typed into the URL field. I am pretty sure Dahua cameras use "digest authentication" which does not transfer the password in plain text.

Even if it was plain text, there is almost zero risk in sending a camera's credentials over your LAN in plain text.
 
This is an amazing idea. Is there a risk to having the username and password sent in clear text like that? Someone snooping the network or something? I suppose if there is a VLAN or separate network it might be okay?
If someone is snooping on your network you have way bigger problems than your dahua cam password. Moreover, think of an ipcamera password as a do not enter sign. It will only keep semi-honest folks out. I yearn for the days that the cameras allowed me to leave the default password active.
 
No, it isn't sent to the camera the way it is typed into the URL field. I am pretty sure Dahua cameras use "digest authentication" which does not transfer the password in plain text.

Even if it was plain text, there is almost zero risk in sending a camera's credentials over your LAN in plain text.
My password manager and even copy/paste won't get the passwords into the Dahua password box, which is really irritating!!

As @fenderman said, if someone has that level of access, you have other issues you should be concerned about.
 
My password manager and even copy/paste won't get the passwords into the Dahua password box, which is really irritating!!
...

Hmm... are you right clicking to access the copy/paste commands?

I regularly use ctrl+v to paste the password into the Dahua camera web login with much success.

Maybe it's a limitation of the firmware version
 
I have a logitech keyboard and setup a couple of the extra 'G' keys along the left edge to paste in the user and password. Same thing could be done using autohotkey and the F keys for example
 
Thank you so much for creating this and I been using this utility for my Cams and have been working great,

However Recently helped a neighbor setup his system as well he went the NVR route however, I am still trying to see if I could somehow dial his camera profile, zoom and focus based off sunset sunrise.

The solution from this post will require a PC to be constantly on, However I was wondering has anyone figured out how can we run this maybe on a small device like raspberry pi ? or something similar which is small enough just for this utility ??

Only thing I think I came across on google search where a user seem to be running ESP8266 along with ambient sensor to trigger profile based off sunset sunrise... Again I have no idea how will I go about setting that Maybe someone here have something similar ?


 
  • Like
Reactions: EMPIRETECANDY
One option is to use a home automation controller provided it allows for HTTP GET functions within its rules structure.

One such device is the Hubitat C7 hub as it will control Dahua cameras with a Dahua NVR using the correct HTTP API. Plug the hub into the LAN side of your router along with the NVR. And program the hub, using the built in rules machine to create a sunup and sunset rule.

To change a HFW-5849 camera from B/W to color at sunrise I use the following HTTP call within the rules machine.

Code:
http://username:password@192.168.1.108:80/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[2].NightOptions.SwitchMode=0&VideoInOptions[2].NightOptions.DayNightColor=0
To test for HTTP access, one can use a GET statement with a browser to display settings. The below will display the names of the cameras connected to the NVR.
Code:
http://192.168.1.108/cgi-bin/configManager.cgi?action=getConfig&name=ChannelTitle
Have been using the hub for both Dahua camera control and home automation. It works well for both.
 
Last edited:
Hmm... are you right clicking to access the copy/paste commands?

I regularly use ctrl+v to paste the password into the Dahua camera web login with much success.

Maybe it's a limitation of the firmware version

I use a FireFox browser to access my cameras, and it comes with a password manager.
 
  • Like
Reactions: tech101
One option is to use a home automation controller provided it allows for HTTP GET functions within its rules structure.

One such device is the Hubitat C7 hub as it will control Dahua cameras with a Dahua NVR using the correct HTTP API. Plug the hub into the LAN side of your router along with the NVR. And program the hub, using the built in rules machine to create a sunup and sunset rule.

To change a HFW-5849 camera from B/W to color at sunrise I use the following HTTP call within the rules machine.

Code:
http://username:password@192.168.1.108:80/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[2].NightOptions.SwitchMode=0&VideoInOptions[2].NightOptions.DayNightColor=0
To test for HTTP access, one can use a GET statement with a browser to display settings. The below will display the names of the cameras connected to the NVR.
Code:
http://192.168.1.108/cgi-bin/configManager.cgi?action=getConfig&name=ChannelTitle
Have been using the hub for both Dahua camera control and home automation. It works well for both.

Hello,

Would you mind sharing both the day and night commands for a Dahua camera?
 
  • Like
Reactions: tech101
These settings are used for the Dahua HFW-5849 T1-ASE-LED or IPC-Color 4K-X camera. This camera does not have a day/night setting sensor to change modes at sunset or sunrise.

The camera has a schedule to set the time in monthly increments for sunset/sunrise. In Alaska, during this time of year, the sun up/down times change by 5 minutes and 40 seconds per day. Thus the need for a better control system. If using BI, then the use of their sun up/down program add on would be a nice alternative.

The below HTTP is used to alter the full time day and the full time night schedules. These are normally set on a 24x7 basis. However, when using the Hubitat C7 the full time day and full time night modes can be activated as needed.

Other threads, on this site, have also addressed this issue. These use a different set of HTTP calls to perform similar actions depending on the camera firmware version.

Color to B/W - Sunset
Code:
http://username:password@192.168.1.108:80/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[2].NightOptions.SwitchMode=3&VideoInOptions[2].NightOptions.DayNightColor=2

B/W to Color - Sunrise
Code:
http://username:password@192.168.1.108:80/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[2].NightOptions.SwitchMode=0&VideoInOptions[2].NightOptions.DayNightColor=0

Note: The [2] is the camera that is plugged into the RJ-45 DVR port 3. In this case cameras, as far as logic is concerned, are numbered as N-1.

Definitions

NightOptions.SwitchMode

0: NoSwitch, always use day options.
1: Switch depends on brightness.
2: Switch depends on time, switch to NightOptions
when time is after sunset time and before sunrise.
3: NoSwitch, always use NightOptions.
4: No switch, always use NormalOptions.

NightOptions.DayNightColor
0: always multicolor
1: autoswitch along with brightness
2: always monochrome
 
  • Like
Reactions: DLONG2
Thank you so much for creating this and I been using this utility for my Cams and have been working great,

However Recently helped a neighbor setup his system as well he went the NVR route however, I am still trying to see if I could somehow dial his camera profile, zoom and focus based off sunset sunrise.

The solution from this post will require a PC to be constantly on, However I was wondering has anyone figured out how can we run this maybe on a small device like raspberry pi ? or something similar which is small enough just for this utility ??

Only thing I think I came across on google search where a user seem to be running ESP8266 along with ambient sensor to trigger profile based off sunset sunrise... Again I have no idea how will I go about setting that Maybe someone here have something similar ?


@Alaska Country nailed it. I've been doing this with a Raspberry Pi for years. Just a simple cron job that executes the html calls he posted during sunrise/sunset.
 
  • Love
Reactions: tech101
@Alaska Country nailed it. I've been doing this with a Raspberry Pi for years. Just a simple cron job that executes the html calls he posted during sunrise/sunset.

Thank you @biggen I think just found your post with instructions now How to get it on Rasberry PI ..


 
Has anyone had any issues getting this Sunrise/Sunset switching to work correctly on the EMPIRETECANDY / Dahua 5442 cameras that are running the latest (Feb. 18, 2022) firmware that just came out this week?

Unfortunately I am setting this up for the first time, so I don't know if the problems I am having are due to this newest firmware behaving differently, or just some other setup mistake/typo of my own doing. I followed the directions explicitly from the first post of this thread (using the more recent native B.I. method, not the old software utility), and I do have the cameras set to "Full time" and Always Enable "Day" in Profile Management. My daytime camera settings are forced to Color mode, and Night settings are forced to B/W, so the changeover should be obvious, but I am currently seeing only color mode regardless of time.

The B.I. logs indicate that each of the cameras do see the "Event: PTZ Preset 2 (2202)" happening, followed by the "Web: HTTP/1.1 200 OK" response at Sunset, so it would seem that they should be switching to B/W at that point, but it doesn't happen. I would think that would also indicate that my string with the Camera IPs, user/password info, and "0" or "1" at the end, is being read and interpreted correctly, but perhaps these cameras on the new firmware want to see a different number at the end (some cameras seem to need a "3", right?).

Any suggestions on other troubleshooting steps that I should take?
 
You can try the URL in a web browser and see the full response.

If you want full API documentation: latest Version of DAHUA HTTP API FOR IPC Documentation ??
Interesting, running the command in a browser DID immediately switch the camera to the Night profile and B/W. Odd that I am seeing the commands run in the B.I. log with the "Web: HTTP/1.1 200 OK " response at the appropriate times, but nothing happens there.
 
This utility doesn't go into the BI logs, so you must be seeing something else. Look at the log file for this utility.

Or as an alternative run this API command directly in BI based on profile.
 
This utility doesn't go into the BI logs, so you must be seeing something else. Look at the log file for this utility.

Or as an alternative run this API command directly in BI based on profile.
Yes, as I mentioned previously, I am not running the old (software based) utility, I am using the newer, currently recommended "native" B.I. API PTZ/ Camera Scheduler based method now outlined in post #1 of this thread, so yes, I do see some logging in B.I. as detailed above.