Running HomeAssistant on CE

Hi,

This topic is for those of you trying to run Docker containers that use python-zeroconf and get the error messages like “[Errno 98] Address already in use”.
Example are the HomeAssistant and ESPHome containers.

Context:

HomeAssistant requires to set the network mode as host, meaning that all ports that are open by the container will be bind to the hosts (in this case CE) interface.

The missing information is that HomeAssistant auto discovery uses python-zeroconf that needs to bind to UDP port 5353, that is the port used for nDNS, zeroconf, avahi, bonjour (whatever you want to call it)

But by default CE’s avahi-daemon configuration denies to have multiple processes binding to that port, as per: https://github.com/CoreELEC/CoreELEC/blob/2d16550a390c8e93815d07a113aadb7dc4632811/packages/network/avahi/package.mk#L60

Solution:

Solution 1: the neatest solution would be to open a PR to change the default value :slight_smile: but despite the age of the comment (2013) I’m afraid that it would cause issues to some users.

Solution 2: But there’s a workaround, one just need to have a configuration file that allows multiple processes to bind to the above mentioned UDP port and restart the avahi-daemon with this new file.

Run:

cp /etc/avahi/avahi-daemon.conf /storage/.config/avahi-daemon.conf
sed -e "s,^.*disallow-other-stacks=.*$,disallow-other-stacks=no,g" -i /storage/.config/avahi-daemon.conf

Create the file /storage/.config/system.d/avahi-daemon-stacks.service with the contents:

[Unit]
Description=Avahi Daemon
After=network.target avahi-defaults.service
Requires=avahi-defaults.service
ConditionPathExists=/storage/.cache/services/avahi.conf

[Service]
Restart=on-failure
EnvironmentFile=-/run/libreelec/debug/avahi.conf
ExecStart=/usr/sbin/avahi-daemon -f /storage/.config/avahi-daemon.conf -s $AVAHI_DEBUG
ExecReload=/usr/sbin/avahi-daemon -r
TimeoutStopSec=1s
RestartSec=2
StartLimitInterval=60
StartLimitBurst=10

[Install]
WantedBy=multi-user.target

And finally, create a /storage.config/autostart.sh if you don’t have one yet, don’t forget to add execution bit (chmod +x /storage.config/autostart.sh) and add the followinf to it:

( 
systemctl stop avahi-daemon
sleep 2
systemctl start avahi-daemon-proxy
) &

Hope it works for you, good luck

3 Likes

Hi,

Thanks for this. I’m trying to run HASS on my N2.
Which docker image should I use? Linux image or Raspberrypi3 image?

Thanks

EDIT:
got it running :slight_smile:

docker run -d --name homeassistant --restart=always -v /storage/homeassistant:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/aarch64-homeassistant:latest
1 Like

Hi! Thanks for your notes!
I got it running, however, I can’t connect my tradfri bulbs to my conbee II.
Works fine in windoze though! Yay!

It says one is supposed to add user to the dialout group, but I’m root, even though its through docker right?

Hi! Thanks for the solution. But is it possible to also running hass.io(aarch64-hassio-supervisor) as a docker container? Like this one
Running HomeAssistant on CE

Yeah, it would be nice to get supervisor going.

I modified script a bit based of this one, source here:
Don’t forget to start it with the right -m
I.e : ./hassio-install.sh -m aach64

It pulls from docker, and that’s about it. If anyone could diagnose this a bit further would help a lot!! Thanks!

#!/usr/bin/env bash
set -e

ARCH=$(uname -m)
DOCKER_BINARY=/storage/.kodi/addons/service.system.docker/bin/docker
DOCKER_REPO=homeassistant
DOCKER_SERVICE=docker.service
URL_VERSION="https://version.home-assistant.io/stable.json"
URL_SERVICE_HASSIO="https://raw.githubusercontent.com/home-assistant/hassio-installer/master/files/hassio-supervisor.service"
URL_BIN_HASSIO="https://raw.githubusercontent.com/home-assistant/hassio-installer/master/files/hassio-supervisor"
URL_SERVICE_HASSIO="https://raw.githubusercontent.com/home-assistant/hassio-installer/master/files/hassio-supervisor.service"

