Skip to content

Automate brightness level in Ubuntu 16.04 based on power source

Update(29-July-2017): Also tested on Dell Latitude-7480, and it works fine.

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/auto-backlight.sh and paste the following in it:

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

# On AC
false)
# Don't Dim screen backlight
cat /sys/class/backlight/intel_backlight/max_brightness > \
/sys/class/backlight/intel_backlight/brightness
;;
esac

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 auto-backlight.sh

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/auto-backlight.sh true"
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/home/USERNAME/auto-backlight.sh 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. 🙂

Reference: https://askubuntu.com/questions/613741/ubuntu-15-04-pm-utils-do-not-look-into-etc-pm-power-d-anymore-what-instead/

Published inLinuxUbuntu

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of
Theme by Compete Themes. Enhanced for The Random Bits only. © The Random Bits 2018.