Home Assistant Supervised (previously known as Hass.io) on Synology DSM as native package (not supported or working atm)

Did you run this first on your NAS?
ln -s /dev/YourdeviceUSB /dev/serial/by-id/usb-0658_USBDevice_ffffffd1ffffffb2ffffffdbffffffa0-if00

And also for your Other devices?

On Hassio i use the long USB path for my devices:
/dev/serial/by-id/usb-0658_USBDevice_ffffffd1ffffffb2ffffffdbffffffa0-if00

No, I didn’t do that as the like was existing to …/…/ttyUSB0 for example…

I will give it a try

I have done what you were saying, but after a restart of docker (home assistant), everything has been recreated as below:

I think it is normal, as the udev process restarted on the container and all the link has been recreated.

Please start a new thread with this issue and hopefully the developers of hass.io can explain how the entities are created so I can add it to the startup script in Synology.

You should create the links on your nas not in the container.

HI Fredrik,

I have seen my mistake when I have re-read the full thread :slight_smile: Now it is working. But if you create the links, it will work until your NAS reboot (until the udev process restart).

In order to make it more persistent you have to create a file (udev rules). I have created the file /lib/udev/rules.d/59-usb-serial.rules

I have added the 2 lines for my zwave USB key and for my RFX433 USB device:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="serial/by-id/usb-RFXCOM_RFXtrx433_A1YHLM21-if00-port0"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="serial/by-id/usb-0658_USBDevice_ffffffd1ffffffb2ffffffdbffffffad-if00"

After a reboot, the links were recreated with the good devices associated to it.

the idVendor and the idProduct could be different (depending of our USB devices). I have used the link https://www.domoticz.com/wiki/PersistentUSBDevices

What I think, we need to understand how Home assistant or Hassio is creating those devices to create this file automatically.

4 Likes

Great! My idea is to modify the startup script in the hassio package to create the symlinks automatically when the hassio package starts. The thing is that as you said, we need to understand what hassio are expecting. Please investigate more…

3 Likes

I can confirm that after configuring my udev on the Synology everything is working like a charm. Certificate are managed through my Synology and I am using the Synology reverse proxy. I have also configured the firewall to allow the Hassio network container. I think there is also something to do in the Synology package to propose during the installation.

I will try to see how to configure this udev file to add it automatically. If this can help.

Great job @fredrike ! I don’t need to adapt or create container any more for home assistant on my Synology which has a better performance compared to my rpi2.

1 Like

It works indeed like a charm!! Great job @fredrike!! Thanks a lot!

@fredrike, if you want to automatically create the symlinks via udev, it looks like the info required to create that ‘by-id’ string can be pulled from /proc/bus/usb/devices on the NAS

Great!

Do you have an example on how it might look?

I just pulled this together, based on info in /sys instead…this generates the right ‘by-id’ names for USB serial devices (for me):

for tty_path in $(find /sys/bus/usb/devices/usb*/ -name tty); do
        tty_iface_path=`dirname $tty_path`
        serial_device_path=`dirname $tty_iface_path`
        prefix=usb
        idVendor=`cat $serial_device_path/idVendor`
        product=`cat $serial_device_path/product`
        serial=`cat $serial_device_path/serial`
        bInterfaceNumber=`cat $tty_iface_path/bInterfaceNumber`
        echo $prefix-$idVendor\_$product\_$serial-if$bInterfaceNumber
done
1 Like

Great!

So which is best, using your script as base to generate /lib/udev/rules.d/59-usb-serial.rules and restart udev or manually create symlinks (in that case what is the device name eg. /dev/ttyUSB1)?

I would suggest using it to create the udev rules file - that seems much cleaner than boot script that I was using earlier.

You can adapt my example to pull the idProduct variable needed for the rules file. Just add

idProduct=`cat $serial_device_path/idproduct`

I assume you can take it from there?

Great, I was trying to do a script as well, but I got issues. Your script should help a lot.

When I have executed your lines, it was working only with my zwave USB key, not my RF433. I will invest age on my side as well.

The rules are the way to do, I agree.

Would this work if the function was added to /var/packages/hassio/target/bin/hassio.sh and fix_usb_devices is added in start_hassio ()

