LEDs/Sync with backlight

== Trigger ==
Actually there is a LED trigger available to turn on/off some LEDs when the backlight goes on/off (link). For usage of LED triggers, see LEDs#Triggers. Though probably it is currently not enabled in most of the kernel configs.
== Scripts ==
If the backlight LED trigger is not available, does not work for some reason or when backlight handling is not yet implemented for the device, there are other ways to achieve such a behaviour.
One approach is having a look on dbus-monitor if some signals or method calls can be used parasitically to turn on/off the LEDs at certain situations. Check the screen blanking/unblanking behavior works best via ssh. For view the session bus, the DISPLAY variable needs to be exportet: DISPLAY=:0 dbus-monitor --session. This is not needed to see the system bus but dbus-monitor --system shows singnals only. To see method calls on the system bus, sudo is required: sudo dbus-monitor --system.
=== Phosh ===
When the screen blanks or unblanks, there are some method calls concerning the color manager on the system bus. This can be used to turn on/off the leds. As method calls on the system bus need sudo, the command can be added to visusdo to avoid a password query for the command.
The dbus method call of the color manager unfortunately does not reveal whether the screen was blanked or unblanked. To find out about the state, the sysfs node /sys/class/drm/card0-DSI-1/dpms is queried. You might need to adapt the path according your setup. If your device doesn't provide dpms information, you need to find other ways to query the state of the screen, maybe looking for other dbus signals or method calls.
The example shows turning on/off the leds of tm2-touchkey (used by some samsung devices). To handle the LEDs in the script, the user needs permission to change them, see LEDs#Access_via_sysfs.
If the LEDs you want to use are turned off by default, you need to turn them on at boot. The keys for this example can be found by udevadm info --attribute-walk /sys/class/leds/tm2-touchkey.
* sudo vi /etc/udev/rules.d/21-tm2-touchkey-leds.rules
ACTION=="add", SUBSYSTEM=="leds", KERNEL=="tm2-touchkey", ATTR{brightness}="1"
Now let's create the script:
* vi ~/tm2-touchkey-leds-phosh.sh
#!/bin/sh
while true; do
 sudo dbus-monitor --system interface=org.freedesktop.ColorManager | grep -m 0 FindDeviceByProperty
 if [ "$(cat /sys/class/drm/card0-DSI-1/dpms)" = "Off" ]; then
 echo 0 > /sys/class/leds/tm2-touchkey/brightness
 else
 echo 1 > /sys/class/leds/tm2-touchkey/brightness
 fi
done
Make it executable:
* chmod +x ~/tm2-touchkey-leds-phosh.sh
Add the dbus command to the sudoers file:
* sudo visudo
## watch ColorManager changes to detect screen blanking
user ALL=NOPASSWD: /usr/bin/dbus-monitor --system interface=org.freedesktop.ColorManager
And create an autostart file:
* vi ~/.config/autostart/tm2-touchkey-leds-phosh.desktop
[Desktop Entry]
Type=Application
Name=tm2-touchkey-leds-phosh
Exec=/home/user/tm2-touchkey-leds-phosh.sh
X-GNOME-Autostart-Phase=Initialization
=== Plasma Mobile ===
Unfortunately, dbus-monitor seems not easily accessible via ssh. This makes it harder to find appropriate signals or method calls that can be used.
=== Xfce4 ===
See Screen locker:Disable inputs#Xfce4, a more extensive draft script that handles both input and LEDs.
Category:Hardware