hjr265.me / blog /

Allow External Keyboard to Wake Laptop

My setup at my workspace isn’t much: a display and a few peripherals connected to a USB-C hub. This way, I can come in, plug in the hub to my laptop, and start working.

But if my laptop goes to sleep, I can wake it up only by pressing a key on the internal keyboard or the trackpad. Since I keep the lid of my laptop closed, I have to take it out of the stand first, then open the lid (which causes the laptop to wake up anyway).

However, it is easy to let a USB device wake the laptop. The configuration is per USB port.

echo enabled > /sys/bus/usb/devices/usb3/power/wakeup

The easy route is to allow all the ports to wake the laptop up. But that doesn’t sit right with me.

Instead, I added a small udev rule to allow just one port to wake the laptop - the port where I connect the USB C hub. Which, in turn, my keyboard connects to.

1
2
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="2516", ATTRS{idProduct}=="0067" RUN+="/bin/sh -c 'echo enabled > /sys/bus/usb/devices/usb3/power/wakeup'"
ACTION=="remove", SUBSYSTEM=="usb", ATTRS{idVendor}=="2516", ATTRS{idProduct}=="0067" RUN+="/bin/sh -c 'echo disabled > /sys/bus/usb/devices/usb3/power/wakeup'"

The ArchWiki has a well-written outline around creating and managing udev rules.

The vendor ID, the product ID, and the USB bus number can be known using the lsusb command:

1
2
3
             Vendor ID ↓
Bus 003 Device 022: ID 2516:0067 Cooler Master Co., Ltd. MK750
      ↑ USB Bus             ↑ Product ID

This way, when I connect my keyboard, udev will enable wake-up on USB activity for that specific port. And it will be disabled when I disconnect the keyboard.

The only caveat is that I need to connect or disconnect the keyboard while the laptop is awake.


This post is 57th of my #100DaysToOffload challenge. Want to get involved? Find out more at 100daystooffload.com.


comments powered by Disqus