getumbrel / umbrel-apps

The official app repository of the Umbrel App Store. Submit apps and updates here. Learn how → https://github.com/getumbrel/umbrel-apps#readme
https://apps.umbrel.com
528 stars 398 forks source link

USB Accessory for Home Assistant on umbrel #581

Open jonnylangefeld opened 2 years ago

jonnylangefeld commented 2 years ago

I'm running the Home Assistant App on my umbrel on a raspberry pi and it works great. However, in the Home Assistant community it's pretty common to add a little USB dongle (not a storage medium) to integrate with zigbee or Z-Wave devices in your smart home. I bought the Zooz ZST10 700 and plugged it into my umbrel only to find out that the umbrel finds no USB devices except for the one external hard drive to store the blockchain on.

This is the relevant bit of code: https://github.com/getumbrel/umbrel/blob/703a5bc9757df631255ec5bd9c9dc773a24d67d4/scripts/umbrel-os/external-storage/mount#L66-L83

It attempts to unbind the external hard drive from the uas driver and binds it again with the usb-storage driver. That part actually does make sense cause I've tried to run umbrel with the hard drive bound with the uas driver and the entire raspberry pi is unresponsive and basically unusable.

However the two lines https://github.com/getumbrel/umbrel/blob/703a5bc9757df631255ec5bd9c9dc773a24d67d4/scripts/umbrel-os/external-storage/mount#L80-L81 actually unbind everything and for some reason only the hard drive comes back up again in the lsusb output.

I've tried to shutdown the raspberry pi, unplug the hard drive, plug int the USB dongle and restarting it. That makes the mount script exit early, because it doesn't find a bulk device. Then when I ssh into the raspberry pi, obviously umbrel is not running because it didn't find the hard drive, but the lsusb output shows the USB dongle:

# lsusb 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub 
Bus 001 Device 005: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP2102/CP2109 UART Bridge Controller [CP210x family] 
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

If I now plug in the hard drive, it shows up as well:

# lsusb
Bus 002 Device 003: ID 152d:0577 JMicron Technology Corp. / JMicron USA Technology Corp. 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub 
Bus 001 Device 005: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP2102/CP2109 UART Bridge Controller [CP210x family] 
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

# lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M 
    |__ Port 2: Dev 2, If 0, Class=Mass Storage, Driver=uas, 5000M 
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M 
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M 
        |__ Port 3: Dev 3, If 0, Class=Vendor Specific Class, Driver=cp210x, 12M 

Now with both, the dongle and the hard drive plugged in, I restart the umbrel, which triggers the run of the mount script. Once restarted umbrel is running again as normal and the external hard drive is mounted on /mnt/data. However, the dongle isn't recognized anymore. And for some resaon the VIA Labs, Inc. Hub entry is also gone:

# lsusb
Bus 002 Device 003: ID 152d:0577 JMicron Technology Corp. / JMicron USA Technology Corp. 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

# lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M 
    |__ Port 2: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M 
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M 

I have experimented with this while the hard drive wasn't plugged in during startup, so that the mount script wouldn't run. I have manually executed the two lines that the mount script would execute:

echo '0000:01:00.0' > '/sys/bus/pci/drivers/xhci_hcd/unbind'
echo '0000:01:00.0' > '/sys/bus/pci/drivers/xhci_hcd/bind'

Before the VIA Labs hub, the dongle and the hard drive are all there, and after only the hard drive is there.

I figured I have two options:

  1. Either unbind and bind the hard drive during the mount script in a way that doesn't unbind everything, but just the hard drive.
  2. Leave umbrel untouched and just run my own script that binds the VIA Labs hub and the Dongle back in.

I haven't had success with either of these options. Does anyone have an idea, how umbrel could switch to the external-usb driver while other non storage USB accessories are still usable?

jonnylangefeld commented 2 years ago

One workaround I just found is this:

Add the output of lsusb | awk '{print $6":u"}' | tr '\n' ',' | sed 's/,$//' to the usb-storage.quirks= comma separated list of the /boot/cmdline.txt file, then edit the mount file via vi /sd-root/home/umbrel/umbrel/scripts/umbrel-os/external-storage/mount and comment out this line: https://github.com/getumbrel/umbrel/blob/703a5bc9757df631255ec5bd9c9dc773a24d67d4/scripts/umbrel-os/external-storage/mount#L191

But that's not perfect because the next over-the-air update will override that line, and then during the next reboot of my system my USB dongle won't be recognized again. Any idea how to get around this?

mihaimetal commented 1 year ago

jonnylangefeld, thanks, that worked. My problem was with VirtualHere and Logitech G920 wheel.

Maybe Umbrel could use a List all usb devices and the option to whitelist in Settings.

Maximal73 commented 1 year ago

jonnylangefeld, I have same problem i'm using HA on Umbrel 0.5.3 on a rasberry PI 4 as usb dangle I take a sonoff ZB 3.0 Dongle-P, and then also a ConBee II to check if problem was sonoff dongle. I follow your workaround adding lsusb output to /boot/cmdline.txt and comment line 191 in mount, but HA still doesn't detect dongle. Do you find other solution about it ?

evercape commented 1 year ago

I have the same problem with a Sonoff Zigbee 3.0 USB Dongle E.

I will send this to umbrel team - ideally they permit whitelisting of USB devices in settings.

evercape commented 1 year ago

When I run lsusb I get the following:

`umbrel@umbrel:~ $ lsusb Bus 002 Device 002: ID 2109:0715 VIA Labs, Inc.

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub`

Here is an older link how someone added the device to the docker-compose.yaml in HASS however if umbrel OS does not even permit USB devices other than the main HD then this is an issue?

evercape commented 1 year ago

Me again: https://apps.umbrel.com/app/home-assistant

Apparently USB devices are now discovered:

This update brings Home Assistant to version 2023.7.1, and now includes USB Discovery! The previous update included automatic device discovery for devices connected to the same network, and the ability to save your personalized settings and automations.

Really odd, not working for me. I cannot find the Sonoff USB 3 device.

I am on Umbrel 0.5.4 and Home Assistant 2023.7.1 so the USB discovery should in theory work, however, when I go on SSH and do $ lsusb or $ lsblk I don't see the Zigbee dongle at all

CapGus commented 12 months ago

this dongle error still happening?

evercape commented 12 months ago

Yes. I moved away to dedicated NUC, HA in docker on umbrel just not reliant enough I am afraid.

dadofsambonzuki commented 9 months ago

I couldn't get this working either. USB (Sonoff USB 3) not recognised.