Miscellaneous

Installing Home Assistant on a Raspberry Pi 3

December 26, 2019

There are a lot of guides out there on setting up a fresh image of Hasbian and having your installation of Home Assistant up in a few minutes but there wasn’t much that I could find on installing it on an existing Raspberry Pi 3 image which was already being used for other purposes.

Whether you just have one raspberry pi, or you’re like me and have several and each of them already have several jobs, it’s definitely possible to get Home Assistant on there without going the nuclear option and starting with a fresh image.

In my case I had retired my Raspberry Pi 3 which had served as an OctoPrint server for some time. It also runs one of my PiHole servers so I wanted to keep both of those going if I could.

I started off by following the Raspberry Pi Installation Guide on Home Assistant, which made it sound pretty easy. However once I got to the step where you run pip3 install homeasisstant I got an error telling me that I needed to upgrade Python to 3.6.1 in order to install HA as I only had 3.5.3. I quickly discovered that there was not a newer version in the apt repository and had to build it from source. I will save you all some time here, you actually want to go with an even newer version than that as soon as you install HA and run it for the first time with 3.6.1 it will give you this lovely popup:

Very funny HA. You could have just told me I needed 3.7.

I should mention before I move on that HA did run at this point but I was only able to setup my Chromecast device. Beyond that I was getting errors with the default configuration and the cloud and mobile_app. But I figured I should get all those errors resolved before starting to configure everything.

So back to bulding from source I went. This time I used 3.7.5 and wen through the same steps. (Note: If you’re following along, don’t actually do this step, skip ahead). For this I had to download the Python source and build it (you’ll do this as the Pi user in the home directory).

cd ~
sudo wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar xvzf Python-3.7.5.tgz
cd Python-3.7.5 
./configure
make -j4
make install

Aftwards I fired up Home Assistant only to get the same warning. Hmmm. After some digging I discovered that yup, it was still running on 3.6 and the easiest way to fix that was to kill my virtual environment and recreate it.

Uninstalling the old one is as simple as deleting it. However if you’re running inside of that virtual environment you’ll first want to type exit to get back to your pi user and standard prompt.

sudo rm -rf /srv/homeassisstant

Now we can recreate it, this time using 3.7.5.

sudo mkdir homeassistant
sudo chown homeassistant:homeassistant homeassistant
sudo -u homeassistant -H -s
cd /srv/homeassistant
python3.7 -m venv .
source bin/activate

Now you’ve recreated your virtual enviornment, and it will run inside of Python 3.7 specifically. But alas, you will just ge tmore errors when you install home assistant and start it up. This time it will complain about missing sqlite3 prerequisites.

It turns out you need to compile python with support for sqlite3. D’oh! So again, I had to delete my virtual enviornment, rebuild python and then recreate the virtual environment using 3.7.

So if you’re skipping the compiling without sqlite blunder that I made, the corret steps will be:

cd ~ 
sudo apt-get install libsqlite3-dev 
sudo wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz tar xvzf Python-3.7.5.tgz 
cd Python-3.7.5  
./configure --enable-loadable-sqlite-extensions  
make -j4 
make install

The make -j4 command will take quite some time to complete despite the extra parameter telling it to use all 4 cores on the raspberry pi. This it due to some extra tests that will run with the extra extensions enabled.

Once it is done you will again have to recreate your virtual environment:

sudo rm -rf /srv/homeassisstant
sudo mkdir homeassistant
sudo chown homeassistant:homeassistant homeassistant
sudo -u homeassistant -H -s
cd /srv/homeassistant
python3.7 -m venv .
source bin/activate 

And from there you’ll continue off with the last two steps in the installation guide:

python3 -m pip install wheel homeassistant
hass

This will build and install Home Assistant using Python 3.7.

Next up you’ll probably run into some errors about GLIBC not meeting the required version. If you have any Z-Wave sensors on your network and auto discover turned on this will result in segmentation faults and the application crashing out. You will need to install v2.28 to fix this problem.

Run the following commands as the pi user:

ldd --version
sudo apt-cache policy libc6
sudo apt-get install libc6
ldd --version

After running ldd –version for the second time you should see the following:

ldd (Debian GLIBC 2.29-3) 2.29
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

At this point you can restart hass again and you will no longer encounter segmentation faults.

Sources: https://community.home-assistant.io/t/error-after-installing/21651/6,
https://community.home-assistant.io/t/zwave-errors-after-python-upgrade/120948/3, https://askubuntu.com/questions/736208/upgrading-glibc

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.