USB Wakeup Settings?

When I put my PC to sleep, I’d like to be able to disable my keyboard and mouse from waking my pc, but allow my bluetooth and xbox controllers to wake the pc.

I have achieved this by creating a bash script that changes the wakeup state of the specific USB devices, the script for that is listed below.

#!/bin/bash
sudo chmod 666 /sys/bus/usb/devices/1-7.2/power/wakeup
sudo echo “disabled” > /sys/bus/usb/devices/1-7.2/power/wakeup #disables keyboard usb wakeup
sudo chmod 644 /sys/bus/usb/devices/1-7.2/power/wakeup

sudo chmod 666 /sys/bus/usb/devices/1-13.4/power/wakeup
sudo echo “disabled” > /sys/bus/usb/devices/1-13.4/power/wakeup #disables mouse usb wakeup
sudo chmod 644 /sys/bus/usb/devices/1-13.4/power/wakeup

sudo chmod 666 /sys/bus/usb/devices/1-13.1/power/wakeup
sudo echo “enabled” > /sys/bus/usb/devices/1-13.1/power/wakeup #enables bluetooth usb wakeup
sudo chmod 644 /sys/bus/usb/devices/1-13.1/power/wakeup

I have attempted to create a service that runs this script on startup butI am unable to make it start when booting or rebooting my pc. If I run the script and then only put my pc to sleep the wakeup states stay as I’d like them, however when rebooting the script must be manually run again.

Any help would be appreciated.

You can use this to find which devices can wake your PC:

for device in /sys/bus/usb/devices/*/power/wakeup; do 
    echo "$device - $(cat $device)"
done

And then for each of those run echo "disabled" | sudo tee /sys/bus/usb/devices/1-6/power/wakeup (where 1-6 is the device id).

You can add a service file like this at /etc/systemd/system/disable-usb-wake.service:

  GNU nano 8.1                                                                                                     /etc/systemd/system/disable-usb-wake.service                                                                                                                
[Unit]
Description=Disable USB Wake
After=suspend.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo "disabled" | sudo tee /sys/bus/usb/devices/1-6/power/wakeup'

[Install]
WantedBy=suspend.target

then run sudo systemctl daemon-reload and sudo systemctl enable --now disable-usb-wake. Worked for me, hope it will work for you as well!

1 Like

There’s a better way. Put something like this into /etc/udev/rules.d/wakeup.rules:

# Prevent Logitech (046d) Bolt (c548) devices from waking up the computer
ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c548", ATTR{power/wakeup}="disabled"

You’ll have to replace the vendor and device codes (046d and c548 respectively) with whatever device is waking up your PC. It’s usually not hard to figure that out, e.g.:

$ lsusb
...
Bus 001 Device 003: ID 046d:c548 Logitech, Inc. Logi Bolt Receiver
...

This is both easier to do, and it’s also independent of which USB port the device is plugged in.