Change Day Schedule on Dahua IP Camera via Dahua API

JwBayTech

n3wb
Jul 21, 2023
1
0
United States
Hello there,

--- Below is code that works (obviously, I removed the IP address and authentication) ---

Command:
curl --digest -X GET "http://<ip>/cgi-bin/configManager.cgi?action=getConfig&name=VideoInMode"

Output:

table.VideoInMode[0].Config[0]=0
table.VideoInMode[0].Config[1]=1
table.VideoInMode[0].Mode=1
table.VideoInMode[0].TimeSection[0][0]=1 10:00:00-16:00:00
table.VideoInMode[0].TimeSection[0][1]=0 00:00:00-24:00:00
table.VideoInMode[0].TimeSection[0][2]=0 00:00:00-24:00:00
table.VideoInMode[0].TimeSection[0][3]=0 00:00:00-24:00:00
table.VideoInMode[0].TimeSection[0][4]=0 00:00:00-24:00:00

QUESTION

How can I modify the schedule shown in table.VideoInMode[0].TimeSection[0][0]=1 10:00:00-16:00:00 via api requests?


IMPORTANT: I have already confirmed that the following command works in changing mode, but nothing I've found gets me the ability to change the schedule itself.
curl --digest -X GET "http://<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Mode=2"

Thanks for any and all help!
 
It took me a lot of trial and error and testing but I finally found this to work on the newest Web5.0 with my newer PTZ cam. This method does not work for Web4.0

"http://<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][0]=10:00:00-16:00:00 Day"

I found you have to adjust the Night settings as well to make it work correctly as such:

"http://<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][1]=00:00:00-09:59:59 Night"
"http://<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][2]=10:00:01-24:00:00 Night"

The first [ ] after "TimeSectionV2" is the month integer where January is 0 and so on.
The second [ ] denotes a new block on the schedule. I found they dont have to be in any order.

I am doing this under customized scene.

I adjust my schedule daily based on the sunrise and sunset using a customized script as you can see from the attached pic

schedule.jpg
 
  • Love
Reactions: Alaska Country
Appreciate your time and effort to come up with an API to switch Time Plan Settings. It would be nice if the HTTP API would address these issues, but the document does not.

Using the following PTZ for day/night operations - Web 5
Device Model: Dahua SD5A425XA-HNR (PTZ5A4M-25X)
Algorithm Version: 2.0.2
PTZ Version: V2.401.0000001.42.RHNCT_220811_42531
Web Version: V5.01.0.1314701.TA

The GET statement correctly reports the camera data for the VideoInMode. The Day API works correctly and changes the time plan settings as indicated for the PTZ.

Code:
http://admin:password@192.168.55.156/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][0]=00:00:00-24:00:00 Day

Note: For my use in Hubitat (C7 Hub) , the ampersand has to be escaped. "^&" and the quote marks are not part of the escape. For a Window's BAT file, the ampersand does not have to be escaped, but the space next to the word Day needs to be escaped. ("%20" for the escape code - again no quotes)

The Night part of the API does not work. When changing the block from zero to one (TimeSectionV2[0][1]) the browser reports an error in FireFox. However, if the V2 is removed, then the block works, but changes a time section that is not part of the Time Plan Settings.

Workaround
In place of using three time blocks only one is used. It is set from 000:00:00 to 24:00:00. Thus the orange line will be solid orange for day and solid purple for night. Hubitat uses two different API to change from day to night and from night to day when LUX is at the correct level.

Day Switch
Code:
http://admin:password@192.168.55.156/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][0]=00:00:00-24:00:00 Day

Night Switch
Code:
 http://admin:password@192.168.55.156/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][0]=00:00:00-24:00:00 Night

The only difference is the word at the end. Day or Night in this example.

Other modes can be used such as Custom1 or Custom2. The end word in the API would be Custom or Custom1 in this case.

The application of changing one line of code could be applied to using Blue Iris PTZ settings to run the API as per instructions provided by pb2008.

Alternative using Blue Iris to set camera profiles
 
@Alaska Country I think I know why you are seeing the error with the Night settings. It's partly my fault because I forgot to add that you MUST first set the number of time blocks you want each month in the time settings manually. Once they are set, then the api commands work.

