Aug 272022

Home Assistant is not friendly for plain installs. It seems designed for containers or running everything out of pip install. That, in itself, is a disturbing trend I’ve seen on several projects (what? you’re not running a git cloned image?).

I’ve seen reports of people running containers etc. However, I want to run this on FreeBSD. I don’t want to muck about with installing containers etc. If containers are the only way for a project to run, you’re doing it wrong.

I tried recently and eventually succeeded after several failures. Open source should not be this difficult. The devs seem unware of the problems. A previous attempt in June involved an Ansible playbook. After terrible install this past Tuesday night, I’m going to amend that playbook.

In this post:

  1. FreeBSD 13.1
  2. creation of the jail is out of scope
  3. I see no reason why this would not work on a bare host instead of a jail
  4. homeassistant-2022.8.7
  5. I’m using the gist provided by Daniel O’Connor
  6. The guide, helped but was for Python 3.8 and it seems big changes have occurred since Python 3.9 came out.
  7. homeassistant will be installed to /srv/homeassistant
  8. I found using pip installed from a package did not give the same results as using /srv/homeassistant/bin/pip. This may be my lack of knowledge of pip.

In the next section, I try to explain why certain packages are installed. I hope that helps.

Packages installed first

I suspect the packages/hosts which the devs use come with SQLite already installed. That’s why it fails without first installing. That might also be why the first guide I used installed wheel manually.

  1. rust is a known dependency.
  2. This is why I manually install pillow
  3. I install wheel because I saw lots of Using legacy ‘ install’ for sqlalchemy, since package ‘wheel’ is not installed. – Installing wheel as a package did not silence this message.
  4. This is why I installed sqlalchemy. Installing a package onto the host did not help. It needed to be pip.
  5. I installed sqlalchemy because hass failed to start with no visual reason why. The guide mentions that dependency.
  6. sqlite3 gets installed because it errors out otherwise.
  7. I could not find a pip which would satisfy this requirement.

These are the packages I installed first. Others mentioned above get installed later, via pip.

root@homeassistant:/ # pkg install rust py39-pillow py39-sqlite3

User creation

I create a homeassistant user:

root@homeassistant:/ # pw useradd homeassistant -w no -m -c "Home Assistant"
root@homeassistant:/ # pw groupmod dialer -m homeassistant
root@homeassistant:/ # chmod 770 /home/homeassistant

The chmod is to keep others out of sensitive information.

The installation directory

root@homeassistant:/ # mkdir -p /srv/homeassistant
root@homeassistant:/ # chown homeassistant:homeassistant /srv/homeassistant

The remaining is done as the homeassistant user

The above commands were run as root.

The below commands are run as the homeassistant user.

Ideally, I’d like the code to be non-modifiable by the user running it, mostly for security reasons. Recent software trends seem to ignore security aspects such as this and assumes the user can modify the code.

Create the virtual environment

Do this as the homeassistant user:

root@homeassistant:/ # su -l homeassistant
homeassistant@homeassistant:~ $ 

Create a Python virtual environment:

homeassistant@homeassistant:~ $ python -m venv /srv/homeassistant
homeassistant@homeassistant:~ $ ls -l /srv/homeassistant
total 19
drwxr-xr-x  2 homeassistant  homeassistant  12 Aug 26 13:27 bin
drwxr-xr-x  2 homeassistant  homeassistant   2 Aug 26 13:27 include
drwxr-xr-x  3 homeassistant  homeassistant   3 Aug 26 13:27 lib
lrwxr-xr-x  1 homeassistant  homeassistant   3 Aug 26 13:27 lib64 -> lib
-rw-r--r--  1 homeassistant  homeassistant  76 Aug 26 13:27 pyvenv.cfg
homeassistant@homeassistant:~ $ 

Activate our virtual environment:

homeassistant@homeassistant:~ $ chmod 700 /srv/homeassistant/bin/activate
homeassistant@homeassistant:~ $ /srv/homeassistant/bin/activate

Installing some dependencies

Install the software which doesn’t work as packages. This completed in about 15 seconds.

