These instructions have been deprecated and re-written for a newer version of Home Assistant.
They are only kept here for reference purposes.
Introduction Link to heading
Welcome to the 2024.4
version of running Home Assistant in a FreeBSD Bastille Jail.
This page is here to provide a walkthrough for anyone wanting to run Home Assistant on FreeBSD for the first time, or provide guidance on what needs to be installed manually if you are upgrading from a previous release of HA.
Some of these instructions are copied forward from my previous posts on setting up the jail and creating an rc script for HA. My aim is provide a single page containing everything that a new user needs to install HA Core.
If you have any suggestions or notice any errors, please let me know by email: ‘blog’ at ’the primary-domain.com’ or via mastodon: @brendan@mastodon.brendans-bits.com
homeassistant
user, and installed pyenv
, you can skip straight to UpgradingSoftware versions (tested 2024-04-19) Link to heading
- FreeBSD 14.0 (quarterly)
- Bastille 0.10.20231125
- Python 3.12.2 (installed in a python virtual environment)
- Home Assistant Core 2024.4.3
These instructions install the core
version of HA.
You will need to install additional software manually. For example:
The supervisor and add-ons do not work with this method because they are installed in docker containers.
New installations - start here Link to heading
Setting up the host Link to heading
First we create the jail:
# bastille create -V home-assistant-test 14.0-RELEASE "DHCP SLAAC" igb0
# bastille console home-assistant-test
I prefer to use VNET jails so that I can assign IP addresses later.
Setting up the jail Link to heading
Jail dependencies Link to heading
First, we install some required dependencies:
# pkg update
# pkg install \
bash \
ca_root_nss \
cmake \
ffmpeg \
git \
openblas \
openjpeg \
pkgconf \
pyenv \
rust \
sqlite3 \
vim
Create an rc script for HA Link to heading
If you are installing HA for the first time, you may want to have FreeBSD’s rc system manage HA.
Create a new script file in the jail at /usr/local/etc/rc.d/homeassistant
:
#!/bin/sh
# PROVIDE: homeassistant
# REQUIRE: DAEMON NETWORKING
# KEYWORD: shutdown
# Version 20240323
#
# homeassistant_enable: Enable the Home Assistant service
# Required: Yes
# Default: "NO"
#
# homeassistant_environment: Path to where you have installed Home Assistant Core
# Required: Yes
# Default: ""
# This needs to provide a path to the Python virtual environment
# where you have installed Home Assistant Core
#
# homeassistant_user: The user that will run Home Assistant Core
# Required: No
# Default: "homeassistant"
#
# homeassistant_group: The group that will run Home Assistant Core
# Required: No
# Default: "homeassistant"
#
# homeassistant_log_folder: Where Home Assistant Core will store logs
# Required: Yes
# Default: "/var/log/homeassistant/"
#
# homeassistant_config_folder: Where Home Assistant Core stores config files and database
# Required: Yes
# Default: "/home/homeassistant/.homeassistant"
#
# homeassistant_run_options: Other flags to pass to Home Assistant Core
# Required: No
# Default: ""
# Any flags that can be passed to `hass` go here. Examples include:
# - `--verbose` to enable verbose logging
# Note: `--ignore-os-check`, --log-file`, and `--config` are already passed.
. /etc/rc.subr
name="homeassistant"
rcvar=homeassistant_enable
load_rc_config $name
: ${homeassistant_enable:="NO"}
: ${homeassistant_environment:=""}
: ${homeassistant_user:="homeassistant"}
: ${homeassistant_group:="homeassistant"}
: ${homeassistant_log_folder="/var/log/homeassistant"}
: ${homeassistant_config_folder="/home/homeassistant/.homeassistant"}
: ${homeassistant_run_options=""}
pid_directory=/var/run/homeassistant
pidfile="${pid_directory}/${name}_child.pid"
ppidfile="${pid_directory}/${name}_daemon.pid"
homeassistant_command="${homeassistant_environment}/bin/python ${homeassistant_environment}/bin/hass"
command="/usr/sbin/daemon"
procname="${homeassistant_environment}/bin/python"
procname_args="${homeassistant_environment}/bin/hass --ignore-os-check --config=${homeassistant_config_folder} --log-file=${homeassistant_log_folder}/homeassistant-daemon.log"
command_args="-p ${pidfile} -P ${ppidfile} -f -r ${procname} ${procname_args} ${homeassistant_run_options} ${rc_flags}"
start_precmd="${name}_prestart"
homeassistant_prestart()
{
# Check if PIF directory exists
if [ ! -d ${pid_directory} ]; then
install -d -o ${homeassistant_user} ${pid_directory}
fi
# Check that the log folder exists
if [ ! -e ${homeassistant_log_folder} ]; then
install -d -o ${homeassistant_user} -g ${homeassistant_group} -m 760 ${homeassistant_log_folder}
fi
# Check if the HA env variable has been set
if [ -z ${homeassistant_environment} ]; then
echo "Please set 'homeassistant_environment=' in /etc/rc.conf" && exit 1
fi
# Check if the provided HA environment actually exists
if [ ! -e ${homeassistant_environment}/bin/hass ]; then
echo "Home Assistant script not found - please install Home Assistant" && exit 1
fi
}
# Custom status command adapted from:
# https://github.com/tprelog/iocage-homeassistant/blob/master/overlay/usr/local/etc/rc.d/homeassistant
status_cmd=${name}_status
homeassistant_status() {
local _http_ _ip_
if [ -n "${rc_pid}" ]; then
: "${homeassistant_secure:="NO"}" # This is only a cosmetic variable - used by the status_cmd
_ip_="$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')"
checkyesno homeassistant_secure && _http_="https" || _http_="http"
echo "${name} is running as pid ${rc_pid}."
echo "${_http_}://${_ip_}:${homeassistant_port:-"8123"}" # This is only a cosmetic variable
${homeassistant_environment}/bin/python --version
${homeassistant_environment}/bin/hass --version
else
echo "${name} is not running."
return 1
fi
}
stop_cmd="${name}_stop"
homeassistant_stop()
{
echo "Stopping PID: $(cat ${ppidfile})"
/bin/kill -9 $(cat ${ppidfile})
echo "Stopping PID: $(cat ${pidfile})"
/bin/kill -15 $(cat ${pidfile})
}
run_rc_command "$1"
Add the following lines to the jail’s /etc/rc.conf
:
homeassistant_enable="YES"
homeassistant_environment="/home/homeassistant/HA-2024.4"
homeassistant_log_folder="/var/log/homeassistant"
homeassistant_config_folder="/home/homeassistant/.homeassistant"
homeassistant_run_options="--verbose"
Setting up a user Link to heading
Then we create a dedicated user for Home Assistant:
# pw useradd homeassistant -w no -m -c "Home Assistant"
# pw groupmod dialer -m homeassistant
# chmod 770 /home/homeassistant
# pw usermod homeassistant -s /usr/local/bin/bash
I prefer to use bash as my shell and the rest of the commands assume that you are also using bash.
Installing python for the user Link to heading
These instructions are taken from decuser over at the FreeBSD forums
We need to switch to the homeassistant
user and install Python 3.12 using pyenv:
# su - homeassistant
$ pyenv install 3.12.2
$ pyenv global 3.12.2
$ pyenv init
# Load pyenv automatically by appending
# the following to
# your shell's login startup file (for login shells)
# and your shell's interactive startup file (for interactive shells) :
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Restart your shell for the changes to take effect.
You will have to add the following lines to ~/.bashrc
and ~/.profile
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Finally, we leave the homeassistant
use shell and switch back into it to check that pyenv
has loaded its shims correctly:
$ exit
# su - homeassistant
$ echo $PATH
/home/homeassistant/.pyenv/shims:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/homeassistant/bin
$ python --version
Python 3.12.2
Upgrading - start here Link to heading
Setting up a python virtual environment Link to heading
If you were able to successfully install Python 3.12, you can create a virtual environment to install Home Assistant.
$ mkdir HA-2024.4
$ cd HA-2024.4
$ python -m venv .
$ source bin/activate
I choose to name the python virtual environment according to the version of HomeAssistant that I plan to install in that PVE.
If all goes well, you will notice your shell change to:
(HA-2024.4) home assistant jail ~/HA-2024.4 $
This indicates that the home-assistant
environment is being used.
We update pip
and install wheel
:
$ pip install --upgrade pip
$ pip install wheel
Setting up additional python dependencies Link to heading
There are two packages that do not automatically install correctly for HA Core 2024.4.
webrtc-noise-gain Link to heading
Version 1.2.3 of webrtc-noise-gain
does not build on FreeBSD.
Some patches have been submitted into commit a5ea46f, after version 1.2.3 was released.
$ pip install git+https://github.com/rhasspy/webrtc-noise-gain.git@a5ea46ffa29e76d5bde2b0bafaa28bee21cb7415
This is a known issue.
numpy Link to heading
You need to install numpy
manually from the instructions here
$ git clone https://github.com/numpy/numpy.git numpy-git
$ cd numpy-git
$ git checkout v1.26.0
$ git cherry-pick 040ed2d
$ git submodule update --init
$ cd ..
$ pip install numpy-git/
Installing Home Assistant Link to heading
Finally, we’re ready to install Home Assistant.
Stop any existing HA installations (if you are upgrading from a previous version) Link to heading
If you are upgrading from a previous version of HA Core, you need to stop any HA service that is running.
Please make sure you have a backup of your HA configuration folder before installing any new version of HA. For example:
$ cp -r .homeassistant/ .homeassistant-backup/
Install and test the new version of HA Link to heading
We’re going to let HA install the rest of its dependencies and check that it is working
$ pip install homeassistant~=2024.4.0
$ hass --ignore-os-check -v -c /home/homeassistant/.homeassistant
hass
will now install more dependencies.
After several minutes, you can go to xx.xx.xx.xx:8123
and be greeted by the Home Assistant landing page:
Check for any missing custom dependencies Link to heading
If you have installed any custom components that require additional dependencies, you will see errors when hass
is running for the first time.
For example, I use a postgresql database as my recording backend and when I upgraded my version of HA I got this error because I had forgotten to reinstall psycopg2
:
2024-04-18 23:23:57.868 ERROR (Recorder) [homeassistant.components.recorder.core] Error during connection setup: No module named 'psycopg2' (retrying in 3 seconds)
Traceback (most recent call last):
File "/usr/home/homeassistant/HA-2024.4/lib/python3.12/site-packages/homeassistant/components/recorder/core.py", line 940, in _setup_recorder
self._setup_connection()
File "/usr/home/homeassistant/HA-2024.4/lib/python3.12/site-packages/homeassistant/components/recorder/core.py", line 1439, in _setup_connection
self.engine = create_engine(self.db_url, **kwargs, future=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 2, in create_engine
File "/usr/home/homeassistant/HA-2024.4/lib/python3.12/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
return fn(*args, **kwargs) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^
File "/usr/home/homeassistant/HA-2024.4/lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 599, in create_engine
dbapi = dbapi_meth(**dbapi_args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/home/homeassistant/HA-2024.4/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 690, in import_dbapi
import psycopg2
ModuleNotFoundError: No module named 'psycopg2'
Let service
manage HA
Link to heading
Make sure that you have stopped any running instances of hass
.
Then let service
start homeassistant
:
(as jail root) # service homeassistant start
Check your logs while you are testing the new version of HA to check for any missing dependencies:
# tail -f /var/log/homeassistant/homeassistant-daemon.log
Credits and thanks Link to heading
These instructions build upon the guides written by Dan Langille and Engr. Rez Cab.
Thanks goes to:
@justdude@mastodon.nl
for picking up a missing step in a previous version of this post@jan@jit.social
for noticing that I had not listedca_root_nss
as a dependency