You are not logged in.

#1 2025-07-22 07:58:09

matheos
Member
Registered: 2025-07-22
Posts: 4

Razer keyboard lights not turning off at shutdown

Hello

I am currently transitioning from Fedora to Arch (btw) and I am right now setting up everything as I want it, based on what I had on Fedora. I have a Razer Ornata V2 keyboard with RGB lights and a Corsair Harpoon RGB mouse.
On Fedora, I initially had issues with getting the keyboard lights to turn off completely after turning the PC off. A simple fix was ofc to disable USB power in S4 (or whatever state it now was) in BIOS. This is not however what I want, as I want to be able to charge my USB headset even with the PC turned off.
In Fedora, my workaround was a simple shutdown.target systemd service which simply calls a script which loops through all USB devices and sets autosuspend_delay_ms to 0 and power/control to auto. This worked just fine and was my solution in Fedora.

In Arch, this does work for all peripherals BUT the keyboard.. The mouse correctly is switched off (as well as my other BT mouse), but the keyboard stays lit... sad

❯ cat /opt/before-shutdown-script/before-shutdown.service
[Unit]
Description=Unbind usb devices before shutdown
DefaultDependencies=no
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/opt/before-shutdown-script/script.sh
TimeoutStartSec=0

[Install]
WantedBy=shutdown.target

❯ cat /opt/before-shutdown-script/script.sh
#!/bin/bash

