Allows you to control usb power through a HomeKit device using the uhubctl command and the hc library. This has only been tested on the Raspberry Pi with Raspberry Pi OS Buster.
The method used to turn off a USB device is a bit heavy handed as it turns off all USB ports and should be used in a headless Raspberry Pi setup where you don't depend a USB keyboard, mouse, or and other USB device.
uhubctl
is required and can be installed on debian based distros with apt:
sudo apt install -y uhubctl
The uhubctl
command requires root access so you can build and run with the following command:
go build .
sudo ./usb-smart-switch
One way to run this command at boot is to add the following to /etc/rc.local:
usbSmartSwitchDir={path_to_usb-smart-switch}
cd ${usbSmartSwitchDir}
${usbSmartSwitchDir}/usb-smart-switch &