Turris Omnia and Home Assistant in LXC Container

Turris Omnia hosting Homeassistant in LXC Container

In the Turris Omnia I have installed the AEOTEC ZWave Dongle, in the front USB port.

This is largely inspired by [1] and [2] and all credits belog to the author.

Assume we have the containers stored in /srv/lxc and the container is called homeassistant.

Install the kernel module

 # opkg update && opkg install kmod-usb-acm  

or 

# opkg update && opkg install kmod-usb-uhci  

Now I don't remember :(


Expose the USB to the LXC container

 Edit the /srv/lxc/homeassistant/config file and put there:

# Give an access to the USB with the Aeotec dongle
lxc.mount.entry = /dev/bus/usb dev/bus/usb none bind,optional,create=dir 0 0  
lxc.mount.entry = /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file 0 0

Setup the host system to expose the ttyACM0 device

Modify the device permission access using the hotplug system. Just create the following script:

# cat /etc/hotplug.d/usb/10-zwave 
ZWAVE_PRODID="658/200/0"
SYMLINK="zwave"
if [ "${PRODUCT}" = "${ZWAVE_PRODID}" ]; then
    if [ "${ACTION}" = "add" ]; then
        DEVICE_NAME=$(find /sys/${DEVPATH}/tty/ -name ttyACM* | grep -Eo "ttyACM.*$")
        if [ -z ${DEVICE_NAME} ]; then
            logger -t hotplug "20-zwave: Info: no tty device created - exiting"
            exit
        fi
  logger -t hotplug "20-zwave: determined ${DEVICE_NAME} as device name for Aeotec Z-Stick "
        /bin/chown root:plugdev /dev/${DEVICE_NAME}
        /bin/chmod 664 /dev/${DEVICE_NAME}
        logger -t hotplug "20-zwave: Changed access rights for /dev/${DEVICE_NAME}"
        ln -s /dev/${DEVICE_NAME} /dev/${SYMLINK}
        logger -t hotplug "20-zwave: Symlink /dev/${SYMLINK} -> /dev/${DEVICE_NAME} created"
    fi
    if [ "${ACTION}" = "remove" ]; then
        rm /dev/${SYMLINK}
        logger -t hotplug "20-zwave: Symlink /dev/${SYMLINK} removed"
    fi
fi
EOF

Make sure that the plugdev group is added
# groupadd -g 46 plugdev

Now after plugging the Zwave dongle back, you should see


# ls -l /dev/ttyACM0 
crw-rw-r--    1 root     plugdev   166,   0 Oct 28 00:24 /dev/ttyACM0


[1] https://klein-gedruckt.de/2016/12/turris-omnia-arduino-nano-usb/
[2] https://klein-gedruckt.de/2016/12/turris-omnia-zwave-install/

Comments

Popular posts from this blog

Controlling servo with RPi3B+

Turris Omnia Minidlna