Skip to content

Commit

Permalink
Add software package: Home Assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Nov 22, 2024
1 parent 82cf417 commit 0d04aaf
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 0 deletions.
Binary file added tools/include/images/HA003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions tools/include/markdown/HA003-footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
|Functionality|HAOS|Armbian with HA|
|:--|:--:|:--:|
|Automations|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|
|Dashboards|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|
|Integrations|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|
|Add-ons|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|
|One-click updates|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|
|Backups|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:|
|General purpose server|:x:|:white_check_mark:|
|Running on exotic hardware|:x:|:white_check_mark:|
16 changes: 16 additions & 0 deletions tools/include/markdown/HA003-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Home Assistant is an open source smart home platform that allows you to connect your smart home devices like your TV, fan, cameras, thermostats, lights, and sensors. As a user, you can build intricate automation using Home Assistant's user-friendly, unified web-based user interface.

Perfect to run on any single board computer with 4 cores and at least 512Mb of memory. Armbian installation is optimised to run from SD/eMMC media, but it is recommended to use SSD.

=== "Access to the web interface"

The web interface is accessible via port **8123**:

- URL: `https://<your.IP>:8123`
- Username/Password: Are set at first web interface login

=== "Directories"

Home Assistant on Armbian runs supervised in a Docker container. This secures same functionality as stock HAOS.

- Config directory: `/usr/share/haos`
20 changes: 20 additions & 0 deletions tools/json/config.software.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,26 @@
"status": "Stable",
"author": "@armbian",
"condition": "check_if_installed openhab"
},
{
"id": "HA003",
"description": "Install Home Assistant",
"command": [
"module_haos install"
],
"status": "Preview",
"author": "@igorpecovnik",
"condition": "! check_if_installed homeassistant-supervised && grep -q bookworm /etc/os-release"
},
{
"id": "HA004",
"description": "Remove Home Assistant",
"command": [
"module_haos uninstall"
],
"status": "Preview",
"author": "@igorpecovnik",
"condition": "check_if_installed homeassistant-supervised"
}
]
},
Expand Down
156 changes: 156 additions & 0 deletions tools/modules/software/install_haos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
declare -A module_options
module_options+=(
["module_haos,author"]="@igorpecovnik"
["module_haos,feature"]="module_haos"
["module_haos,example"]="help install uninstall"
["module_haos,desc"]="Hos container install and configure"
["module_haos,ports"]="8123"
["module_haos,status"]="review"
)
#
# Install haos container
#
module_haos() {

case "${ARCH}" in
armhf) MACHINE="tinker";;
amd64) MACHINE="generic-x86-64";;
arm64) MACHINE="odroid-n2";;
esac


# dependency
# command -v unzip systemd-journal-remote apparmor cifs-utils nfs-common network-manager udisks2

# ha agent
[[ "${ARCH}" == "armhf" ]] && local ha_os_agent_arch="armv7"
[[ "${ARCH}" == "arm64" ]] && local ha_os_agent_arch="aarch64"
[[ "${ARCH}" == "amd64" ]] && local ha_os_agent_arch="x86_64"
local ha_os_agent_cache_dir=$(mktemp -d /tmp/XXXXXXXXXX)
local ha_os_agent_version="1.6.0"
local ha_os_supervised_commit="c99ffd00fcb32c06fc4140040c9ee7e919becce9"
local ha_os_agent_filename="os-agent_${ha_os_agent_version}_linux_${ha_os_agent_arch}.deb"
local ha_os_agent_url="https://github.com/home-assistant/os-agent/releases/download/${ha_os_agent_version}/${ha_os_agent_filename}"
local ha_os_agent_cache_file="${ha_os_agent_cache_dir}/${ha_os_agent_filename}"

# supervised deb: all
local ha_supervised_version="1.6.0"
local ha_supervised_filename="homeassistant-supervised_${ha_supervised_version}.deb"
local ha_supervised_url="https://github.com/home-assistant/supervised-installer/releases/download/${ha_supervised_version}/homeassistant-supervised.deb"
local ha_supervised_cache_file="${ha_os_agent_cache_dir}/${ha_supervised_filename}"

if check_if_installed docker-ce; then
local container=$(docker container ls -a | mawk '/home-assistant/{print $1}')
local image=$(docker image ls -a | mawk '/home-assistant/{print $3}')
fi
# Convert the example string to an array
local commands
IFS=' ' read -r -a commands <<< "${module_options["module_haos,example"]}"

