Package: auto-adjust-display-brightness
Theauto-adjust-display-brightnessprogram automatically adjusts the
brightness ofLinuxcomputer displays based on whether it’s light or dark
outside. To get it working you create a configuration file defining your
physical location (this is how it figures out whether it’s light or dark
outside) and how to manage the brightness of which displays (so it knows the
best way to control the brightness).I’m a computer programmer and sometimes work through the evening and into the
night because itenables deep concentration. During such evenings / nights a
recurring irritation was that I had to manually adjust the brightness of my
laptop screen and the external monitor attached to my laptop to avoid
unnecessaryeye strain. I’d been usingxfluxfor years (it removes the blue
light from computer displays during the evening) but that doesn’t dim the
backlight of my MacBook Air while I found this to be essential to avoid eye
strain.InstallationGetting startedRunning from cronContactLicenseInstallationTheauto-adjust-display-brightnessprogram is written in Python and is
available onPyPIwhich means installation should be as simple as:$ pip install auto-adjust-display-brightnessThere’s actually a multitude of ways to install Python packages (e.g. theper
user site-packages directory,virtual environmentsor just installing
system wide) and I have no intention of getting into that discussion here, so
if this intimidates you then read up on your options before returning to these
instructions ;-).Getting startedTheauto-adjust-display-brightnessprogram requires a configuration file
that defines your physical location (this is how it figures out whether it’s
light or dark outside) and how to manage the brightness of which displays (so
it knows the best way to control the brightness). As an example here’s the
configuration file that I’m using at the moment:# My physical location. I determined these values using Google Maps.[location]latitude=53.240534499999995longitude=6.614897599999949elevation=-2# The laptop screen of my MacBook Air. This controls the physical backlight# which is the best way to reduce the brightness (it also reduces power# consumption :-).[display:MacBook Air]min-brightness=7max-brightness=70sys-directory=/sys/class/backlight/acpi_video0# My external monitor connected via a display port to DVI adapter. I haven't# found any way to configure the physical backlight of this monitor so I'm# resorting to a software only modification here (better than nothing).[display:ASUS monitor]min-brightness=30max-brightness=60output-name=HDMI1The configuration file is loaded from the following locations:~/.auto-adjust-display-brightness.ini/etc/auto-adjust-display-brightness.iniThe structure of the configuration file is as follows:The[location]section has three items, all of which are required
(latitude,longitudeandelevation). Some hints on how to find
the correct values:You can find your latitude and longitude onGoogle Maps.Finding your elevation is a bit trickier: Google Maps has the required
information but doesn’t expose it. Fortunately there area dozen online
toolsthat make it easy to find your elevation.Each[display:...]section defines a computer display whose brightness
should be controlled by the program:The label after thedisplay:tag is the name of the display (it’s used
in logging output but not otherwise significant, although it should of
course be unique).Displays may have a configured minimum brightness (min-brightness) and
maximum brightness (max-brightness). These items default to 0% and 100%
respectively (the values are percentages).Currently two types of brightness control are supported:The physical brightness of the backlight of laptop screens. This uses
the Linuxsysfsvirtual file system’s/sys/class/backlightinterface
to control backlight brightness. The only required item issys-directorywhich is expected to contain the absolute pathname of
the directory that controls the backlight brightness of your laptop
screen (you’ll have to figure this out for yourself).The software brightness of any display usingxrandrto apply a software
only modification of display brightness. The main advantage of this
approach is that it will (should) always work. The disadvantage is that
it won’t dim the back light of the screen. In other words, if you can
get the other type of brightness control to work for your display it’s
likely preferable.Running from cronTo actually have your display brightness adjusted without manually running any
commands you can runauto-adjust-display-brightnessfrom a cron schedule.
Here’s what I’m currently using:# /etc/cron.d/auto-adjust-display-brightness:
# Crontab entries for automatic adjustment of display brightness.

DISPLAY=:0
HOME=/home/peter
VIRTUAL_ENV=/home/peter/.virtualenvs/auto-adjust-display-brightness

@reboot root $VIRTUAL_ENV/bin/auto-adjust-display-brightness --force 1>/dev/null 2>&1
* * * * * root $VIRTUAL_ENV/bin/auto-adjust-display-brightness 1>/dev/null 2>&1Some notes about this crontab:The@rebootline is responsible for running the program straight after
boot to avoid the display brightness starting in the wrong state and being
decreased or increased gradually in the minutes after I’ve booted my laptop.
When the program detects that it’s being run less than 60 seconds after the
system has booted it changes the brightness at once instead of gradually.The commands are run asrootso that the program has the privileges
required to write to/sys/class/backlight/acpi_video0(to control the
physical backlight of my MacBook Air).TheDISPLAYvariable enablesxrandrto work even though it’s not
being run from within my GUI environment.TheHOMEvariable enablesauto-adjust-display-brightnessto find my
configuration file without having to move it to/etc/auto-adjust-display-brightness.ini. This enables me to track the
configuration file in my private dotfiles git repository :-).ContactThe latest version ofauto-adjust-display-brightnessis available onPyPIandGitHub. For bug reports please create an issue onGitHub. If you have
questions, suggestions, etc. feel free to send me an e-mail atpeter@peterodding.com.LicenseThis software is licensed under theMIT license.© 2016 Peter Odding.