There is also a javascript possible way even though it's not perfect
- Install this package:
https://www.npmjs.com/package/usb-detection
sudo npm install usb-detection
- Edit your NR settings.js and add the line with the usbDetect:
functionGlobalContext: {
//tellduslive:require('telldus-live'),
//noble:require('noble'),
SunCalc:require('suncalc'),
usbDetect:require('usb-detection'),
-
Restart NR
-
Import the flow below, click ONCE only on "Start usb monitoring"
[{"id":"7b3a1756.5c8518","type":"function","z":"60f50465.20a53c","name":"","func":"var usbDetect = global.get('usbDetect');\n\nif(msg.payload){\n usbDetect.startMonitoring();\n node.warn('started usb monitoring');\n \n usbDetect.on('add', function(device) {\n device.state = \"connected\";\n node.send(device);\n });\n \n usbDetect.on('remove', function(device) {\n device.state = \"removed\";\n node.send(device);\n });\n}\n\nif(!msg.payload){\n usbDetect.stopMonitoring();\n node.warn('stopped usb monitoring');\n}\n\n","outputs":1,"noerr":0,"x":1020,"y":130,"wires":[["b7c8d674.1671c8"]]},{"id":"b7c8d674.1671c8","type":"debug","z":"60f50465.20a53c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1200,"y":130,"wires":[]},{"id":"a3913d80.f3765","type":"inject","z":"60f50465.20a53c","name":"Start usb monitoring","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":780,"y":130,"wires":[["7b3a1756.5c8518"]]},{"id":"523afc6c.afbbb4","type":"inject","z":"60f50465.20a53c","name":"Stop usb monitoring","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":780,"y":230,"wires":[["7b3a1756.5c8518"]]}]
- Remove & then connect a usb device and check the result in the debug window. I tested with a usb memory stick and a usb camera, I received a notification for both. In the function node I have added the property state so that you easily can identify if the device was "connected" or "removed"
PLEASE note that you can only start the monitoring once. If you change the code in the function node after the monitoring has started, you may have to reboot the Pi before those changes works. Read more here why: https://github.com/MadLittleMods/node-usb-detection/issues/53