Running Home Assistant on FreeBSD Servers
Home Assistant is an open-source home automation system powered by Python, primarily intended to run on single-board computers like the Raspberry Pi, with Linux as the host operating system.
The following procedure shows how to run Home Assistant Core on FreeBSD servers, on either physical or virtual machines.
1. PREPARING THE SERVER
1.1. Update the package list and upgrade the existing packages.
root@host: # pkg update && pkg upgrade -y
1.2. Install Python and other required packages.
root@host: # pkg install python38 py38-sqlite3 openssl autoconf libffi rust
1.3. Create a system account with disabled login (-w no), a dedicated home directory (-m), and some informational text (-c comment).
root@host: # pw useradd homeassistant -w no -m -c "Home Assistant"
1.3.1. If groups for hardware input/output are present, append the system account. Else, skip this step for now.
root@host: # pw groupmod gpio -m homeassistant
root@host: # pw groupmod i2c -m homeassistant
18.104.22.168. The "dialer" group in FreeBSD is the equivalent of the "dialout" group in Linux.
root@host: # pw groupmod dialer -m homeassistant
1.4. Ensure that only the system account and members of its group can access the dedicated home directory.
root@host: # chmod 770 /home/homeassistant
1.5. Create an installation directory for Home Assistant Core.
root@host: # mkdir -p /srv/homeassistant
1.6. Change owner of the installation directory to the system account.
root@host: # chown homeassistant:homeassistant /srv/homeassistant
2. SETTING UP HOME ASSISTANT
2.1. Log in as the system account.
root@host: # su - homeassistant
2.2. Create a virtual environment for Home Assistant Core.
user@host: $ python3.8 -m venv /srv/homeassistant
2.3. Make the "activate" command executable by the system account.
user@host: $ chmod 700 /srv/homeassistant/bin/activate
2.4. Activate the virtual environment.
user@host: $ /srv/homeassistant/bin/activate
2.5. Install the "wheel" Python package.
user@host: $ /srv/homeassistant/bin/pip3.8 install wheel
2.6. Install Home Assistant Core.
user@host: $ /srv/homeassistant/bin/pip3.8 install homeassistant
2.7. Run the Home Assistant server. It may take around twenty (20) minutes to initially configure itself. Many required libraries and dependencies will be downloaded and installed on its first run.
user@host: $ /srv/homeassistant/bin/hass
2.8. Access the Home Assistant server through a web browser.
3. AUTO-RUN HOME ASSISTANT ON BOOT
3.1. Log in as the system account.
root@host: # su - homeassistant
3.2. Follow the FreeBSD crontab steps on this blog post but replace the @reboot line with the following.
@reboot /srv/homeassistant/bin/hass > /dev/null &
There is an issue concerning SSLv3 on which the following errors manifest.
* ERROR (MainThread) [homeassistant.setup] Setup failed for cloud: ... site-packages/cryptography/hazmat/bindings/_openssl.abi3.so: Undefined symbol "SSLv3_client_method"
* ERROR (MainThread) [homeassistant.setup] Setup failed for mobile_app: ... site-packages/cryptography/hazmat/bindings/_openssl.abi3.so: Undefined symbol "SSLv3_client_method"
The reason for this is that some SSLv3 components are disabled in FreeBSD by default due to major security flaws, as explained here. Fixing these errors may require action from either the Python package maintainers or the Home Assistant developers to remove dependencies from deprecated vulnerable packages.
Other than that, the other parts of Home Assistant Core work well with the FreeBSD operating system. HTTPS can be enabled in Home Assistant to encrypt data transfers for better security.