I auto-adjust the brightness on my display using a cron which runs at 7 pm everyday.
xrandr --output eDP-1 --brightness 0.9
This sets the brightness to 90% of maximum brightness.
The above command works when run from my terminal. But when run on a cron, it does not produce any effect. We need to explicitly mention the "display number" as an environment variable
8 19 * * * DISPLAY=:0 xrandr --verbose --output eDP-1 --brightness 0.9
xrandr will give you a lot of output like
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384 eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis)
In my case, the display number is
xrandr is unable to find backlight, it only changes "perceived" brightness i.e it does software color correction. If we want to save battery, we will need to reduce the backlight brightness.
In Linux, the backlights can be found in
/sys/class/backlight. In my case, it was
/sys/class/backlight/intel_backlight. In this folder, there are many files like
actual_brightness max_brightness brightness
max_brightness shows highest possible level of brightness for the display. We can adjust the value in
brightness file to reduce backlight brightness.
Here's what I do to adjust it:
echo 1800 > /sys/class/backlight/intel_backlight/brightness (in root crontab)
Unlike the xrandr command, this does not require setting any DISPLAY variable in the cron file.
- brightnessctl is an easy to use tool which integrates well with systemd. It is also available in the package managers of various distributions like Debian, Ubuntu, Arch Linux.