The ThinkPad E14 has a light up power button. It’s very futuristic looking: its a thin ring around the circular power button. But, it is a bit of a bother when I’m watching movies. I hunted around the internet looking for a way to turn it off. This is Linux. The LED on the power button is a device.

/sys/class/leds/tpacpi::power/brightness

So you can do things like

# Get LED setting
cat '/sys/class/leds/tpacpi::power/brightness'

# Turn it off!! From the command line!!
echo 0 | sudo tee /sys/class/leds/tpacpi::power/brightness

Of course, once I found that out, there was no stopping. I quickly made this a script

# In ~/bin/led-off.sh
#!/bin/bash
echo 0 | tee /sys/class/leds/tpacpi::power/brightness

which I would invoke using

sudo led-off.sh

I didn’t want to have to type in my password each time, so I added the script to my sudoers file.

#in /etc/sudoers.d/kghose
kghose ALL=(ALL) NOPASSWD: /home/kghose/bin/led-off.sh

Awesome!

But the problem was that every time the computer woke from sleep the system would turn the LED on. Invoking sudo /home/kghose/bin/led-off.sh each time I opened the lid grew tedious.

After further searching on the internet I figured out how to run the script automatically each time the computer woke from sleep:

# In /lib/systemd/system-sleep/led-off
#!/bin/sh
case "$1" in
post)
echo 0 | sudo tee /sys/class/leds/tpacpi::power/brightness
;;
esac

Perfect! At least until I remembered that the ThinkPad’s power button was also a finger print reader. I didn’t really need a fingerprint reader: I was quite happy logging in with my password, but hey, anything to save a few keystrokes amirite?

I searched on the Lenovo website and found that they had a Linux driver for my finger print reader. I installed it and WooHoo! the finger print reader started working. It was also the first time I’d seen the power LED go a shade of blood red. It was quite cool: the computer would come out of sleep or lock screen and the power button would start flashing red. I would tap my finger on it and I’d log in.

Problem was that the fingerprint driver, or whatever it was flashing the LED, overwrote the LED state and didn’t restore it. So I was back to having the LED being on when the laptop came out of sleep. Bother!

After more searching on the internet, it turns out that there is a way to detect when the computer unlocks the screen, using something called dbus-monitor (which is quite cool, and it’s fascinating to see the programs broadcast messages on the dbus).

# In ~/bin/dbus-led-off.sh
#!/bin/bash

while read x
do
case "$x" in
*"boolean false"*) sudo /home/kghose/bin/led-off.sh;;
esac
done < <(dbus-monitor --session "type='signal', interface='org.gnome.ScreenSaver'")

And this script I run on desktop start up, by adding

# In ~/.config/autostart/led-off.desktop
[Desktop Entry]
Type=Application
Exec=dbus-led-off.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=Battery Rate
Name=Battery Rate
Comment[en_US]=Taskbar notification for power draw
Comment=Taskbar Notification for power draw

Ahhhh! I can watch movies in peace again! Not that I got a lot of movie watching done, with all the internet searches, and reading up about dbus and so on and so forth. But it’s the principle that counts …