Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add software package: Home Assistant #235

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions tools/modules/runtime/config.runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ update_sub_submenu_data "Software" "Media" "SW24" "https://localhost:$emby_media

plex_media_port="$(lsof -i -P -n | grep TCP | grep LISTEN | grep 'plex' | awk -F: '{print $2}' | awk '{print $1}' | head -n 1)"
update_sub_submenu_data "Software" "Media" "SW22" "https://localhost:$plex_media_port"

update_sub_submenu_data "Software" "HomeAutomation" "HA004" "http://$LOCALIPADD:${module_options["module_haos,port"]}"
149 changes: 149 additions & 0 deletions tools/modules/software/install_haos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
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,port"]="8123"
["module_haos,status"]="review"
)
#
# Install haos container
#
module_haos() {



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

# this hack will allow running it on minimal image, but this has to be done properly in the network section, to allow easy switching
systemctl disable systemd-networkd

# 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

# determine machine type
case "${ARCH}" in
armhf) MACHINE="tinker";;
amd64) MACHINE="generic-x86-64";;
arm64) MACHINE="odroid-n2";;
*) exit 1;;
esac

# 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
sleep 5
for s in {1..10};do
for i in {0..100..10}; do
j=$i
echo "$i"
sleep 1
done
if [[ -n "$(docker container ls -a | mawk '/hassio-cli/{print $1}')" ]]; then
ha supervisor info --raw-json >/dev/null
if [[ $status -ne 0 ]]; then break; fi
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

# restore os-release
sed -i "s/^PRETTY_NAME=\".*/PRETTY_NAME=\"${VENDOR} ${REVISION} ($VERSION_CODENAME)\"/g" "/etc/os-release"

# show that its done
$DIALOG --msgbox "Home assistant is available at\n\nhttps://${LOCALIPADD}:8123 " 10 38
;;
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
echo -e "Removing Home Assistant containers.\n\nPlease wait few minutes! "
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"