for dev in /sys/bus/usb/devices/*
do
    echo '0' | sudo tee "$dev/power/autosuspend_delay_ms"
    echo 'auto' | sudo tee "$dev/power/control"
done

I have tried various other solutions, such as openrazer-daemon + mode setting as well as usbreset utility which seemingly is bundled with arch or some dependency I have installed. Both only managed to disable the "main Enter key" on the keyboard but the rest of the keyboard stayed functional and lit (when ran manually as a test). I eventually uninstalled openrazer as it had no effect, I confirmed this in Fedora too (my solution works without it).

This is my lsusb

❯ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 002: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 003 Device 003: ID 0b05:18f3 ASUSTek Computer, Inc. AURA LED Controller
Bus 003 Device 004: ID 2516:0051 Cooler Master Co., Ltd. AMD SR4 lamplight Control
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 002: ID 05e3:0610 Genesys Logic, Inc. Hub
Bus 005 Device 003: ID 045e:0779 Microsoft Corp. LifeCam HD-3000
Bus 005 Device 004: ID 1038:2232 SteelSeries ApS SteelSeries Arctis Nova 5
Bus 005 Device 005: ID 1b1c:1b3c Corsair Corsair Gaming HARPOON RGB Mouse
Bus 005 Device 006: ID 1532:025d Razer USA, Ltd RZ03-0338, Gaming Keyboard [Ornata V2]
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 006 Device 002: ID 05e3:0626 Genesys Logic, Inc. Hub

❯ lsusb -t
/:  Bus 001.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/6p, 480M
/:  Bus 002.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 10000M
/:  Bus 003.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/6p, 480M
    |__ Port 002: Dev 002, If 0, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 002: Dev 002, If 1, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 002: Dev 002, If 2, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 004: Dev 003, If 0, Class=Vendor Specific Class, Driver=[none], 12M
    |__ Port 004: Dev 003, If 2, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 005: Dev 004, If 0, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 005: Dev 004, If 1, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 005: Dev 004, If 2, Class=Human Interface Device, Driver=usbhid, 12M
/:  Bus 004.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 10000M
/:  Bus 005.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 480M
    |__ Port 001: Dev 002, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 001: Dev 003, If 0, Class=Video, Driver=uvcvideo, 480M
        |__ Port 001: Dev 003, If 1, Class=Video, Driver=uvcvideo, 480M
        |__ Port 001: Dev 003, If 2, Class=Audio, Driver=snd-usb-audio, 480M
        |__ Port 001: Dev 003, If 3, Class=Audio, Driver=snd-usb-audio, 480M
        |__ Port 002: Dev 004, If 0, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 002: Dev 004, If 1, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 002: Dev 004, If 2, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 002: Dev 004, If 3, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 002: Dev 004, If 4, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 002: Dev 004, If 5, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 003: Dev 005, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 003: Dev 005, If 1, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 004: Dev 006, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 004: Dev 006, If 1, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 004: Dev 006, If 2, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 004: Dev 006, If 3, Class=Human Interface Device, Driver=usbhid, 12M
/:  Bus 006.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/4p, 10000M
    |__ Port 001: Dev 002, If 0, Class=Hub, Driver=hub/4p, 5000M

As you see, my Keyboard is connected via a "hub" which is a usb switch (generic off brand). This is likely causing some issues, but I really don't want to give up on it as I use it daily, and, as mentioned, it works on Fedora..

I did notice that my DE, KDE Plasma, DOES manage to turn off the keyboard lights correctly instantly when the screen goes black (screen saver). This is quite interesting, as that means I could potentially try to replicate whatever "it" does, but in my script instead.
No idea why this works on Fedora but not on Arch.. sad

Last edited by matheos (2025-07-22 08:02:37)

Offline

#2 2025-07-23 09:46:16

ankabo
Member
Registered: 2025-07-14
Posts: 16

Re: Razer keyboard lights not turning off at shutdown

Hi,

have you installed the "openrazer-daemon"?

Install:

paru -S openrazer-daemon
paru -S razer-cli
systemctl enable --now openrazer-daemon

Check your keyboard:

razer-cli -l

Check if this works:

razer-cli set-brightness 0

If it is working, you can use a script like this - Create "/etc/systemd/system/usb-shutdown.service" with this:

[Unit]
Description=Custom USB Powerdown Script
DefaultDependencies=no
Before=poweroff.target halt.target shutdown.target reboot.target

[Service]
Type=oneshot
ExecStart=/opt/before-shutdown-script/script.sh
TimeoutSec=0
RemainAfterExit=yes

[Install]
WantedBy=poweroff.target halt.target shutdown.target reboot.target

And this is the script you are calling in the ExecStart:

#!/bin/bash

# Razer LEDs off
if command -v razer-cli &>/dev/null; then
    razer-cli set-brightness -a 0
fi

# Standard-USB-Autosuspend
for dev in /sys/bus/usb/devices/*
do
    echo '0' > "$dev/power/autosuspend_delay_ms" 2>/dev/null
    echo 'auto' > "$dev/power/control" 2>/dev/null
done

After that:

sudo systemctl daemon-reload
sudo systemctl enable usb-shutdown.service

Last edited by ankabo (2025-07-23 09:54:14)

Offline

#3 2025-07-23 10:43:42

matheos
Member
Registered: 2025-07-22
Posts: 4

Re: Razer keyboard lights not turning off at shutdown

Thanks for the suggestion!

Unfortunately, it does not work all the way for me (yet).

I did consider razer-daemon + razer-cli earlier but I was hoping to avoid these altogether. Anyway, I gave it a shot and these are the current state and remaining challenges

- razer-cli --brightness 0 works fine when running manually
- razer-cli unfortunately cannot run as root (which a system service would) as the DBUS_SESSION_BUS_ADDRESS is not set for non-user sessions

Traceback (most recent call last):

  File "/usr/bin/razer-cli", line 8, in <module>

    sys.exit(main())

             ~~~~^^

  File "/usr/lib/python3.13/site-packages/razer_cli/razer_cli/main.py", line 27, in main

    device_manager = DeviceManager()

  File "/usr/lib/python3.13/site-packages/openrazer/client/__init__.py", line 22, in __init__

    session_bus = _dbus.SessionBus()

  File "/usr/lib/python3.13/site-packages/dbus/_dbus.py", line 209, in __new__

    return Bus.__new__(cls, Bus.TYPE_SESSION, private=private,

           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

                       mainloop=mainloop)

                       ^^^^^^^^^^^^^^^^^^

  File "/usr/lib/python3.13/site-packages/dbus/_dbus.py", line 99, in __new__

    bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)

  File "/usr/lib/python3.13/site-packages/dbus/bus.py", line 120, in __new__

    bus = cls._new_for_bus(address_or_type, mainloop=mainloop)

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead

/opt/before-shutdown-script/script.sh: line 13: syntax error near unexpected token `done'

/opt/before-shutdown-script/script.sh: line 13: `done'

- razer-cli --brightness is not reset on boot, so I would need to set it back to 100 (or whatever) on boot too

I tried (with the help of AI) to create a user service that runs on shutdown and/or logout which hopefully would be able to run the command as a "lingering" service from the user session. I am yet to get this working though... (

❯ cat .config/systemd/user/razer-brightness-off.service
[Unit]
Description=Turn off Razer device brightness on logout/shutdown
# Ensure openrazer-daemon is available and running as a user service
After=openrazer-daemon.service

[Service]
Type=oneshot
# ExecStop is triggered when the service is stopped (during shutdown)
ExecStart=/usr/bin/true
ExecStop=/usr/bin/razer-cli --brightness 0
RemainAfterExit=yes

[Install]
WantedBy=default.target
WantedBy=exit.target
❯ systemctl --user status razer-brightness-off.service
● razer-brightness-off.service - Turn off Razer device brightness on logout/shu>
     Loaded: loaded (/home/matheos/.config/systemd/user/razer-brightness-off.se>
     Active: active (exited) since Wed 2025-07-23 13:34:04 EEST; 5min ago
 Invocation: e493f14893ef40c9ba9447fd59bbd829
   Main PID: 768 (code=exited, status=0/SUCCESS)
   Mem peak: 1.7M
        CPU: 4ms

Possibly I am confusing the .targets or whatever, but I did confirm the exit.target is reached so I am not sure why the service is not run. I also use sudo loginctl enable-linger matheos. Starting and, more importantly, stopping the service manually gives the desired effect.

This is currently where I am stuck. I don't think I can get it to run as part of my original system service (as razer-daemon runs as a user service), and I would also need to do a startup service or something to turn the brightness back ON when I turn on the machine... Any ideas?

Offline

#4 2025-07-23 13:11:05

Xephon
Member
Registered: 2024-12-22
Posts: 189

Re: Razer keyboard lights not turning off at shutdown

Why do you need a user service? Just run a login/logout script.

In KDE System Settings->Autostart->Add New (button in the upper right corner)

Offline

#5 2025-07-24 07:36:58

matheos
Member
Registered: 2025-07-22
Posts: 4

Re: Razer keyboard lights not turning off at shutdown

Xephon wrote:

Why do you need a user service? Just run a login/logout script.

In KDE System Settings->Autostart->Add New (button in the upper right corner)

Wow, that was easy! Thanks for the tip. This worked very well.

The only thing I would argue now that is missing is some way of recognizing whether it is actually "logout only" or a complete shutdown. I would like to keep the keyboard lit for regular logouts. Likewise, it would be nice if I could get it lit BEFORE login on boot as if I start the PC in a dark room, I can't see anything on the keyboard (need to enter my password) smile Any suggestions how to make this possible? Potentially this won't be possible with KDE autostart? sad

Offline

#6 2025-07-24 07:51:13

SimonJ
Member
From: Alicante, Spain
Registered: 2021-05-11
Posts: 306
Website

Re: Razer keyboard lights not turning off at shutdown

matheos wrote:
Xephon wrote:

Why do you need a user service? Just run a login/logout script.

In KDE System Settings->Autostart->Add New (button in the upper right corner)

Wow, that was easy! Thanks for the tip. This worked very well.

The only thing I would argue now that is missing is some way of recognizing whether it is actually "logout only" or a complete shutdown. I would like to keep the keyboard lit for regular logouts. Likewise, it would be nice if I could get it lit BEFORE login on boot as if I start the PC in a dark room, I can't see anything on the keyboard (need to enter my password) smile Any suggestions how to make this possible? Potentially this won't be possible with KDE autostart? sad

Eventually you will learn to touch type ;-)


Rlu: 222126

Offline

#7 2025-07-24 12:15:39

Xephon
Member
Registered: 2024-12-22
Posts: 189

Re: Razer keyboard lights not turning off at shutdown

...some way of recognizing whether it is actually "logout only" or a complete shutdown

Not sure if it's possible. You might try to create a python script that subscribes to PrepareForShutdownWithMetadata signal from org.freedesktop.login1.Manager D-Bus interface and see if type value is different for logout and shutdown

...it would be nice if I could get it lit BEFORE login on boot as if I start the PC in a dark room, I can't see anything on the keyboard...

Take a look at this:
https://github.com/openrazer/openrazer/ … -(systemd)

Offline

#8 2025-07-25 21:30:39

matheos
Member
Registered: 2025-07-22
Posts: 4

Re: Razer keyboard lights not turning off at shutdown

Xephon wrote:

Not sure if it's possible. You might try to create a python script that subscribes to PrepareForShutdownWithMetadata signal from org.freedesktop.login1.Manager D-Bus interface and see if type value is different for logout and shutdown

Hmm... Thanks. I may investigate this in the future but rn, can't be asked big_smile

Thanks a ton for this link. It was extremely helpful. I got that working, along my other "parts" of the solution, so now the keyboard does light up before login. due to my new system service:

[Unit]
Description=Apply OpenRazer brightness on boot
After=multi-user.target
Requires=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/openrazer-prelogin.sh
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

and script:

❯ sudo cat /usr/local/bin/openrazer-prelogin.sh
#!/bin/bash

# Allow time for the kernel to initialise devices
sleep 2

# Bumps the keyboard brightness to max (255) on boot
for dev in /sys/bus/hid/devices/0003:1532:*/matrix_brightness
do
    if [[ -w "$dev" ]]; then
        echo -ne "255" > "$dev"
        echo "Set full brightness for $dev (Razer keyboard)"
    fi
done

This works fine, but it does not replace my current solutions as for now, a manual LOCK or logout will trigger the logout script which turns the keyboard off. To turn it BACK on after such an event, I need my current KDE login script (autostart). For boot, the new one and the autostart login script kind of overlaps with each other, but that's fine.

The only downside now is the fact that if I logout or lock the computer AFTER booting, the keyboard will of course stay off. As suggested, I could investigate the python script way for that, but it is already feeling a bit "too hacky" for my liking tongue Kind of feels like I should wrap this solution up in a git repo so I don't loose it if I distro hop or install a new system...

Thanks for the brilliant suggestions! Further improvements are ofc welcome, but I would consider the main issue resolved (unless knitpicking... The NUMLOCK light stays lit on shutdown/lock/logout ?)

Offline

Board footer

Powered by FluxBB