[TRACKING] "auto-brightness" aka ambient light sensor in Linux? Details?

I don’t think that one is KDE specific, it is Intel specific. It does seem to mostly work.
It assigns a brightness variable from 1,000 to 100,000 to the brightness file.
*9,600 to 96,000

cat /sys/class/backlight/intel_backlight/brightness

By reading the ambient light sensor.

cat /sys/bus/iio/devices/iio:device0/in_illuminance_raw

The ambient light sensor on the Framework seems to match 1:1 with the raw illuminance values, though the raw illuminance can detect values over 100% brightness.

A glitch in the script causes it to go full brightness in dark rooms, and when fixing the glitch it looks like the code was attempting to compensate for the monitor as a light source.

Edit:

This will need to be run as ‘sudo’. It works on Kubuntu 21.10.

#!/bin/bash
max=$(cat /sys/class/backlight/intel_backlight/max_brightness)
sensitivity=$((max/10))
min=$((max/10))
delay=6
while [ 1 ]
do
updated=1
while [ $updated -gt 0 ]
do
updated=0
backlight=$(cat /sys/class/backlight/intel_backlight/brightness)
sensor=$(cat /sys/bus/iio/devices/iio:device0/in_illuminance_raw)
target=$sensor
if [ $backlight -gt $sensor ]
then
if [ $(($backlight - $sensor)) -gt $sensitivity ]
then
updated=1
fi
fi
if [ $backlight -lt $sensor ]
then
if [ $(($backlight - $sensor)) -lt $sensitivity ]
then
updated=1
fi
fi
if [ $target -gt $max ]
then
target=$max
fi
if [ $target -lt 1 ]
then
target=$min
fi
if [ $updated -gt 0 ]
then
echo “Starting brightness: $backlight”
echo “Ambient light: $sensor”
echo “Adjusted brightness: $target”
echo “-------------------------------”
echo “Sensitivity: $sensitivity”
echo “Min: $min Max: $max”
echo
echo $target > /sys/class/backlight/intel_backlight/brightness
fi
done
sleep $delay
done

6 Likes