case "$1" in
"${commands[0]}")
## help/menu options for the module
echo -e "\nUsage: ${module_options["module_haos,feature"]} <command>"
echo -e "Commands: ${module_options["module_haos,example"]}"
echo "Available commands:"
if [[ "${container}" ]] || [[ "${image}" ]]; then
echo -e "\tstatus\t- Show the status of the $title service."
echo -e "\tremove\t- Remove $title."
else
echo -e " install\t- Install $title."
fi
echo
;;
install)
check_if_installed docker-ce || install_docker

# hack to force install
sed -i 's/^PRETTY_NAME=".*/PRETTY_NAME="Debian GNU\/Linux 12 (bookworm)"/g' "${SDCARD}/etc/os-release"

# we host packages at our repository and version for both is determined:
# https://github.com/armbian/os/blob/main/external/haos-agent.conf
# https://github.com/armbian/os/blob/main/external/haos-supervised-installer.conf

apt_install_wrapper apt-get -y install --download-only homeassistant-supervised os-agent

# this we can't put behind wrapper
MACHINE="${MACHINE}" apt-get -y install homeassistant-supervised os-agent

# workarounding supervisor loosing healthy state https://github.com/home-assistant/supervisor/issues/4381
cat <<- SUPERVISOR_FIX > "/usr/local/bin/supervisor_fix.sh"
#!/bin/bash
while true; do
if ha supervisor info 2>&1 | grep -q "healthy: false"; then
echo "Unhealthy detected, restarting" | systemd-cat -t $(basename "$0") -p debug
systemctl restart hassio-supervisor.service
sleep 600
else
sleep 5
fi
done
SUPERVISOR_FIX

# add executable bit
chmod +x "/usr/local/bin/supervisor_fix.sh"

# generate service file to run this script
cat <<- SUPERVISOR_FIX_SERVICE > "/etc/systemd/system/supervisor-fix.service"
[Unit]
Description=Supervisor Unhealthy Fix
[Service]
StandardOutput=null
StandardError=null
ExecStart=/usr/local/bin/supervisor_fix.sh
[Install]
WantedBy=multi-user.target
SUPERVISOR_FIX_SERVICE

if [[ -f /boot/armbianEnv.txt ]]; then
echo "extraargs=systemd.unified_cgroup_hierarchy=0 apparmor=1 security=apparmor" >> "/boot/armbianEnv.txt"
fi

for s in {1..10};do
for i in {0..100..10}; do
j=$i
echo "$i"
sleep 1
done
ha supervisor info --raw-json >/dev/null
if [[ $status -eq 0 ]]; then break; fi
done | $DIALOG --gauge "Preparing Home Assistant Supervised\n\nPlease wait! " 10 50 0

# enable service
systemctl enable supervisor-fix >/dev/null 2>&1
systemctl start supervisor-fix >/dev/null 2>&1

$DIALOG --msgbox "Reboot is required to finish installation.\n\nAfter reboot, you need to wait few minutes that website on port 8123 becomes available! " 10 46
;;
uninstall)
# disable service
systemctl disable supervisor-fix >/dev/null 2>&1
systemctl stop supervisor-fix >/dev/null 2>&1
apt_install_wrapper apt-get -y purge homeassistant-supervised os-agent
TERM=linux $DIALOG --infobox "Removing Home Assistant containers.\n\nPlease wait! " 6 40
if [[ "${container}" ]]; then
echo "${container}" | xargs docker stop >/dev/null 2>&1
echo "${container}" | xargs docker rm >/dev/null 2>&1
fi
if [[ "${image}" ]]; then
echo "${image}" | xargs docker image rm >/dev/null 2>&1
fi
rm -f /usr/local/bin/supervisor_fix.sh
rm -f /etc/systemd/system/supervisor-fix.service
sed -i "s/ systemd.unified_cgroup_hierarchy=0 apparmor=1 security=apparmor//" /boot/armbianEnv.txt
systemctl daemon-reload >/dev/null 2>&1
# restore os-release
sed -i "s/^PRETTY_NAME=\".*/PRETTY_NAME=\"${VENDOR} ${REVISION} ($VERSION_CODENAME)\"/g" "/etc/os-release"
;;
status)
[[ "${container}" ]] || [[ "${image}" ]] && return 0
;;
esac
}

module_haos "$1"

0 comments on commit 0d04aaf

Please sign in to comment.