# Check env
command -v systemctl > /dev/null 2>&1 || { echo "[Error] Only systemd is supported!"; exit 1; }
command -v docker > /dev/null 2>&1 || { echo "[Error] Please install docker first"; exit 1; }
command -v jq > /dev/null 2>&1 || { echo "[Error] Please install jq first"; exit 1; }
command -v curl > /dev/null 2>&1 || { echo "[Error] Please install curl first"; exit 1; }
command -v avahi-daemon > /dev/null 2>&1 || { echo "[Error] Please install avahi first"; exit 1; }
command -v dbus-daemon > /dev/null 2>&1 || { echo "[Error] Please install dbus first"; exit 1; }

# Check if Modem Manager is enabled
if systemctl list-unit-files ModemManager.service | grep enabled; then
    echo "[Warning] ModemManager service is enabled. This might cause issue when using serial devices."
fi

# Detect if running on snapped docker
if docker >/dev/null 2>&1; then
    DOCKER_BINARY=/storage/.kodi/addons/service.system.docker/bin/docker
    DATA_SHARE=/storage/.opt/snap/docker/common/hassio
    CONFIG=$DATA_SHARE/hassio.json
    DOCKER_SERVICE="docker..service"
fi

# Parse command line parameters
while [[ $# -gt 0 ]]; do
    arg="$1"

    case $arg in
        -m|--machine)
            MACHINE=$2
            shift
            ;;
        -d|--data-share)
            DATA_SHARE=$2
            shift
            ;;
        -p|--prefix)
            PREFIX=$2
            shift
            ;;
        -s|--sysconfdir)
            SYSCONFDIR=$2
            shift
            ;;
        *)
            echo "[Error] Unrecognized option $1"
            exit 1
            ;;
    esac
    shift
done

PREFIX=${PREFIX:-/storage/.opt}
SYSCONFDIR=${SYSCONFDIR:-/storage/.opt/etc}
DATA_SHARE=${DATA_SHARE:-$PREFIX/.opt/etc/share/hassio}
CONFIG=$SYSCONFDIR/hassio.json
DOCKER_SERVICE="docker.service"
# Generate hardware options
case $ARCH in
    "i386" | "i686")
        MACHINE=${MACHINE:=qemux86}
        HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
        HASSIO_DOCKER="$DOCKER_REPO/i386-hassio-supervisor"
    ;;
    "x86_64")
        MACHINE=${MACHINE:=qemux86-64}
        HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
        HASSIO_DOCKER="$DOCKER_REPO/amd64-hassio-supervisor"
    ;;
    "arm" |"armv6l")
        if [ -z $MACHINE ]; then
            echo "[ERROR] Please set machine for $ARCH"
            exit 1
        fi
        HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
        HASSIO_DOCKER="$DOCKER_REPO/armhf-hassio-supervisor"
    ;;
    "armv7l")
        if [ -z $MACHINE ]; then
            echo "[ERROR] Please set machine for $ARCH"
            exit 1
        fi
        HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
        HASSIO_DOCKER="$DOCKER_REPO/armv7-hassio-supervisor"
    ;;
    "aarch64")
        if [ -z $MACHINE ]; then
            echo "[ERROR] Please set machine for $ARCH"
            exit 1
        fi
        HOMEASSISTANT_DOCKER="$DOCKER_REPO/$MACHINE-homeassistant"
        HASSIO_DOCKER="$DOCKER_REPO/aarch64-hassio-supervisor"
    ;;
    *)
        echo "[Error] $ARCH unknown!"
        exit 1
    ;;
esac

if [ -z "${HOMEASSISTANT_DOCKER}" ]; then
    echo "[Error] Found no Home Assistant Docker images for this host!"
fi

### Main

# Init folders
if [ ! -d "$DATA_SHARE" ]; then
    mkdir -p "$DATA_SHARE"
fi

# Read infos from web
HASSIO_VERSION=$(curl -s $URL_VERSION | jq -e -r '.supervisor')

