First, can the while-loop be terminated after 5 sec or so?
Second, could anyone please try to improve the script so that lower brightness-levels can be set using the script? Maybe the way the 256 brightness-levels are mapped to the ones that can be set for the screen would need to be changed.

Yeah, I tried redshift and f.lux, both didn't work correctly. And if I use the webcam the result should be more accurate, even if the color temperature doesn't get adjusted
–
ToxicbitsSep 4 '11 at 18:41

1 Answer
1

In older kernels there was brightness control file somewhere in /proc, but I think that it was the same functionality as /sys in your code snippet. In this /procfile there was several levels of brightness that you could use and probably the same is in that mechanism. Try to cat /sys/devices/virtual/backlight/acpi_video0/brightness and check if there is information about brightness levels that you may use.

If you remove loop whole code will be executed once so it will be possible to set brightness only once per half hour period. There is little disadvantage of this solution - if you cover camera at the moment of brightness checking, brightness will be changed and next reading will be after half hour so you end up with completely dark screen for half hour.

To avoid this situation you could replace while loop by for loop (0 to 5 for example) with 5 seconds sleep with it. In loop you can only check brightness five times and after loop you could calculate average brightness and set it.

The output is 5. Unfortunately I don't know how to code in python, could you please try to implement that? Thx
–
ToxicbitsSep 4 '11 at 18:45

If there is only one value I think that may be current value. In /proc version there was current value and a list of possible values. I edited my answer, but you must check on your own if it makes sense...
–
pbmSep 4 '11 at 19:02

Thanks a lot, the script works great :)! I use a laptop, so covering the webcam by accident won't really be an issue. I counted the brightness levels I can adjust the screen to using the Fn keys and got 11 levels. But does that matter at all? Or would this line x.append(int((int((max(image) / 256.0) * 10) + 1) ** 0.5 / 3 * 10)) need to be altered?
–
ToxicbitsSep 4 '11 at 21:47

Could you check if there is a change in this file when you change brightness using fn? If yes whats max and min values? What is the step?
–
pbmSep 5 '11 at 6:18