I assume you and most others would want to have three blocks as you can see in the above pic. What you need to do is create one manually then copy them to all the months. They will all look the same at that point. Now the api commands will adjust them correctly.

Also through much trial and error I discovered another bug that I forgot to mention. You MUST have the camera set to 24 hr mode, not 12 Hr. None of the time settings will work with 12 Hr setting. I passed this bug along to Andy and his response was to just set it to 24Hr.... sigh.
 
  • Like
Reactions: Alaska Country
I am interested how you got the username: password authentication to work with a single http statement. I tried using Http directly through Blue Iris, then tried VB.net script using HomeSeer without any luck. Didn't think to escape the blank or the &. Nice! I ended up having to use a more complicated script run locally on the BI machine:

Code:
Imports System.Net
Sub Main( ByVal Parm as Object )

    Dim sunrise as Date
    Dim sunset as Date
    dim sunsetStr as string
    Dim sunriseStr as String
    Dim sunriseStr1 as String
    Dim sunsetStr1 as String
    Dim sunriseOffset as Double     'in minutes
    Dim sunsetOffset  as Double     'in minutes
    Dim monthInt as Integer
    Dim cgiparam As String
    Dim url As String
    Const host = "192.168.40.124"
    Const page As String = "cgi-bin/configManager.cgi"
    Const user As String = "admin"
    Const pass As String = "XXXXXXX"

    '=== adjust as required ===
    sunriseOffset = -10   '- before , + after
    sunsetOffset = 10
    '-===

    sunrise = hs.SunriseDt.AddMinutes(sunriseOffset)
    sunset = hs.SunsetDt.AddMinutes(sunsetOffset)
  
    sunriseStr = sunrise.ToString("HH:mm:ss")      
    sunsetStr = sunset.ToString("HH:mm:ss")

    sunriseStr1 = sunrise.AddSeconds(-1).ToString("HH:mm:ss")      
    sunsetStr1 = sunset.AddSeconds(1).ToString("HH:mm:ss")

    monthInt = DateTime.Now.Month - 1


    cgiparam  = "action=setConfig&VideoInMode[0].TimeSectionV2[" & monthInt & "][0]=" & sunriseStr & "-" & sunsetStr & " Day"
    url = String.Format("http://{0}/{1}?{2}", host, page, cgiparam)

    Dim client As New System.Net.WebClient
    client.Credentials = New NetworkCredential(user, pass)

    Dim resp As String
    Dim resp1 As String
    Dim resp2 As String

    Try
        resp = client.DownloadString(url)
    Catch ex As Exception
        resp = ex.Message
    End Try

    hs.waitsecs(5)

    cgiparam = "action=setConfig&VideoInMode[0].TimeSectionV2[" & monthInt & "][1]=00:00:00-" & sunriseStr1 & " Night"
    url = String.Format("http://{0}/{1}?{2}", host, page, cgiparam)


    Try
        resp1 = client.DownloadString(url)
    Catch ex As Exception
        resp1 = ex.Message
    End Try

    hs.waitsecs(5)

    cgiparam = "action=setConfig&VideoInMode[0].TimeSectionV2[" & monthInt & "][2]=" & sunsetStr1 & "-24:00:00 Night"
    url = String.Format("http://{0}/{1}?{2}", host, page, cgiparam)


    Try
        resp2 = client.DownloadString(url)
    Catch ex As Exception
        resp2 = ex.Message
    End Try

  If resp.contains("OK") and resp1.contains("OK") and resp2.contains("OK") then
    hs.writelog("Remote Script","balcony_ptz.vb OK")
  Else
    hs.writelog ("Error",  "Remote script balcony_ptz.vb failed")

End Sub
 
Thanks for clarifying the issue on the Night settings. It appears that the API, for that call, is requiring some additional information in order to generate an additional time block as it bounces back an error. Looks like that is most likely undocumented in the API listings.

Yes, using three blocks, one for day and two for night is a good logical approach when using the Web-5 camera GUI. My take is to only use two and to extend that time for a full 24 hours. Thus it makes it simpler to switch from day to night and night to day mode. Under Working Mode have setup Day and Night modes under Customized Scene for camera settings. Self-Adaptive would be nice to also use, however there is no option for the selection of two different modes thus making it unusable for a day/night switch.

