How to have keyboard backlights turned on at boot

Progress!

I used @xircon 's script and unit file and followed his directions.

At reboot the backlight now turns on; when I log in they turn off for a second or so, and then they turn on again and stay on. That’s indeed what I wanted, so thank you @xircon.

Snag is: if I turn the backlight off by pressing the appropriate FN-key the backlights turn off, and, after one second or so, they turn on again :-).
I think I can live with that, though.

I’m just surprised that hardware manufacturers can’t put out a product that works from the get go. It would be extremely disappointing if i purchased a laptop knowing that it has a backlit keyboard and yet it doesn’t work out of the box. I just know that my Lenovo Thinkbook does and I’m not sure that’s the case for all Lenovo products. Most likely it’s not but i fail to understand why? If they can make it work on one then it should work on all their products they produce. I’m glad you have it working to your satisfaction thanks to @anthony93 and @xircon.

Edit: I realize yours is an Asus product but I’m just saying it should be the same for any manufacturer that produce a laptop with backlit keyboards.

This could be due to the fact that you added always for the Restart option in the unit file. If you use always, the service will always be restarted after the process exits; this means that your script will always be run even after it has already done its thing. That is probably why the backlight turns back on after you manually turned it off; because the script is being restarted (run) repeatedly.

Change

Restart=always

to

Restart=on-failure

and you should be good.

This is a great point, actually. I’m not even sure where to find the code to load the hardware settings. Probably in some kernel module, I reckon. A possible reason why such things work out of the box for Thinkpads is that there are more users running Linux on Thinkpads compared to other hardware.

Mine is a Thinkbook which is a Thinkpad sibling i guess. :man_shrugging:

Thank you so much for explaining all this. :+1:

Changed the unit file accordingly.

Now they don´t stay on at boot anymore.

If I then run

sudo systemctl enable kb-light.service --now

the backlights do turn on and stay on.

I’ll revert back to always for now.

If there is anything else I can try, please let me know.

With on-failure, if you turn it off with the FN-key, does it automatically turn back on?

Interesting. Can you post the contents of the script you run with that unit file? Also post the journal entries for the affected boot (the boot where you tested on-failure)

Thank you!

Will be back later tomorrow and get the info.

The script is further up in the post I made, it is just a shebang and the echo line.

Just comment out the restart lines, save, daemon reload. This is the behaviour you are looking for:

#Restart=always
#RestartSec=3

Thanks @xircon - I tried that.

Unit file now looks like this:

[Unit]
Description=Set Keyboard light

[Service]
User=root
WorkingDirectory=/usr/bin/
ExecStart=kb-light.sh
# optional items below
#Restart=always
#RestartSec=3

[Install]
WantedBy=multi-user.target

kb-light.sh looks like this:

#!/usr/bin/env bash
echo 3 |  tee /sys/class/leds/asus::kbd_backlight/brightness

The behaviour I am seeing now is the same is with ’ Restart=on-failure’: the backlights are on when booting but turn off after I logged in. Pressing the appropriate FN-key works as expected.

Is it still helpful if I do as suggested here?:

Try running kb-light.sh as your login script.

Tried this.

I disabled the kb-light service then added the script as a login script.

Result: keyboard backlights NOT turned on. :thinking:

Rhyme nor reason, me thinks?

I’ll activate “always” and "restartsec¨ and enable the service again - that is the best option so far.

Silly question perhaps but:

In the unit file it says:

[Service]
User=root

What would happen if I change User to my username?

1 Like

It needs sudo rights. The only way I know to do this is a unit… or …

Disable sudo password, I do this, my machine, my rules :skull_and_crossbones: then you can stick it in your autostart or shell init script.

Ah, right. That would not be helpful then.

Coming weekend I’ll do some more digging and experimenting with the unit file, and/or the startup script to see if I can get it to work as one would expect it to work.

I’ll report back here.

After you changed the service file you did do a daemon reload? Just a thought (or a reboot will do it).

I did a reboot.

1 Like

Sorry for the late heads up. Life’s been having plans I did not know about.

The only way I’ve been able to have the keyboard backlights turned on is with:

Restart=always
RestartSec=3

I’ve read up on unit files and their options; things get complicated rather fast as the options are interrelated and - for a noob like me - rather obscure in some cases.

I think I will try the oneshotoption [1] next.

[1]

Does not work either: backlights not turned on.

It sounds like something else is setting the backlight value later in the startup routine. If you could figure out what and stop it, that would resolve your issue.

Other than that, you could try changing the target to something which occurs later on in the login process like graphical-session.target.

[Unit]
Description=Set Keyboard light
After=graphical-session.target
Wants=graphical-session.target

[Service]
Type=simple
ExecStart=/usr/bin/kb-light.sh

[Install]
WantedBy=graphical-session.target