fix_usb_devices () {
    RULES_FILE="/lib/udev/rules.d/59-usb-serial.rules"

    for tty_path in $(find /sys/bus/usb/devices/usb*/ -name tty); do
        tty_iface_path=`dirname $tty_path`
        serial_device_path=`dirname $tty_iface_path`
        prefix=usb
        idVendor=`cat $serial_device_path/idVendor`
        product=`cat $serial_device_path/product`
        serial=`cat $serial_device_path/serial`
        bInterfaceNumber=`cat $tty_iface_path/bInterfaceNumber`
        idProduct=`cat $serial_device_path/idproduct`
        symLink="${prefix}-${idVendor}\_${product}\_${serial}-if${bInterfaceNumber}"
        line="SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"${idVendor}\", ATTRS{idProduct}==\"${idProduct}\", SYMLINK+=\"serial/by-id/${symLink}\""
        
        grep -s $symLink $RULES_FILE >/dev/null || \
            echo ${line} >> $RULES_FILE
    done

    udevadm control --reload
}
1 Like

The script that @MizterB was not working for me (100%), only /dev/ACMx was working, my /dev/USBx was not “discovered”.

Here is a fixed version:

#!/bin/bash
for tty_path in $(find /sys/bus/usb/devices/usb*/ -name tty); do
        tty_iface_path=`dirname $tty_path`
        serial_device_path=`dirname $tty_iface_path`
        prefix=usb
        if test -f "$serial_device_path/idVendor"; then
                
                idVendor=`cat $serial_device_path/idVendor`
                product=`cat $serial_device_path/product`
                idProduct=`cat $serial_device_path/idProduct`
                serial=`cat $serial_device_path/serial`
                bInterfaceNumber=`cat $tty_iface_path/bInterfaceNumber`
                echo SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"$idVendor\", ATTRS{idProduct}==\"$idProduct\", SYMLINK+=\"serial/by-id/$prefix-$idVendor\_$product\_$serial-if$bInterfaceNumber\"
        else
                bInterfaceNumber=`cat $serial_device_path/bInterfaceNumber`
                # We need to go up 1 level to get information
                serial_device_path=`dirname $serial_device_path`
                idVendor=`cat $serial_device_path/idVendor`
                product=`cat $serial_device_path/product`
                idProduct=`cat $serial_device_path/idProduct`
                serial=`cat $serial_device_path/serial`
                manufacturer=`cat $serial_device_path/manufacturer`
                echo SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"$idVendor\", ATTRS{idProduct}==\"$idProduct\", SYMLINK+=\"serial/by-id/$prefix-$manufacturer\_$product\_$serial-if$bInterfaceNumber-port0\"
        fi

done

1 Like

What about this script:

#!/bin/bash

fix_usb_devices () {
    RULES_FILE="/lib/udev/rules.d/59-usb-serial.rules"

    for tty_path in $(find /sys/bus/usb/devices/usb*/ -name tty); do
        tty_iface_path=`dirname $tty_path`
        serial_device_path=`dirname $tty_iface_path`
        prefix=usb
        if test -f "$serial_device_path/idVendor"; then
            bInterfaceNumber=`cat $tty_iface_path/bInterfaceNumber`
        else
            bInterfaceNumber=`cat $serial_device_path/bInterfaceNumber`
            # We need to go up 1 level to get information
            serial_device_path=`dirname $serial_device_path`
        fi
        idVendor=`cat $serial_device_path/idVendor`
        product=`cat $serial_device_path/product`
        idProduct=`cat $serial_device_path/idProduct`
        serial=`cat $serial_device_path/serial`
        manufacturer=`cat $serial_device_path/manufacturer`

        symLink="${prefix}-${idVendor}\_${product}\_${serial}-if${bInterfaceNumber}"
        line="SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"${idVendor}\", ATTRS{idProduct}==\"${idProduct}\", SYMLINK+=\"serial/by-id/${symLink}\""
        echo $line
        grep -s $symLink $RULES_FILE >/dev/null || \
            echo ${line} >> $RULES_FILE
    done

    udevadm control --reload
}

fix_usb_devices

Should be perfect :slight_smile:

I have noticed that something is going wrong. I was adding at the end “-port0” in the else case.