As a question, what happens if day is set from 06:00 to 13:00 with no other Time Plan Settings. Would assume that the camera would stay in Day mode and never change. i.e. non colored blanks showing in the camera GUI.

Glad you brought up the 24 hour time scenario . Always use time in a 24 hour format so it was not an issue. But it is interesting that Dahua is not concerned. As others have said, we are not the intended audience thus a fix is most unlikely.
 
Last edited:
I am interested how you got the username: password authentication to work with a single http statement.

On this end, API calls are tested by placing the URL into FireFox on the same network and machine that is hosting BI. As listed in the posted code, the user and password are part of the URL. Have not had any issues with it not working. If the user and password are not part of the URL, then FF will pop up a screen asking for this data.

My usual scenario is to first test in a browser and if the API code works then port over to a HTTP GET statement as a Hubitat action with the hub on the same sub net as BI. Note: BI and the Hub are on a sub net that is isolated from the internet.

Your testing and API provided the answer that was needed to make the day/night mode switch operational. Again, thank you for providing that much needed API!!!
 
This is in response to a message about the day/night setup....

The first step to determine if an API call will work, is to enter a test API URL for a specific camera using a browser on the same machine that is hosting BI. In my case, I use FireFox. Note that Web-4 and Web-5 (the blue one) often use different API calls for specific actions but not always.

If the API works and is a GET statement. then information will be displayed in the browser. If a SET statement (makes changes to a camera setting) then an "OK" will be displayed. However, an "OK" is not an indication that the action took place. Just that the code works and presented no errors.

If the API does not work, then "Error" or "Error Bad Request!" is displayed. Make the appropriate changes and try again.

A good place to start is with a simple API GET statement that retrieves camera system information.

Note: User Name, Password and camera IP address must be changed to match your camera. Often BI users will keep "admin" for the user name and only change the password.

Code:
http://admin:password@192.168.55.166/cgi-bin/magicBox.cgi?action=getSystemInfo

This appears to work on most Dahua cameras and will display 7 lines of data.

For setting the Time Plan Settings on a Dahua SD5A425XA-HNR (PTZ5A4M-25X) the following GET statement can be used to see if the camera data has changed. This has been tested on only this model and a specific FW version.

Code:
http://admin:password@192.168.55.166/cgi-bin/configManager.cgi?action=getConfig&name=VideoInMode

If successful, then there will be a page of data displayed as in post 1 of this thread.

For other Web-4 cameras the following code is being used to change from day/night and night/day modes with the camera being set for "Full-Time Day" under "Profile Management". Keep in mind, that the posted API's may not work for all FW versions and Dahua models.

Day Switch
Code:
http://admin:password@192.168.55.166/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions.NightOptions.SwitchMode=0

Night Switch
Code:
http://admin:password@192.168.55.166/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions.NightOptions.SwitchMode=3

The only difference between day and night modes is the number at the end of the URL. In this case a 0 for day and a 3 for night.
 
It took me a lot of trial and error and testing but I finally found this to work on the newest Web5.0 with my newer PTZ cam. This method does not work for Web4.0

"http://<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][0]=10:00:00-16:00:00 Day"

I found you have to adjust the Night settings as well to make it work correctly as such:

"http://<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][1]=00:00:00-09:59:59 Night"
"http://<ip>/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].TimeSectionV2[0][2]=10:00:01-24:00:00 Night"

The first [ ] after "TimeSectionV2" is the month integer where January is 0 and so on.
The second [ ] denotes a new block on the schedule. I found they dont have to be in any order.

I am doing this under customized scene.

I adjust my schedule daily based on the sunrise and sunset using a customized script as you can see from the attached pic

View attachment 168272

You don't want gaps in the schedule such as in July (evening), Aug-Dec.

With gaps it will go to a default and you'll probably find at dusk and dawn that the picture is too dark. Better to merge them all together so everything crosses over. If daylight is too dark at dusk and night to light, add a low illuminace section between the 2 with settings suitable for dawn / dusk.

Also on the nightime gaps Aug-Dec, you'll probably find you have no usable recording in those gaps, as the default setting probaby won't be suitable for really llow light.