homeassistant@homeassistant:~ $ /srv/homeassistant/bin/pip install wheel sqlalchemy fnvhash
Collecting wheel
  Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Collecting sqlalchemy
  Downloading SQLAlchemy-1.4.40.tar.gz (8.3 MB)
     ---------------------------------------- 8.3/8.3 MB 19.2 MB/s eta 0:00:00
  Preparing metadata ( ... done
Collecting fnvhash
  Downloading fnvhash-0.1.0.tar.gz (1.9 kB)
  Preparing metadata ( ... done
Collecting greenlet!=0.4.17
  Downloading greenlet-1.1.3.tar.gz (91 kB)
     ---------------------------------------- 91.6/91.6 KB 2.3 MB/s eta 0:00:00
  Preparing metadata ( ... done
Using legacy ' install' for sqlalchemy, since package 'wheel' is not installed.
Using legacy ' install' for fnvhash, since package 'wheel' is not installed.
Using legacy ' install' for greenlet, since package 'wheel' is not installed.
Installing collected packages: fnvhash, wheel, greenlet, sqlalchemy
  Running install for fnvhash ... done
  Running install for greenlet ... done
  Running install for sqlalchemy ... done
Successfully installed fnvhash-0.1.0 greenlet-1.1.3 sqlalchemy-1.4.40 wheel-0.37.1
WARNING: You are using pip version 22.0.4; however, version 22.2.2 is available.
You should consider upgrading via the '/srv/homeassistant/bin/python -m pip install --upgrade pip' command.

Upgrade pip because we got told

Let’s just upgrade this, because it said to. This command completed in about 6 seconds.

homeassistant@homeassistant:~ $ /srv/homeassistant/bin/python -m pip install --upgrade pip
Requirement already satisfied: pip in /srv/homeassistant/lib/python3.9/site-packages (22.0.4)
Collecting pip
  Downloading pip-22.2.2-py3-none-any.whl (2.0 MB)
     ---------------------------------------- 2.0/2.0 MB 11.3 MB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 22.0.4
    Uninstalling pip-22.0.4:
      Successfully uninstalled pip-22.0.4
Successfully installed pip-22.2.2

The main event

Install homeassistant. This takes about 9 minutes. The full output of this command is in this gist.

homeassistant@homeassistant:~ $ /srv/homeassistant/bin/pip install homeassistant
Collecting homeassistant
  Downloading homeassistant-2022.8.7-py3-none-any.whl (18.5 MB)
     ---------------------------------------- 18.5/18.5 MB 16.6 MB/s eta 0:00:00
Collecting python-slugify==4.0.1
  Downloading python-slugify-4.0.1.tar.gz (11 kB)
  Preparing metadata ( ... done
  Building wheel for multidict (pyproject.toml) ... done
  Created wheel for multidict: filename=multidict-6.0.2-cp39-cp39-freebsd_13_1_release_p1_amd64.whl size=32246 sha256=8fd6edc246e35bd9cc5e3c42e4060e896f45b0d402bfacae6cfe1cafeb5dcb9e
  Stored in directory: /usr/home/homeassistant/.cache/pip/wheels/09/2e/af/35665f2dc3fdfa03603e3164d8d900effca39bd1ca5598f8d2
Successfully built aiohttp bcrypt ciso8601 cryptography lru-dict orjson python-slugify pyyaml yarl frozenlist MarkupSafe multidict
Installing collected packages: voluptuous, text-unidecode, rfc3986, pytz, lru-dict, ifaddr, ciso8601, voluptuous-serialize, urllib3, typing-extensions, sniffio, six, pyyaml, python-slugify, PyJWT, pycparser, orjson, multidict, MarkupSafe, idna, h11, frozenlist, charset-normalizer, certifi, awesomeversion, attrs, atomicwrites-homeassistant, async-timeout, astral, yarl, requests, jinja2, cffi, bleak, anyio, aiosignal, httpcore, home-assistant-bluetooth, cryptography, bcrypt, aiohttp, httpx, homeassistant
Successfully installed MarkupSafe-2.1.1 PyJWT-2.4.0 aiohttp-3.8.1 aiosignal-1.2.0 anyio-3.6.1 astral-2.2 async-timeout-4.0.2 atomicwrites-homeassistant-1.4.1 attrs-21.2.0 awesomeversion-22.6.0 bcrypt-3.1.7 bleak-0.15.1 certifi-2022.6.15 cffi-1.15.1 charset-normalizer-2.1.1 ciso8601-2.2.0 cryptography-36.0.2 frozenlist-1.3.1 h11-0.12.0 home-assistant-bluetooth-1.3.0 homeassistant-2022.8.7 httpcore-0.15.0 httpx-0.23.0 idna-3.3 ifaddr-0.1.7 jinja2-3.1.2 lru-dict-1.1.8 multidict-6.0.2 orjson-3.7.8 pycparser-2.21 python-slugify-4.0.1 pytz-2022.2.1 pyyaml-6.0 requests-2.28.1 rfc3986-1.5.0 six-1.16.0 sniffio-1.2.0 text-unidecode-1.3 typing-extensions-4.3.0 urllib3-1.26.12 voluptuous-0.13.1 voluptuous-serialize-2.5.0 yarl-1.7.2

Start homeassistant

This command will install/build/compile additional dependencies. Some compiling will occur. This might take 10-15 minutes. The full output of this command is in this gist.

If successful, this should not come back to the command line and you will have homeassistant up and running.

BUT, I have noticed that homeassistant starts running on the web UI before this command completes. See the next section for details.

homeassistant@homeassistant:~ $ /srv/homeassistant/bin/hass --ignore-os-check -v -v -v -v
Unable to find configuration. Creating default one in /home/homeassistant/.homeassistant
2022-08-27 16:02:43.322 INFO (MainThread) [homeassistant.bootstrap] Config directory: /home/homeassistant/.homeassistant
2022-08-27 16:02:43.333 INFO (SyncWorker_0) [homeassistant.loader] Loaded homeassistant from homeassistant.components.homeassistant
2022-08-27 16:02:43.334 INFO (SyncWorker_1) [homeassistant.loader] Loaded persistent_notification from homeassistant.components.persistent_notification
2022-08-27 16:11:42.552 INFO (MainThread) [homeassistant.core] Starting Home Assistant
2022-08-27 16:11:42.578 INFO (MainThread) [homeassistant.components.zeroconf] Starting Zeroconf broadcast
WARNING: No IPv4 address found on lo0 !
2022-08-27 16:11:42.869 WARNING (SyncWorker_2) [scapy.runtime] No IPv4 address found on lo0 !
WARNING: No IPv4 address found on lo0 !
2022-08-27 16:11:42.910 WARNING (SyncWorker_2) [scapy.runtime] No IPv4 address found on lo0 !
WARNING: more No IPv4 address found on ix0 !
2022-08-27 16:11:43.074 WARNING (SyncWorker_2) [scapy.runtime] more No IPv4 address found on ix0 !
  • –ignore-os-check is required because FreeBSD is not considered a valid operating system for homeassistant.
  • The -v helps with debug output and finding out what problem stops the code from succeeding.

If it drops back back to the command line without starting the application, run the command again, perhaps adding another -v to the line. That might tell you what module is missing.

Is is running?

In another terminal session, this is what I saw running:

root@homeassistant:/ # sockstat -4
root@homeassistant:/ # sockstat -4
homeassistant python3.971240 3 tcp4
homeassistant python3.971240 4 tcp4
homeassistant python3.968255 10 tcp4      *:*
homeassistant python3.968255 12 udp4      *:*
root     sendmail   28815 4  tcp4         *:*
root     syslogd    28775 5  udp4        *:*
root@homeassistant:/ # 

This shows homeassistant is up and running. Look for port 8123 is what you want to put into your browser. In my case, that’s

Those other two lines, going out to port 443 is homeassistant reaching out to download source etc for installing.

NOTE: this is not an https connection, there is no TLS here. Everything you type in that browser connection is transmitted in clear text to the server.

This is the page which HomeAssistant first shows you.

This is the page which HomeAssistant first shows you.

What’s next?

I want to get TLS up and running. I’ll do that as a new post. Getting homeassistant up and running is complex enough.

Also required: an rc.d script.

Website Pin Facebook Twitter Myspace Friendfeed Technorati Digg Google StumbleUpon Premium Responsive