Luxafor makes a nice busy status indicator light for the office. Unfortunately it only provides software for Windows and Mac. But it’s not hard at all to get it working on Ubuntu with PyUSB.
1- You need PyUSB installed
pip install pyusb
2- PyUSB basically lets you do anything you want with the USB device including some pretty dangerous stuff so it’s naturally open to super users. It’d be really annoying to have to sudo every light control though, so we’ll open this one particular device to your user. Create a luxafor.rules file in /etc/udev/rules.d/ and put in:
SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="f372" MODE="0664", OWNER="[your user name]"
3- Reload udev with
sudo udevadm control --reload
sudo udevadm trigger
4- Create a Python script, say light.py, to make this easier to control
import argparse
import usb.coredef main():parser = argparse.ArgumentParser(description='Change Luxafor colour')
parser.add_argument('colour', choices=['green', 'yellow', 'red', 'blue', 'white', 'off'], help='colour to change to')
args = parser.parse_args()
colour_codes = {'green': 71, 'yellow': 89, 'red': 82, 'blue':66, 'white': 87, 'off': 79}dev = usb.core.find(idVendor=0x04d8, idProduct=0xf372)if dev is None:
print('Not connected')
returntry:
dev.detach_kernel_driver(0)
except usb.core.USBError:
passtry:
dev.set_configuration()
except usb.core.USBError:
print("Did you give Luxafor USB permission to your user?")
returndev.set_configuration()
dev.write(1, [0, 0])
dev.write(1, [0, colour_codes[args.colour]])if __name__ == '__main__':
main()
5- Control the colour with
python light.py green