I suggest filling the whole table with everything gap free. Note to Andy here, really difficult to do this as gaps open up really easily and so small they'r hard to see. A better way of configuring this is needed or some kind of auto ripple where gaps are automatically closed.
 
If you know vb.net take a look at my script. It creates three perfect blocks daily with no gaps and adjusts each according to sunrise and sunset.

that pic was posted in July
 
for anyone that finds this thread via search like i did and just wants a simple Profile changer for Web5.0 cams, this should work:

Day: Night: General:
To find the other profile names, just open your browser DevTools and watch for the name. I'm not sure what the Mode does, but 4 is what works.

If you interact with the WebUI, it will revert back to your last selected profile since the displayed profile there doesn't update. I'm not sure why its so finicky.
 
  • Like
Reactions: OB1 KNOB
What exactly do these links do?

Do these set your day/night schedule on a daily cycle instead of a monthly cycle?

I tried one and it changed my schedule from orange/purple/orange to solid orange for each month.
 
These links can be setup to change the monthly schedule to a daily schedule based on your local sunrise/set. However, that requires the use of some external programming to send that link to the camera via an HTTP GET statement as a daily update.

Have been using a similar system with a Hubitat Hub to change day/night camera modes for both Web 4 and Web 5 Dahua cameras.
 
  • Like
Reactions: DarkHelmet
Hmmm... sounds like that might be more than I'll be able to handle. I guess I'll stick with my monthly time plan settings and let it be a little off for the part of each month.

It seems like someone would have come up with something in Blue Iris to handle daily sunrise and sunset schedules based on GPS coordinates.
 
Hmmm... sounds like that might be more than I'll be able to handle. I guess I'll stick with my monthly time plan settings and let it be a little off for the part of each month.

It seems like someone would have come up with something in Blue Iris to handle daily sunrise and sunset schedules based on GPS coordinates.

Someone did and it works great with the old GUI, just doesn't work with the new GUI as the API changed.
 
Agree on the monthly time schedule. Here in Alaska, during part of the year, the time changes in the range of 6 minutes per day. Thus, you are correct in that a monthly schedule is not the best way to implement day/night mode changes.

The below thread contains code that works for Web 5 day/night camera mode changes. This changes the monthly schedule to either orange or purple. Orange for your day camera settings and purple for the night settings.


These work in a browser to manually change modes and as stated above and will change the entire month from orange to purple. To use as a daily schedule it will be necessary for you to train your cat to press the enter key to send the code to the camera! It that does not work then there are other methods to add this functionally, no cat needed....

There does not appear to be a plug and play solution, at this time. Only pieces that can be used together for a solution.

Using Hubitat, as it is being used to control the outside lighting for the cameras. Thus it was natural to just continue with its use to control other aspects of the camera. Did use local sunset/rise times with an offset, but that did not take into account the actual outside lighting. Local sunset/rise time is easier to implement then using LUX. Both get the job done.

Now use a LUX sensor that is integrated into the Hub to trigger day/night mode changes based on how light or dark it actually is within a set time frame to eliminate any false mid day triggers.
 
Sounds complicated. Maybe if there was a thread with step-by-step instructions for dummies instead of fifty-eleven threads/posts that you have to try to piece together what's what.

I suppose those who can't figure out the API calls and don't have Hubitat are entering the sunrise/sunset times in the TPS of the camera GUI and living with it being off each month.

I can tell you the Day/Night switch on the one camera I have it on does not work very well. This morning, some 3 hours after daylight, I noticed it was still in night mode but has since switched to day mode.

BTW... we do have a cat, but she is lazy.
 
  • Like
Reactions: Leroy60 and CanCuba
Does this in the first post work... and what's the hiccup with it (written back in 2017)?

 
Maybe if there was a thread with step-by-step instructions for dummies instead of fifty-eleven threads/posts that you have to try to piece together what's what.

This is a volunteer site, wanna offer up your services to create one :lmao:

All joking aside, this thread is probably it for the moment. Several of us have tried and life got in the way and we decided to either use the monthly schedule or a different automation.
 
Last edited:
  • Like
Reactions: Alaska Country