HomeAssistant
Goal
HomeAssistant running on Raspberry PI is one of way where you don’t have to rely on outside services to orchestrate your IOT. Then comes the issues of high availability of the software if only running on one PI. By dockerizing the software first, this open the doors to leverage a kubernetes cluster to ensure HA of the software
Key Aspects
- Use the 3 nodes Raspeberry Cluster
- Access the WIFI, ZWave and Zigbee network
- Leverage the Nortek HUSBZB-1 Zwave and Zigbee dongle.
- Install Home Assistant on node 2 of the cluster
What OS
- Home Assistant haas.io does not support Raspberry 3 B+ yet.
- haas.io is based on ResinOS. ResinOS is not using docker anymore but balena which does not support kubernetes yet See Issue
- Continue to use HyperiotOS
Install AppArmor and download docker container
cat newpgklist
apparmor-utils
apt-transport-https
avahi-daemon
ca-certificates
curl
dbus
jq
network-manager
socat
software-properties-common
for i in `cat newpgklist`
do
sudo apt-get install -y $i
done
Download and run the installation script. Will attempt to replace it by Kubernetes/Helm script.
curl -sL https://raw.githubusercontent.com/home-assistant/hassio-build/master/install/hassio_install > hassio_install
./hassio_install -m raspberrypi3
Installed Services
hassio-apparmor service
cat /etc/systemd/system/hassio-apparmor.service
[Unit]
Description=Hass.io AppArmor
Wants=hassio-supervisor.service
Before=docker.service hassio-supervisor.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/sbin/hassio-apparmor
[Install]
WantedBy=multi-user.target
cat /usr/sbin/hassio-apparmor
#!/bin/sh
set -e
# Load configs
CONFIG_FILE=/etc/hassio.json
# Read configs
DATA="$(jq --raw-output '.data // "/usr/share/hassio"' ${CONFIG_FILE})"
PROFILES_DIR=${DATA}/apparmor
CACHE_DIR="${PROFILES_DIR}/cache"
REMOVE_DIR="${PROFILES_DIR}/remove"
# Exists AppArmor
if ! command -v apparmor_parser > /dev/null 2>&1; then
echo "[Warning]: No apparmor_parser on host system!"
exit 0
fi
# Check folder structure
mkdir -p ${PROFILES_DIR}
mkdir -p ${CACHE_DIR}
mkdir -p ${REMOVE_DIR}
# Load/Update exists/new profiles
for profile in ${PROFILES_DIR}/*; do
if [ ! -f ${profile} ]; then
continue
fi
# Load Profile
if ! apparmor_parser -r -W -L ${CACHE_DIR} ${profile}; then
echo "[Error]: Can't load profile ${profile}"
fi
done
# Cleanup old profiles
for profile in ${REMOVE_DIR}/*; do
if [ ! -f ${profile} ]; then
continue
fi
# Unload Profile
if apparmor_parser -R -W -L ${CACHE_DIR} ${profile}; then
if rm ${profile}; then
continue
fi
fi
echo "[Error]: Can't remove profile ${profile}"
done
hassio-supervisor service
Main run seems to start hassio-supervisor
cat /etc/systemd/system/hassio-supervisor.service
[Unit]
Description=Hass.io supervisor
Requires=docker.service
After=docker.service dbus.socket
[Service]
Type=simple
Restart=always
RestartSec=5s
ExecStartPre=-/usr/bin/docker stop hassio_supervisor
ExecStart=/usr/sbin/hassio-supervisor
ExecStop=-/usr/bin/docker stop hassio_supervisor
[Install]
WantedBy=multi-user.target
cat /usr/sbin/hassio-supervisor
#!/bin/sh
set -e
# Load configs
CONFIG_FILE=/etc/hassio.json
SUPERVISOR="$(jq --raw-output '.supervisor' ${CONFIG_FILE})"
HOMEASSISTANT="$(jq --raw-output '.homeassistant' ${CONFIG_FILE})"
DATA="$(jq --raw-output '.data // "/usr/share/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
docker run --name hassio_supervisor \
$APPARMOR \
--security-opt seccomp=unconfined \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/run/dbus:/var/run/dbus \
-v ${HASSIO_DATA}:/data \
-e SUPERVISOR_SHARE=${HASSIO_DATA} \
-e SUPERVISOR_NAME=hassio_supervisor \
-e HOMEASSISTANT_REPOSITORY=${HOMEASSISTANT} \
${SUPERVISOR}
}
# Run supervisor
mkdir -p ${HASSIO_DATA}
([ "${HASSIO_IMAGE_ID}" = "${HASSIO_CONTAINER_ID}" ] && docker start --attach hassio_supervisor) || runSupervisor
Docker traces
docker ps shows homeassistance images downloaded but no controlled yet by Kubernetes
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e1fd86ed3b20 homeassistant/raspberrypi3-homeassistant "/bin/entry.sh pytho…" 28 minutes ago Up 28 minutes homeassistant
f05058843583 homeassistant/armhf-hassio-supervisor "python3 -m hassio" 30 minutes ago Up 30 minutes hassio_supervisor
65d89478378b d7ebe361fe95 "/usr/local/bin/kube…" 30 minutes ago Up 30 minutes k8s_kube-proxy_kube-proxy-4chwh_kube-system_68b68391-80b7-11e8-acaf-b827ebd5ad4c_2
9b8c7c2d431e k8s.gcr.io/pause:3.1 "/pause" 30 minutes ago Up 30 minutes k8s_POD_kube-proxy-4chwh_kube-system_68b68391-80b7-11e8-acaf-b827ebd5ad4c_2
8513e6cc5125 184e05022e7f "/opt/bin/flanneld -…" About an hour ago Up About an hour k8s_kube-flannel_kube-flannel-ds-wqxsz_kube-system_95f94b5f-80ba-11e8-acaf-b827ebd5ad4c_2
1aee6f79fe8e k8s.gcr.io/pause:3.1 "/pause" About an hour ago Up About an hour k8s_POD_kube-flannel-ds-wqxsz_kube-system_95f94b5f-80ba-11e8-acaf-b827ebd5ad4c_1
# docker attach --sig-proxy=false f05058843583
18-07-06 06:50:19 INFO (MainThread) [hassio.addons] Load addons: 41 all - 41 new - 0 remove
18-07-06 06:50:19 INFO (MainThread) [hassio.updater] Fetch update data from https://s3.amazonaws.com/hassio-version/stable.json
18-07-06 06:50:19 INFO (MainThread) [hassio.snapshots] Found 0 snapshot files
18-07-06 06:50:19 INFO (MainThread) [__main__] Run HassIO
18-07-06 06:50:19 INFO (MainThread) [hassio.misc.dns] Start DNS port forwarding for host add-ons
18-07-06 06:50:19 INFO (MainThread) [hassio.core] Ignore Hass.io auto updates on dev channel
18-07-06 06:50:19 INFO (MainThread) [hassio.core] Start API on 172.30.32.2
18-07-06 06:50:19 INFO (MainThread) [hassio.addons] Startup initialize run 0 addons
18-07-06 06:50:19 INFO (MainThread) [hassio.addons] Startup system run 0 addons
18-07-06 06:50:19 INFO (MainThread) [hassio.addons] Startup services run 0 addons
18-07-06 06:50:21 INFO (SyncWorker_0) [hassio.docker.homeassistant] Start homeassistant homeassistant/raspberrypi3-homeassistant with version 0.73.0b6
18-07-06 06:51:01 INFO (MainThread) [hassio.homeassistant] Detect a running Home-Assistant instance
18-07-06 06:51:01 INFO (MainThread) [hassio.addons] Startup application run 0 addons
18-07-06 06:51:01 INFO (MainThread) [hassio.tasks] All core tasks are scheduled
18-07-06 06:51:01 INFO (MainThread) [hassio.core] Hass.io is up and running
First Setup
Zigbee/ZWave support
Enable the zigbee/zwave dongle
Locate the container
sudo docker ps | grep homea
1fba92d1b40e homeassistant/raspberrypi3-homeassistant "/bin/entry.sh pytho…" 34 minutes ago Up 34 minutes homeassistant
4c3f66563a3c homeassistant/armhf-hassio-supervisor "python3 -m hassio" 6 hours ago Up 34 minutes hassio_supervisor
Enter the docker container
sudo docker exec -ti 1fba92d1b40e /bin/bash
Edit the configuration file
vi /config/configuration.yaml
zwave:
usb_path: /dev/ttyUSB0
zha:
usb_path: /dev/ttyUSB1
database_path: /config/zigbee.db
Reload the configuration file Access the UI and invoked reload core
http://192.168.1.92:8123/config/core
sudo docker ps | grep homea
702fd9424bfd homeassistant/raspberrypi3-homeassistant "/bin/entry.sh pytho…" 40 seconds ago Up 38 seconds homeassistant
4c3f66563a3c homeassistant/armhf-hassio-supervisor "python3 -m hassio" 6 hours ago Up 43 minutes hassio_supervisor
Let’s get back in zigbee.db now exists
sudo docker exec -ti 702fd9424bfd /bin/bash
bash-4.4# ls -lt
total 1928
-rw-r--r-- 1 root root 1802240 Jul 6 21:05 home-assistant_v2.db
-rw-r--r-- 1 root root 32768 Jul 6 21:05 home-assistant_v2.db-shm
-rw-r--r-- 1 root root 32 Jul 6 21:05 home-assistant_v2.db-wal
-rw-r--r-- 1 root root 14971 Jul 6 21:05 OZW_Log.txt
-rw-r--r-- 1 root root 45056 Jul 6 21:05 zigbee.db
-rw-r--r-- 1 root root 227 Jul 6 21:05 home-assistant.log
-rw-r--r-- 1 root root 32768 Jul 6 21:05 pyozw.sqlite
-rw-r--r-- 1 root root 1122 Jul 6 21:05 options.xml
-rw-r--r-- 1 root root 1866 Jul 6 21:01 configuration.yaml
drwxr-xr-x 2 root root 4096 Jul 6 06:50 tts
-rw-r--r-- 1 root root 2 Jul 6 06:50 automations.yaml
-rw-r--r-- 1 root root 0 Jul 6 06:50 customize.yaml
-rw-r--r-- 1 root root 0 Jul 6 06:50 groups.yaml
-rw-r--r-- 1 root root 0 Jul 6 06:50 scripts.yaml
-rw-r--r-- 1 root root 157 Jul 6 06:50 secrets.yaml
drwxr-xr-x 2 root root 4096 Jul 6 06:50 deps
HomeAssistant UI Screenshots
Conclusion
- Installation could not proceed further without solving the ZWave SUC Controller aspect.
- Not willing to break my Lowe’s IRIS based network yet and wanted to used Raspberry PI as a SUC Controller (see other post)
- Also need to understand how to create persistency volume in Kubernetes in the PI Cluster (see other post)
- Will be able to remove the dedicated the systemctl services since Kubernetes will control thoses.
Links and Repos
Discovery seems to need –network host if you want to discover the UPnP devices