For debugging, uncomment the print sunrise/sunset statement above and check whether settings were accepted by your webcam using:
$ uvcdynctrl --get="Exposure, Auto"
You can figure out which control flags are accepted by your webcam with:
$ uvcdynctrl -cv
It’ll also print the minimum/maximum allowed values for each camera setting.
If you’re not sure about your settings, try to find the optimal values with guvcview. Here you can adjust your cam settings using sliding bars. Make sure to set “Exposure, Auto” to “Manual Mode” and deselect “Exposure, Auto Priority” as shown below. Then, optimize the picture with the live preview and write down your settings.