Hi! Im still very new to this whole home automation thing. I’m thankful to have found something like Home Assistant to run the show! Hopefully this is in the right place and some can find this helpful. After getting HA running running in a virtualenv on my FreeNAS I wanted to put something together in case I needed to reinstall. Although many great guides are out there none that I came across had all this information in one place and relating to FreeNAS. This is more or less a collection and reorganization of information found in other guides and targeted at using a virtualenv to run HA in a jail on FreeNAS 11 as a non-root user (homeassistant), auto start on jail reboot and working zwave (Aeotec ZW090 Z-Stick GEN5) So here we go!
####Using the FreeNAS GUI, create new jail called Home_Assistant
####From the terminal inside your jail, update and install required packages.
- python35 py35-sqlite3 - Required to run Home Assistant
- bash - Needed to active virtualenv
- gmake - Needed to install Z-Wave
root@Home_Assistant:/ # pkg update
root@Home_Assistant:/ # pkg upgrade
root@Home_Assistant:/ # pkg install python35 py35-sqlite3 bash gmake
root@Home_Assistant:/ # python3.5 -m ensurepip
root@Home_Assistant:/ # pip3 install --upgrade virtualenv
###Create the homeassistant user
Run adduser and answer questions. Although not required, I recommend changing the default shell to bash for the homeassistant user since bash will be needed for activating the virtualenv created later on. Also I am adding the homeassistant user to the ‘dialer’ group. This is only required for using USB Z-Wave devices such as the Aeotec ZW090 Z-Stick.
Here’s how it all looks below. Questions I marked with an astrick (*) are answers I provided. Other questions I simply pressed ‘enter’ to accept default answer
root@Home_Assistant:/ # adduser
* Username: homeassistant
* Full name: Hass
Uid (Leave empty for default):
Login group [homeassistant]:
* Login group is homeassistant. Invite homeassistant into other groups? []: dialer
Login class [default]:
* Shell (sh csh tcsh git-shell bash rbash nologin) [sh]: bash
Home directory [/home/homeassistant]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
se an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
* Enter password:
* Enter password again:
Lock out the account after creation? [no]:
Username : homeassistant
Password : *****
Full Name : Hass
Uid : 1001
Class :
Groups : homeassistant dialer
Home : /home/homeassistant
Home Mode :
Shell : /usr/local/bin/bash
Locked : no
* OK? (yes/no): y
adduser: INFO: Successfully added (homeassistant) to the user database.
* Add another user? (yes/no): n
Goodbye!
Next create a directory for the virtualenv to live and change permissions so it belongs to the homeassistant user:group created in the previous step. Based on other guides Im going to use /srv/homeassistant
root@Home_Assistant:/ # mkdir -p /srv/homeassistant
root@Home_Assistant:/ # chown homeassistant:homeassistant /srv/homeassistant
Now we can become the homeassistant user, create the virtualenv and finally install homeassistant.
Notice how “(homeassistant)” appears at the beginning of command prompt after running the ‘source’ command. This indicates we are now operating in our virtualenv.
root@Home_Assistant:/ # su homeassistant
[homeassistant@Home_Assistant ~]$ virtualenv -p /usr/local/bin/python3.5 /srv/homeassistant
[homeassistant@Home_Assistant ~]$ source /srv/homeassistant/bin/activate
(homeassistant) [homeassistant@Home_Assistant ~]$ pip3 install --upgrade homeassistant
(homeassistant) [homeassistant@Home_Assistant ~]$ exit
You should now be able test home assistant using the following command. This will run in the terminal and you can stop by either using the Home Assistant web GUI or pressing ‘ctrl+c’. Closing the terminal will also stop homeassistant
root@Home_Assistant:/ # su - homeassistant -c '/srv/homeassistant/bin/hass'
- NOTE for the ‘source /srv/homeassistant/bin/activate’ command to work, your homeassistant user will need to be running the bash shell. If you are using a different shell you will need to switch (at least temporarily) to bash. Here’s a few hints:
pkg install bash - to install bash
exec bash - to run bash shell
You can also run homeassistant by adding ’ --deamon’. This will run homeassistant in the background allowing you to close your terminal. You would restart or stop homeassistant using either the web GUI. I will use this command to autostart homeassistant later on.
root@Home_Assistant:/ # su - homeassistant -c '/srv/homeassistant/bin/hass --daemon'
Aeotec ZW090 Z-Stick GEN5
Here we are simply becoming our homeassistant user, entering out virtualenv and install open zwave. I had to specify version 0.4.0.31 of openzwave or home assistant complained about the new version install by default
root@Home_Assistant:/ # su homeassistant
[homeassistant@Home_Assistant ~]$ source /srv/homeassistant/bin/activate
(homeassistant) [homeassistant@Home_Assistant ~]$ pip3 install python_openzwave==0.4.0.31
(homeassistant) [homeassistant@Home_Assistant ~]$ exit
I’ve included my configuration for the Aeotec ZW090 Z-Stick as an example. If you followed this guide the usb_path and config_path should be the same. If not you’ll need to change these to match your system. I’m sorry I cant offer more on this but I’m pretty much a noob myself
Become homeassistant user to edit configuration.yaml. We need to enable the zwave component
root@Home_Assistant:/ # su homeassistant
[homeassistant@Home_Assistant ~]$ edit /home/homeassistant/.homeassistant/configuration.yaml
and add this to the bottom of the file
# Example for Aeotec ZW090 Z-Stick in configuration.yaml
zwave:
usb_path: /dev/cuaU0
config_path: /srv/homeassistant/lib/python3.5/site-packages/python_openzwave/ozw_config
** NOTE for ‘pip3 install python_openzwave==0.4.0.31’ to complete successfully ‘gmake’ is required
# pkg install gmake
** NOTE the homeassistant user must be a member of the ‘dailer’ to use the zwave stick
# pw groupmod dialer -m homeassistant
Auto Start: UPDATED
root@Home_Asistant:/ # edit /usr/local/etc/rc.d/homeassistant
#!/bin/sh
#
# PROVIDE: homeassistant
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# FreeNAS 11 Jail -- Python VirtualEnv -- Home Assistant Daemon -- Non-Root User
#
# The following are available to configure this service:
# Change these options in /etc/rc.conf.local or /etc/rc.conf
#
# EXAMPLE: sysrc homeassistant_enable=yes
# EXAMPLE: sysrc homeassistant_data_dir=/home/homeassistant/.homeassistant
#
# 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.
# > This is optional, however do not specifically set this to an
# > empty string as this will cause the daemon to run with group wheel.
# Default: homeassistant
# homeassistant_data_dir: Directory where homeassistant configuration files will stored.
# Default: /usr/home/homeassistant/.homeassistant
. /etc/rc.subr
name=homeassistant
rcvar=${name}_enable
load_rc_config ${name}
: ${homeassistant_enable:="NO"}
: ${homeassistant_user:="homeassistant"}
: ${homeassistant_group:="homeassistant"}
: ${homeassistant_data_dir:="/usr/home/${homeassistant_user}/.homeassistant"}
pid_dir="/srv/homeassistant/var/run"
pidfile="${pid_dir}/homeassistant.pid"
command="/srv/homeassistant/bin/hass"
command_args="-c ${homeassistant_data_dir} --pid-file ${pidfile} --daemon"
start_precmd=homeassistant_precmd
homeassistant_precmd()
{
if [ ! -d "${pid_dir}" ]; then
install -d -g ${homeassistant_group} -o ${homeassistant_user} -- "${pid_dir}";
fi
if [ ! -d "${homeassistant_data_dir}" ]; then
install -d -g ${homeassistant_group} -o ${homeassistant_user} -m 775 -- "${homeassistant_data_dir}";
fi
}
stop_cmd=":"
stop_postcmd=homeassistant_postcmd
homeassistant_postcmd()
{
rm -f -- "${pidfile}"
}
run_rc_command "$1"
You’ll need to make this file executable
root@Home_Assistant:/ # chmod +x /usr/local/etc/rc.d/homeassistant
If homeassistant is not yet running you can start with the following command
root@Home_Assistant:/ # service homeassistant start
The End!