Turning off a single usb device... again

user2772761 picture user2772761 · Sep 12, 2013 · Viewed 31.3k times · Source

I know that this topic has been discussed many times, but none of the answers helped me. For the record, i'm running Debian.

The deal is: I bought an usb powered led lamp, which is very simple and doesn't even have an on/off switch (it works and is always on). I want to be able to turn it on/off via command line. Here's what i tried:

    echo on > /sys/bus/usb/devices/usb1/power/level       # turn on
    echo suspend > /sys/bus/usb/devices/usb1/power/level  # turn off

which is what i've found on many forums. Turning "on" works, but "suspending" yields

    -su: echo: write error: Invalid argument

for every usbN. I also tried

    echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms"

which doesn't give an error, but also doesn't do anything (again, for every usbN)

trying

    echo "usb1" > /sys/bus/usb/drivers/usb/unbind

works only for more "inteligent" devices, like the keyboard, the mouse, or the usb wifi card. What i mean is that only tyhose devices are turned off, other usbN don't give an error, but the lamp never goes off.

the contents of /sys/bus/usb/devices/ are

    1-0:1.0 1-1:1.0 1-2:1.0 1-2:1.2 2-0:1.0 4-0:1.0 4-1:1.0 6-0:1.0 8-0:1.0 8-2:1.0 usb2 usb4 usb6 usb8
    1-1 1-2 1-2:1.1 1-2:1.3 3-0:1.0 4-1 5-0:1.0 7-0:1.0 8-2 usb1 usb3 usb5 usb7

i tried to do

    echo device_name > /sys/bus/usb/drivers/usb/unbind

with every single one of them, but only the devices usbN and N-M react, the ones of the form n-m:x.y yield

    tee: /sys/bus/usb/drivers/usb/bind: No such device

(i tried putting in, for instance, "1-0:1.0", "1-0\:1.0" and "1-0\:1.0", all gave the same result).

One last thing, what is shown after executing

    lsusb -t

does not change when i plug or unplug the lamp.

Any ideas?

Answer

user3534136 picture user3534136 · Apr 15, 2014

Turn off device ID 2-1:

echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/unbind

Turn device ID 2-1 back on:

echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/bind

In my case, using device ID 2-1 controls power to my usb stick, and as a consequence controls the light.

  • TIP: If they work for you in Debian, create an alias for them to make life easier for you later.

Hope this helps, Su