- May 6, 2018
- 2,688
- 3,060
I got tired of fooling with my Dahua cameras scheduling profiles for Day/Night. I know that @bp2008 has a handy Windows program that accomplishes a similar purpose but I needed something for Linux. Thanks for writing that for the community by the way, @bp2008! I dug into your source to find out what HTTP API calls I needed for my cameras to switch between day/night. It seems there are different HTTP API calls for different cameras so its a bit trial and error before you find the right call you need.
There is a program I found called sunwait which is really really slick. It calculates sunrise/sunset from any GPS coordinates you give it. It can give you standard, civil, twilight, and astronomical sunrise/sunset. You can even customize further with sunwait by giving it angles below/above horizon you want the sun to be before running a command or even how many minutes before/after sunrise/sunset you need the sun to be. Anyway, after any of those conditions occurs, you can give it a command to execute. Commands go after the semicolon ( ; ). So here is a simple cron job that will flip my Dahua PC-T5442TM-AS to Night:
Basically cron kicks this of at 4pm (16:00). Sunwait runs, checks the sunset time for the given GPS coordinates, and then waits for sunset. Once sunset occurs it runs the command
Here cron runs sunwait at 4am, sunwait checks the sunrise time and enters into a wait, and then kicks off the
So basically its just two cronjobs with the appropriate HTTP calls that flips the cameras back and forth. Wanted to put this out there. You can do all kinds of home automation with sunwait. Nice to not have to mess with setting a profile anymore. Its set and forget now.
There is a program I found called sunwait which is really really slick. It calculates sunrise/sunset from any GPS coordinates you give it. It can give you standard, civil, twilight, and astronomical sunrise/sunset. You can even customize further with sunwait by giving it angles below/above horizon you want the sun to be before running a command or even how many minutes before/after sunrise/sunset you need the sun to be. Anyway, after any of those conditions occurs, you can give it a command to execute. Commands go after the semicolon ( ; ). So here is a simple cron job that will flip my Dahua PC-T5442TM-AS to Night:
Bash:
0 16 * * * /location/of/sunwait/binary/sunwait wait set 40.19N 80.79W ; wget -O - --user username --password password "camera_ip:port/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1" >/dev/null 2>&1
Basically cron kicks this of at 4pm (16:00). Sunwait runs, checks the sunset time for the given GPS coordinates, and then waits for sunset. Once sunset occurs it runs the command
wget
which connects to the camera with the supplied ip : port and username: password and flips my camera to night mode. Sunwait then exits after wget
. A separate cron job is created to flip it back to day mode:
Bash:
0 4 * * * /location/of/sunwait/binary/sunwait wait rise 40.19N 80.79W ; wget -O - --user username --password password "camera_ip:port/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=0" >/dev/null 2>&1
Here cron runs sunwait at 4am, sunwait checks the sunrise time and enters into a wait, and then kicks off the
wget
command at sunrise to flip the camera back to day mode. Sunwait exits after the wget
command. These HTTP commands are for the newer PC-T5442TM-AS 4MP cameras. Your HTTP command may be different since Dahua didn't adopt a standard for all their cameras to handle the switch between day/night.So basically its just two cronjobs with the appropriate HTTP calls that flips the cameras back and forth. Wanted to put this out there. You can do all kinds of home automation with sunwait. Nice to not have to mess with setting a profile anymore. Its set and forget now.
Last edited: