themactep.com

A home of miscellaneous projects by Paul Philippov.

Notes

Installing HomeAssistant on Armbian

# Home-assistant does require python 3.8+.
# Armbian buster comes with python 3.7. Hence bullseye!

echo "# Debian bullseye
deb http://deb.debian.org/debian bullseye main contrib non-free
" > /etc/apt/sources.d/debian-bullseye.list

echo "# Armbian bullseye
deb http://apt.armbian.com bullseye main bullseye-utils bullseye-desktop
" > /etc/apt/sources.d/armbian-bullseye.list

# Before we started, let's replace vim with neovim.
# Starting from v8.2 vim brings the whole lot of shit in dependencies.
apt remove --purge vim
apt install neovim

# Upgrade to bullseye.
apt update
apt full-upgrade -y
apt autoremove --purge -y

# Install ffmpeg for cameras
apt install ffmpeg -y

# Install mariaDB server, create database and user
apt install mariadb-server
mariadb-admin create home_assistant
mariadb -e "GRANT ALL PRIVILEGES ON home_assistant.* 
 TO 'hass'@'localhost' IDENTIFIED BY 'secret!'; FLUSH PRIVILEGES;"

# Install headers required in further compilations.
apt install python-dev libffi-dev libjpeg-dev libmariadb-dev -y

# Clean apt cache to free disk space.
apt clean

# Create a user for home-assistant and act like one.
adduser ha
su ha
cd

# Create python virtual environment and install home-assistant.
python3 -m venv homeassistant
cd homeassistant
source bin/activate
python3 -m pip install wheel
python3 -m pip install idna==2.9
python3 -m pip install mysqlclient
python3 -m pip install homeassistant

# Add systemd service file
echo "# Home Assistant
[Unit]
Description=Home Assistant
After=network-online.target mariadb.service

[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant
ExecStart=/home/%i/homeassistant/bin/hass -c "/home/%i/.homeassistant"
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
" > /etc/systemd/system/home-assistant@ha.service

sudo systemctl --system daemon-reload
sudo systemctl enable home-assistant@ha
sudo systemctl start home-assistant@ha