How do I set default display brightness? [duplicate]

Is it possible to set the default display brightness so you don't have to re-adjust it everytime you reboot? My laptop display is killing my eyes at the login screen already because it starts at 100% brightness every time.


Solution 1:

Review of solutions and offering a (hopefully) better one

Previous solutions

/sys/-based : good for console

@gan

This works echo 5 > /sys/class/backlight/acpi_video0/brightness but does not play well with X. More specifically, X is not aware about your preferred settings and you may end up needing to set the brightness manually again at least once, similar to bug #1042359 .

setpci-based : system-dependent, dangerous

@erickjohncuevas

Solutions based on things like setpci -s 01:00.0 F4.B=50 are dangerous. There, 01:00.0 is actually an ID targeting a particular board on the PCI bus. And it is system-dependent. That means blindly following this may write configuration registers on some other boards where it may mean anything, from just nothing to crashing the system at some point in the future. Anyway it does not play well with X either.


Proposed solution

Advantages/drawbacks

The solution below has these advantages:

  • plays nice with X which is fully aware of the settings chosen
  • is more readable, thus maintainable
  • does not contain system-specific address, etc, and as a result may work on a wider range of hardware (e.g. where kernel does not know about backlight, or that don't even use PCI-based video board, think Ubuntu for ARM )

It assumes: Ubuntu using lightdm (that is 11.10 and beyond)

It only sets backlight when lightdm starts. But it can be combined with the /sys-based solution above if you really need to set backlight earlier.

The solution

Copy-paste of these commands should do what you need (sudo will probably ask your password).

  1. Install xbacklight if it is not already installed (it is a small package).

    sudo apt-get install xbacklight
    

    You should test xbacklight on the command-line to see if it works. For example:

    xbacklight = 100 ; sleep 2 ; xbacklight = 30
    

    Try to figure out a suitable value for your hardware and lighting conditions.

  2. Create a small script running xbacklight.
    You can change the =30 into another value if you wish.
    The || true ensures that if xbacklight fails for any reason, X can still start.

    sudo bash -c '{
        echo "#!/bin/bash"
        echo "xbacklight =30 || true"
    } >> /etc/lightdm/display-setup-script.sh '
    
  3. Make the script executable

    sudo chmod a+rx /etc/lightdm/display-setup-script.sh
    
  4. Instruct lightdm to run the script when starting X.
    Specifically, this adds a line display-setup-script in a lightdm configuration file, but only if there is not one already.

    if grep -ri ^display-setup-script /etc/lightdm/
    then 
      echo "There may be already a display-setup-script. It may already do what you need. Else please adjust manually" ; 
    else 
      if [[ -d /etc/lightdm/lightdm.conf.d ]]
      then
        # Ubuntu 13.10 and above have lightdm.conf.d. 14.04 *only* has lightdm.conf.d.
        DEST_CONF_FILE=/etc/lightdm/lightdm.conf.d/20-default-brightness.conf
      else
        # Ubuntu 12.04, 12.10, 14.10 do not have lightdm.conf.d, so we change main configuration file
        DEST_CONF_FILE=/etc/lightdm/lightdm.conf
      fi
      echo "Writing into $DEST_CONF_FILE"
      sudo bash -c "{ 
          echo '[SeatDefaults]' ; 
          echo display-setup-script=/etc/lightdm/display-setup-script.sh ; 
      } >> $DEST_CONF_FILE" ; 
    fi
    

May be tested by restarting lightdm from a root session on the console. Or, more simply, by rebooting.

Tested on Ubuntu 12.04, 12.10, 13.10, 14.04, 14.10, 16.04.

Please provide feedback about your experience.

Solution 2:

source

Actually echoing some value to doesn't help in the brightness as the value will differ from system to system.

First you need to set the brightness of the screen to the level comfortable to you, which can easily be done in System SettingsBrightness & Lock or by using the function keys.

Now go to /sys/class/backlight/<folder> (my folder is intel_backlight)

screen shot of the folder

In this folder you can see the actual_brightness file and the max_brightness file. (If you have made any changes to the brightness after opening this file, don't forget to refresh (using Ctrl+R or F5) to see the actual current settings.)

Now we need the same value as in the brightness every time we start our system. This can be done by changing every time the value in this folder at the startup. We need to change the rc.local file.

First type these commands in the terminal (which can be opened by searching for Terminal in the dash or by pressing Ctrl+Alt+T):

sudo -i
gedit /etc/rc.local

and add the line

echo 900 > /sys/class/backlight/intel_backlight/brightness

Replace 900 with whatever value you need (that is, the value you got from the above procedure). Also replace intel_backlight with the folder name from /sys/class/backlight/.

For example, my /etc/rc.local:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
rfkill block bluetooth
echo 900 > /sys/class/backlight/intel_backlight/brightness

exit 0

As an aside, I added the line rfkill block bluetooth to my rc.local file as I don't use Bluetooth at all but Ubuntu starts Bluetooth every time it reboots (even if the Bluetooth was off before). You can also add it, and just in case you want to use Bluetooth you can always start it again, even if this line is in your rc.local).

Don't change the value of exit 0 in the ending. If that line doesn't exist, add it.

Now even if you have restarted the system you will have the same value that you need.

Be careful to not put a brightness value greater than max_brightness, as that will throw you an error saying that it is an invalid argument.

Solution 3:

It isn't default. Whenever I reboot my brightness is set to 100%. Then I set the brightness with command:

$ echo 5 | sudo tee /sys/class/backlight/acpi_video0/brightness

Solution 4:

Have you look at redshift? It's designed for another purpose (make the screen less bluish at night), but it might solve your problem as well.

To install:

sudo apt-get install redshift

My configuration file (~/.config/redshift.conf):

[redshift]
;temp-day=5700
;temp-night=4600
brightness-day=1.0
brightness-night=0.75
gamma=0.8
adjustment-method=vidmode
location-provider=manual

[manual]
lat=63.81415
lon=20.41742

If you change brightness-day and brightness-night to a value you like and set temp-day and temp-night to the same value, you will effectively use redshift to set your brightness only.

To make redshift autostart at login, select Applications/System tools/Preferences/Startup applications/Add. Name: redshift. Command: /usr/bin/redshift.

Solution 5:

Once you have your preferred brightness set, you can follow the answer by N0rbert here: Brightness is reset to Maximum on every Restart. In summary:

sudo add-apt-repository ppa:nrbrtx/sysvinit-backlight
sudo apt-get update
sudo apt-get install sysvinit-backlight

sudo service sysvinit-backlight status # Show current brightness levels and values saved in files
sudo service sysvinit-backlight start # Set saved levels from files
sudo service sysvinit-backlight stop # Save current levels to files