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
2 Likes

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.

thankyou so muxh for this post. I am trying it now.
I think there is a typo repeated a few times in it: “…/storage.config/…” instead of " … /storage/.config/"

1 Like

Anyone had luck installing HA supervised on CE?

If not, would it be possible to install HA and ESP home dockers ? Any tips / guides greatly appreciated.

A long time ago I tested homeassistant and it worked fine but in my case I only have one surveillance camera and to monitor it I hardly need anything.

If you want to investigate I recommend using the docker homeassistant/home-assistant service, you just need to have the docker addon installed, run the SSH command

docker run --init -d \
   --name 8123-homeassistant \
   --restart=unless-stopped \
   -v /etc/localtime:/etc/localtime:ro \
   -v /storage/.config/dockers/homeassistant/config:/config \
   --network=host \
   homeassistant/home-assistant

and configure it from http://[coreelec-device-ip]:8123

(I don’t know if it works now, I last tested it a year ago)

1 Like

Thanks, this works. Any idea how one could install Home Assistant addons on CE? For eg I managed to install ESPHome using some hacks.

I used entware and opkg to install python3 and pip

then as shown here I used

pip3 install --user esphome

to install esphome.

then

pip install tornado esptool
esphome dashboard config/

this makes esphome dashboard config available on :6052
but dashboard doesn’t seem to automatically restart after reboot. Have to issue the dashboard config/ line above, each time.

I tried

echo 'esphome dashboard config/' >> $HOME/.profile

but this fills the command session with a lot of logs.

Another addon I would be interested in incorporating would be MQTT, but no idea where to begin.

This has stopped working.

When checking docker container status it says " S6-overlay-suexec: fatal: can only run as pid 1"

It doesn’t seem to be a CoreELEC problem. Look here S6-overlay-suexec: fatal: can only run as pid 1 - Installation - Home Assistant Community

I managed to get full hassio with supervisor working a few months back, and also DuckDNS with Let’s encrypt certificate for HTTPS access, HACS, and some other integrations. I created directory /storage/hassio and changed a few paths pointing there and copied supervisor’s startup script from an armbian installation.

X88King:~ # cat /storage/hassio/hassio-supervisor
#!/usr/bin/env bash
set -e

# Load configs
CONFIG_FILE=/storage/hassio/hassio.json

SUPERVISOR="$(jq --raw-output '.supervisor' ${CONFIG_FILE})"
MACHINE="$(jq --raw-output '.machine' ${CONFIG_FILE})"
DATA="$(jq --raw-output '.data // "/storage/hassio"' ${CONFIG_FILE})"

# AppArmor Support
if command -v apparmor_parser > /dev/null 2>&1 && grep hassio-supervisor /sys/kernel/security/apparmor/profiles > /dev/null 2>&1; then
    APPARMOR="--security-opt apparmor=hassio-supervisor"
else
    APPARMOR="--security-opt apparmor:unconfined"
fi

# Init supervisor
HASSIO_DATA=${DATA}
HASSIO_IMAGE_ID=$(docker inspect --format='{{.Id}}' "${SUPERVISOR}")
HASSIO_CONTAINER_ID=$(docker inspect --format='{{.Image}}' hassio_supervisor || echo "")

runSupervisor() {
    docker rm --force hassio_supervisor || true

    # shellcheck disable=SC2086
    docker run --name hassio_supervisor \
        --privileged \
        $APPARMOR \
        --security-opt seccomp=unconfined \
        -v /run/docker.sock:/run/docker.sock \
        -v /run/dbus:/run/dbus \
        -v /etc/machine-id:/etc/machine-id:ro \
        -v "${HASSIO_DATA}":/data:rw \
        -e SUPERVISOR_SHARE="${HASSIO_DATA}" \
        -e SUPERVISOR_NAME=hassio_supervisor \
        -e SUPERVISOR_MACHINE="${MACHINE}" \
        "${SUPERVISOR}"
}

# Run supervisor
mkdir -p "${HASSIO_DATA}"
([ "${HASSIO_IMAGE_ID}" = "${HASSIO_CONTAINER_ID}" ] && docker start --attach hassio_supervisor) || runSupervisor

and put it into /storage/.config/autostart.sh

/storage/hassio/hassio-supervisor 2>&1 > /storage/hassio/hassio-supervisor.log;

I also installed IOT Link in my home laptop/server to control battery charge cycles from 20% to 80% with a meross smart plug and an automation.

I remember I had to upgrade CoreELEC to version 19.X as it has an updated docker, needed for supervisor to work properly.

3 Likes




ramoncio: Maybe you could write some quick tutorial for installation? Just some main points what to do. I’m sure it could be useful to someone.

3 Likes

Sorry, I really don’t remember all the steps, it was really dirty and I didn’t take notes, just did it as a test, as I already had a woking armbian supervisor. But finally it replaced my armbian hassio…
It took a couple of days of struggle, I rsynced docker directory from armbian (from /var/lib/docker to docker’s kodi addon directory), and then did wildcard replacements with find and sed to correct the wrong paths in docker’s filesystems.
I just found this commands in my history

mkdir /storage/hassio/
...
rsync -avz root@192.168.1.50:/usr/share/hassio/ /storage/hassio/
rsync -avz root@192.168.1.50:/var/lib/docker/ /storage/.kodi/userdata/addon_data/service.system.docker/docker/
find /storage/.kodi/userdata/addon_data/service.system.docker/docker/containers \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i 's,/var/lib/docker,/storage/.kodi/userdata/addon_data/service.system.docker/docker,g'
find /storage/.kodi/userdata/addon_data/service.system.docker/docker/containers \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i 's,/usr/share/hassio,/storage/hassio,g'

Really dirty, as I said :slight_smile:
Maybe I can upload a backup of docker’s addon and /storage/hassio somewhere, but first I would need to delete all my personal data.