Automate brightness level in Ubuntu 16.04 based on power source

I personally did not find any app or settings which could easily do this, though this is not an app or gui, but its the simplest and easiest way at least for me.

I have successfully implemented this in Ubuntu 16.04 on my HP envy 13 ab0XX laptop.
Your mileage may vary based on your system.

Note : Change USERNAME to your username. File location is up to you bdw.
Create a file /home/USERNAME/ and paste the following in it:

# Adjust brightness of backlights based on power source
case $1 in
# On battery
# Dim screen backlight
expr `cat /sys/class/backlight/intel_backlight/max_brightness` / 2 > \

# On AC
# Don't Dim screen backlight
cat /sys/class/backlight/intel_backlight/max_brightness > \

return 0

It will dim the screen 50% on battery power which is fine for me.

Please note that /sys/class/backlight/intel_backlight/ could be something different in your system, like /sys/class/backlight/acpi_video0/. Check the dir /sys/class/backlight/.

Give execution permission to the script:

chmod 771

Create a udev rule, in /etc/udev/rules.d/99auto-backlight.rules with the following in it:

SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/home/USERNAME/ true"
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/home/USERNAME/ false"

Remember to change the USERNAME.

To enable it at boot, add the following to /etc/rc.local before exit 0:

udevadm trigger -s power_supply

And there you have it. 🙂


M M Arif

Founder of and Husband. Father. Senior Software Engineer. Linux enthusiast, using multiple Linux operating systems for personal use and work. A self taught programmer who love to code and share. Fan of open source and community projects.

Leave a Reply

Be the First to Comment!

Notify of