External monitor brightness control with Redshift and ddcutil
Redshift is a program for Linux that adjusts the color temperature of the screen based on the time of day. I find my screen more comfortable to look at when the color temperature is reduced, especially at night. Redshift also has an option to adjust the brightness, but it does the adjustment in software, so the backlight on the display remains the same. This results in a washed out image at lower brightness levels.
Most monitors support an interface called DDC/CI to adjust the parameters found in the monitor's OSD. ddcutil is a program to send these commands to the monitor. In particular, it can adjust the brightness of the monitor's backlight.
To set it up, first install Redshift and ddcutil:
sudo pacman -S redshift ddcutil
Configure Redshift:
# ~/.config/redshift.conf
[redshift]
temp-day=5500
temp-night=3500
location-provider=manual
fade=0
[manual]
lat=66.058
lon=-74.135
ddcutil requires access to I²C devices. Enable the i2c-dev
module:
echo i2c-dev | sudo tee /etc/modules-load.d/i2c-dev.conf
sudo modprobe i2c-dev
Confirm that ddcutil can see your monitor:
sudo ddcutil detect
Set NOPASSWD
for ddcutil in /etc/sudoers
so that Redshift doesn't need to run as root:
sudo visudo
Add near the end:
youruser ALL = (root) NOPASSWD: /usr/bin/ddcutil setvcp 10 *, /usr/bin/ddcutil setvcp 12 *
Features 10 and 12 and brightness and contrast, respectively. You can get a list of all the features supported by your monitor with sudo ddcutil capabilities
. Confirm that you can now adjust the brightness and contrast without entering a password:
ddcutil setvcp 10 50
ddcutil setvcp 12 25
Now add a hook to Redshift to adjust the brightness and contrast:
# ~/.config/redshift/hooks/ddcutil
#!/bin/bash
case $1 in
period-changed)
case $3 in
night)
# 10=brightness, 12=contrast
sudo ddcutil setvcp 10 50
sudo ddcutil setvcp 12 35
;;
transition)
sudo ddcutil setvcp 10 63
sudo ddcutil setvcp 12 43
;;
daytime)
sudo ddcutil setvcp 10 76
sudo ddcutil setvcp 12 61
;;
esac
;;
esac
Mark it executable:
chmod +x ~/.config/redshift/hooks/ddcutil
Run Redshift and confirm that it adjusts the brightness/contrast on startup:
redshift