FreeNAS is a free and open-source network-attached storage (NAS) software based on FreeBSD and the OpenZFS file system. It is licensed under the terms of the BSD License and runs on commodity x86-64 hardware.
This has been tested on FreeNAS 11.3 and should also work on FreeBSD 11.x as well. These instructions assume you already have a running and accessible jail. For more information on creating a jail read the official FreeNAS User Guide regarding Jails. Once you have the jail available, follow the steps below. Directories used follow standard BSD conventions but can be adjusted as you wish.
This is considered an advanced installation method. This is for running just the Home Assistant Core application directly on Python, using a Virtualenv. It does not provide the full Supervisor experience and thus does not provide the Supervisor panel and add-ons. Please see the Home Assistant ADR for more details.
Installation
Enter the Home Assistant jail. If you donât know which name you have given the jail, you can use the iocage list
command to check.
# If the jail is called 'HomeAssistant'
iocage console HomeAssistant
Install the suggested packages:
pkg update && pkg upgrade
pkg install -y autoconf bash ca_root_nss ffmpeg gcc gmake libjpeg-turbo pkgconf python39 py39-sqlite3 rust
Create the user and group that Home Assistant will run as. The user/group ID of 8123
can be replaced if this is already in use in your environment.
pw groupadd -n homeassistant -g 8123
echo 'homeassistant:8123:8123::::::/usr/local/bin/bash:' | adduser -f -
Create the installation directory:
mkdir -p /usr/local/share/homeassistant
chown -R homeassistant:homeassistant /usr/local/share/homeassistant
Create the virtualenv and install Home Assistant itself:
su - homeassistant
cd /usr/local/share/homeassistant
python3.9 -m venv .
source ./bin/activate
pip install --upgrade wheel
pip install homeassistant
While still in the venv
, use the ensure_config
script to populate the configuration directory.
hass --script ensure_config
Next, using the check_config
script, we can make Home Assistant finish installing the initial dependencies.
hass --script check_config
Then deactivate venv
and logout of the Home Assistant user.
deactivate && exit
Auto-start and running Home Assistant as a service
Create the directory and the rc.d
script for the system-level service that enables Home Assistant to start when the jail starts.
mkdir -p /usr/local/etc/rc.d
Then create the file /usr/local/etc/rc.d/homeassistant
and insert the content below.
ee /usr/local/etc/rc.d/homeassistant
- To save and exit, press ESC then press ENTER twice
#!/bin/sh
#
# https://github.com/tprelog/iocage-homeassistant/blob/master/overlay/usr/local/etc/rc.d/homeassistant
#
# PROVIDE: homeassistant
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# homeassistant_enable: Set to YES to enable the homeassistant service.
# Default: NO
#
# homeassistant_user: The user account used to run the homeassistant daemon.
# This is optional, however do not specifically set this to an
# empty string as this will cause the daemon to run as root.
# Default: "homeassistant"
#
# homeassistant_group: The group account used to run the homeassistant daemon.
# Default: "homeassistant"
#
# homeassistant_config_dir: Directory where the homeassistant `configuration.yaml` is located.
# Default: "$HOME/.homeassistant"
# Change: `sysrc homeassistant_config_dir="/usr/local/etc/homeassistant"`
# Reset to default: `sysrc -x homeassistant_config_dir`
#
# homeassistant_venv: Directory where the homeassistant virtualenv is located.
# Default: "/usr/local/share/homeassistant"
# Change: `sysrc homeassistant_venv="/srv/homeassistant"`
# Reset to default: `sysrc -x homeassistant_venv`
# -------------------------------------------------------
# Copy this file to '/usr/local/etc/rc.d/homeassistant'
# `chmod +x /usr/local/etc/rc.d/homeassistant`
# `sysrc homeassistant_enable=yes`
# `service homeassistant start`
# -------------------------------------------------------
. /etc/rc.subr
name=homeassistant
rcvar=${name}_enable
pidfile_child="/var/run/${name}.pid"
pidfile="/var/run/${name}_daemon.pid"
logfile="/var/log/${name}.log"
load_rc_config ${name}
: ${homeassistant_enable:="NO"}
: ${homeassistant_user:="homeassistant"}
: ${homeassistant_group:="homeassistant"}
: ${homeassistant_config_dir:="/home/homeassistant/.homeassistant"}
: ${homeassistant_venv:="/usr/local/share/homeassistant"}
: "${homeassistant_restart_delay:=1}"
command="/usr/sbin/daemon"
start_precmd=${name}_prestart
homeassistant_prestart() {
install -g ${homeassistant_group} -m 664 -o ${homeassistant_user} -- /dev/null "${logfile}" \
&& install -g ${homeassistant_group} -m 664 -o ${homeassistant_user} -- /dev/null "${pidfile}" \
&& install -g ${homeassistant_group} -m 664 -o ${homeassistant_user} -- /dev/null "${pidfile_child}" \
|| return 1
if [ ! -d "${homeassistant_config_dir}" ]; then
install -d -g ${homeassistant_group} -m 775 -o ${homeassistant_user} -- "${homeassistant_config_dir}" \
|| return 1
fi
HA_CMD="${homeassistant_venv}/bin/hass"
HA_ARGS="--ignore-os-check --config ${homeassistant_config_dir}"
if [ -n "${homeassistant_log_file}" ]; then
install -g ${homeassistant_group} -m 664 -o ${homeassistant_user} -- /dev/null "${homeassistant_log_file}" \
&& HA_ARGS="${HA_ARGS} --log-file ${homeassistant_log_file}"
fi
if [ -n "${homeassistant_log_rotate_days}" ]; then
HA_ARGS="${HA_ARGS} --log-rotate-days ${homeassistant_log_rotate_days}"
fi
rc_flags="-f -o ${logfile} -P ${pidfile} -p ${pidfile_child} -R ${homeassistant_restart_delay} ${HA_CMD} ${HA_ARGS}"
}
start_postcmd=${name}_poststart
homeassistant_poststart() {
sleep 1
run_rc_command status
}
restart_precmd="${name}_prerestart"
homeassistant_prerestart() {
eval "${homeassistant_venv}/bin/hass" --config "${homeassistant_config_dir}" --script check_config
}
status_cmd=${name}_status
homeassistant_status() {
if [ -n "$rc_pid" ]; then
echo "${name} is running as pid $rc_pid."
echo "http://`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'`:8123"
else
echo "${name} is not running."
return 1
fi
}
stop_postcmd=${name}_postcmd
homeassistant_postcmd() {
rm -f -- "${pidfile}"
rm -f -- "${pidfile_child}"
}
run_rc_command "$1"
Make the rc.d
script executable:
chmod +x /usr/local/etc/rc.d/homeassistant
Configure the service to start on boot and finally start Home Assistant!:
sysrc homeassistant_enable="YES"
service homeassistant start
Upgrading Home Assistant
Before upgrading, read the change log to see what has changed and how it affects your Home Assistant instance. Enter the jail using iocage console <jailname>
then stop the Home Assistant service:
service homeassistant stop
Switch to your Home Assistant user and activate the venv
:
su - homeassistant
cd /usr/local/share/homeassistant
source ./bin/activate
Upgrade Home Assistant:
pip install --upgrade homeassistant
Then deactivate venv
and logout of the Home Assistant user. Finally start Home Assistant:
deactivate && exit
service homeassistant start
Upgrading Python
Home Assistant will support the latest two released minor Python versions. When the Python version is updated, you will need to install a supported version of Python and create a new virtualenv for Home Assistant, using the update version.
At this time Python 3.8 is being deprecated. Use these steps for upgrading to Python 3.9
From the jailâs console, install the updated Python requirements.
iocage console $JAIL_NAME
pkg install python39 py39-sqlite3
Stop the Home Assistant service, then remove the current venv. I suggest you also remove the cache directory, however this may be optional.
service homeassistant stop
rm -r /usr/local/share/homeassistant
rm -r /home/homeassistant/.cache
Create a new virtualenv and reinstall Home Assistant.
install -d -g homeassistant -m 775 -o homeassistant -- /usr/local/share/homeassistant
su - homeassistant
python3.9 -m venv /usr/local/share/homeassistant
source /usr/local/share/homeassistant/bin/activate
pip install --upgrade wheel
pip install homeassistant
Next, use the check_config
script, to make Home Assistant finish installing any additional Python dependencies. (This will speed-up the initial start-up)
hass --script check_config
Deactivate the virtualenv and logout from the homeassistant user
deactivate && exit
Finally, you can start the Home Assistant service again
service homeassistant start
Adding support for Z-Wave and Zigbee USB sticks
USB Z-Wave sticks may give
dmesg
warnings similar to âdata interface 1, has no CM over data, has no breakâ. This doesnât impact the function of the Z-Wave stick in Home Assistant. Just make sure the proper/dev/cu*
is used in the Home Assistantconfiguration.yaml
file.
Inside in the jail:
Ensure the following package has been installed
iocage console HomeAssistant
pkg install -y gmake
Then you can install the Z-Wave package
su - homeassistant
cd /usr/local/share/homeassistant
source ./bin/activate.csh
pip install homeassistant-pyozw
deactivate && exit
On the FreeNAS host:
These steps to enable pass through for Z-Wave / Zigbee USB devices were originally created for FreeNAS 9.x - If you are having trouble getting your Z-Wave or Zigbee USB stick to show up in your jail on FreeNAS 11 or TrueNAS Core, you can try this alternate approach.
Stop the Home Assistant Jail
iocage stop HomeAssistant
Edit the devfs rules
vi /etc/devfs.rules
Add the following lines
[devfsrules_jail_allow_usb=7]
add path 'cu\*' mode 0660 group 8123 unhide
Reload devfs
service devfs restart
Edit the ruleset used by the jail in the FreeNAS GUI by going to Jails â HomeAssistant
â Edit â Jail Properties â devfs_ruleset. â Set it to 7
Start, then connect to the Home Assistant jail
iocage start HomeAssistant
iocage console HomeAssistant
Inside in the jail:
Verify that you see the modem devices
ls -l /dev/cu*
You should see output similar to the following
crw-rw---- 1 uucp dialer 0x197 Jul 23 11:45 /dev/cuaU0
crw-rw---- 1 uucp dialer 0x198 Jul 23 11:45 /dev/cuaU0.init
crw-rw---- 1 uucp dialer 0x199 Jul 23 11:45 /dev/cuaU0.lock
Add the Z-Wave configuration to your configuration.yaml
and restart Home Assistant
The Z-Wave integration is now configurable via the Home Assistant UI
vi /home/homeassistant/.homeassistant/configuration.yaml
zwave:
usb_path: /dev/cuaU0
polling_interval: 10000
service homeassistant restart