##
# Write configuration
cat > "$CONFIG" <<- EOF
{
    "supervisor": "${HASSIO_DOCKER}",
    "homeassistant": "${HOMEASSISTANT_DOCKER}",
    "data": "${DATA_SHARE}"
}
EOF

##
# Pull supervisor image
echo "[Info] Install supervisor Docker container"
docker pull "$HASSIO_DOCKER:$HASSIO_VERSION" > /dev/null
docker tag "$HASSIO_DOCKER:$HASSIO_VERSION" "$HASSIO_DOCKER:latest" > /dev/null

##
# Install Hass.io Supervisor
echo "[Info] Install supervisor startup scripts"
curl -sL ${URL_BIN_HASSIO} > "${PREFIX}"/sbin/hassio-supervisor
curl -sL ${URL_SERVICE_HASSIO} > "${SYSCONFDIR}"/systemd/system/hassio-supervisor.service

sed -i "s,%%HASSIO_CONFIG%%,${CONFIG},g" "${PREFIX}"/sbin/hassio-supervisor
sed -i -e "s,%%DOCKER_BINARY%%,${DOCKER_BINARY},g" \
       -e "s,%%DOCKER_SERVICE%%,${DOCKER_SERVICE},g" \
       -e "s,%%HASSIO_BINARY%%,${PREFIX}/sbin/hassio-supervisor,g" \
       "${SYSCONFDIR}"/systemd/system/hassio-supervisor.service

chmod a+x "${PREFIX}"/sbin/hassio-supervisor
systemctl enable hassio-supervisor.service

#Not in coreelec
# Install Hass.io AppArmor
#if command -v apparmor_parser > /dev/null 2>&1; then
#    echo "[Info] Install AppArmor scripts"
#    mkdir -p "${DATA_SHARE}"/apparmor
#    curl -sL ${URL_BIN_APPARMOR} > "${PREFIX}"/sbin/hassio-apparmor
#    curl -sL ${URL_SERVICE_APPARMOR} > "${SYSCONFDIR}"/systemd/system/hassio-apparmor.service
#    curl -sL ${URL_APPARMOR_PROFILE} > "${DATA_SHARE}"/apparmor/hassio-supervisor
#
#    sed -i "s,%%HASSIO_CONFIG%%,${CONFIG},g" "${PREFIX}"/sbin/hassio-apparmor
#    sed -i -e "s,%%DOCKER_SERVICE%%,${DOCKER_SERVICE},g" \
#	   -e "s,%%HASSIO_APPARMOR_BINARY%%,${PREFIX}/sbin/hassio-apparmor,g" \
#	   "${SYSCONFDIR}"/systemd/system/hassio-apparmor.service
#
#    chmod a+x "${PREFIX}"/sbin/hassio-apparmor
#    systemctl enable hassio-apparmor.service
#    systemctl start hassio-apparmor.service
#fi

##
# Init system
echo "[Info] Run Hass.io"
systemctl start hassio-supervisor.service

Friends there is a topic for beginners without (knowledge Advanced)
I have a google home mini I would like to use with CoreELEC.
Can someone direct me to a topic.
My knowledge is minimal.
Thank you.

It would be really nice if it is possible to install home assistant supervised. It would make Coreelec perfect.

Yeah to me coreelec combined with basking in the glory of the N2, can be the perfect solution to many service related things.

I picked up today were I left of jan, I am still on the same note, can’t get access to things like:
zha: usb_path: /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_ radio_type: deconz
Which is “somewhat” essential.
I’m looking at socat & ser2net.

If anyone have had be better luck, please yell loudly in here.

did you manage to install home assistant supervised ? i tried your script but the supervisor wont start with systemctl.
When i start it manually it will start but it gets stuck;
20-08-05 19:38:05 WARNING (MainThread) [supervisor.updater] Can’t process version data: ‘aach64’

The docker images get’s pulled and that’s about it with that script.

You have to choose the right architecture.
If you run it without -m, it should tell you what it is.

About | FAQ | Terms of Service | Privacy Policy | Legal Notice