So i’ve been charting my holiday journey getting started with Homeassistant, which started with a few youtube videos and reading the documentation for installation onto a Raspberry PI.
Unfortunately it seems that at the moment Pi systems are basically not available, and the recommended Pi4 goes for about £100 on eBay, which seems a lot of money for a Pi ! So looking around I found the excellent guide by Alexanderhale (Home Assistant Core on Android Tablet) which proved a very VERY good place to start! kudos to alexander for setting all that out. Unfortunately my journey wasn’t quite as simple as just following the guide, as I think various things have changed since it was written. Hence, I’m writing up my installation experience in case it helps anyone else.
Sorry for the hxxps links - as a new user it wont’ let me put many links in the post…
My starting point:
- Samsung Galaxy Note 20 Ultra (recently replaced with a Pixel 7 Pro, hence a decent powerful device for the installation) Android 13 (Phone stock OS)
- Google Nexus 9 tablet, Android 7.1.1 (Tablet stock OS). This is hopefully going to become a dashboard device, but is being used at the moment to trial these installation steps on a much older android version
I have successfully installed HA on both of these devices, so I believe that installation of a custom ROM like LineageOS as suggested by Alexanderhale may only be required on much older devices, i’m not sure. Of course, if that’s your kind of thing then knock yourselves out
- Installation of F-Droid software repository (steps detailed in Alexanderhale’s guide, I won’t repeat them here)
- Installation of Termux
- no ROOT access (decision born of practicality rather than any objection to rooting, I have a feeling that rooting may some some issues though!)
From a clean install of termux
pkg updates pkg upgrade
When running pkg updates, it will ask a number of times if you want to keep you existing config (option ‘n’) or update. I always opted to keep existing config, which is apparently the default option.
NOTE: At the time of writing (Dec’22), this installs Python 3-11. This is a PITA, because homeassistant (currently version 2022.12.9 on pipy) only states that it supports Python 3.10 (hxxps://github.com/home-assistant/core/issues/84117). Hey ho. Termux apparently doesn’t keep old versions of packages to save on hosting costs. Some workarounds to get old termux packages are listed here (hxxps://stackoverflow.com/questions/64853742/need-to-run-python-3-8-x-on-termux-on-android-currently-installed-with-python-3) but to be honest, I couldn’t be bothered with them, so I just got it working on Python 3.11. Boom!
pkg install python nano openssh termux-api make libjpeg-turbo pkg install dbus-python python-apsw python-apt python-bcrypt python-cryptography python-numpy python-pillow python-tkinter python-tldp python-xcbgen pkg install binutils rust wget pkg install c-ares
The first series of these are as recommended by alexanderhale’s wiki page.
The second lot is several termux-specific python packages (more on this later)
Third is binutils and rust, which are required to compile some homeassistant dependency packages now, and wget for grabbing some packages from t’internet.
Lastly c-ares is required by pycares which is required by homeassistant somewhere (but doesn’t seem to be a dependency, I only found out by running HA)
Next we get and unpack couple of packages that can’t be installed directly by pip.
wget https://files.pythonhosted.org/packages/01/50/e3015e6e03a3cf64113f509e8b86b71af37169b59ccedfcb182f3d031329/pycares-4.3.0.tar.gz wget https://files.pythonhosted.org/packages/ff/4f/62d9859b7d4e6dc32feda67815c5f5ab4421e6909e48cbc970b6a40d60b7/aiohttp-3.8.3.tar.gz tar -xvf pycares-4.3.0.tar.gz tar -xvf aiohttp-3.8.3.tar.gz
Next, we create a python virtual environment for homeassistant to run in. This isn’t strictly necessary, but I followed alexanderhale’s guide and it seems to work well at isolating the HA installation, even if it does bring a couple of headaches that need to be fixed. This step is optional really.
python -m venv hass source hass/bin/activate
We’re now in our nice new virtual environment.
The first thing that I do is to copy all of the python packages we downloaded earlier into this venv. If we didn’t create a venv this would not be necessary, so this is not necessary if you didn’t opt to create a venv.
This appears to be necessary because there a some oddities in termux which are fixed by using the termux-specific python packages. The package that lead me to this is numpy (incidentally another package that’s not a ‘dependency’ but you get immediate errors if you try to execute without it), because for the life of me I could not get a compatible version installed and compiled using pip. However copying the termux-specific package worked brilliantly.
cp -r ../usr/lib/python3.11/site-packages/* ./hass/lib/python3.11/site-packages/
Now comes the fun bit.
This package was a complete pain, and one that I never solved satisfactorily, due to a tangled web of dependencies and installation errors. homeassistant requires aiohttp==3.8.1, which simply just WOULD NOT compile on my termux-python3.11 system.
However, I noticed in the aiohttp documentation that aiohttp is built to be backwards-compatible, which gave me a cunning idea…
The below commands extract the aiohttp 3.8.3 files (downloaded from pipy earlier) and rename the package version to be 3.8.1 instead, and then compile and install the hacked package. Following this, it’s recognised by the system as version 3.8.1, the HA installation proceeds nicely, and everything seems to work nicely.
Side note - i’m aware this is horrible and is good justification by itself for performing the installation in a venv.
cd aiohttp-3.8.3 sed -i s/3.8.3/3.8.1/g PKG-INFO sed -i s/3.8.3/3.8.1/g aiohttp/__init__.py sed -i s/3.8.3/3.8.1/g aiohttp.egg-info/PKG-INFO python setup.py install cd ..
Pycares installation isn’t quite as much of a hack as aiohttp, but it requires some mods to source code to be compatible with this setup.
pycares will be installed by homeassistant during installation, but I found that if you don’t do this modification then when you boot homeassistant you get constant errors. Better to fix the problem at source (literally). The solution was given here (hxxps://github.com/saghul/pycares/issues/78#issuecomment-445508989), noting that the source file is now in a slightly different place, that answer must be old.
cd pycares-4.3.0 sed -i 's/#define HAVE_GETSERVBYPORT_R 1/\/\/#define HAVE_GETSERVBYPORT_R 1/g' deps/build-config/config_android/ares_config.h python setup.py install cd ..
Next, set some compilation flags required to compile homeassistant dependencies successfully. (Otherwise orjson and cryptography refuse to build)
export RUSTFLAGS=" -C lto=no" export CARGO_BUILD_TARGET="$(rustc -vV | sed -n 's|host: ||p')"
Getting there. Install wheel and tzdata (once again, tzdata is not a dependency, but you cannot complete setup if you don’t have it installed. Solution was found here(hxxps://community.home-assistant.io/t/time-zone-error-while-installing-need-help/318807/5))
PyTurboJPEG weird installation is to cope with differences between android and linux, there seems to be some differences in how to test for the presence of the mathlib.
pip install wheel pip install tzdata MATHLIB=“m” pip install PyTurboJPEG==1.6.7
And you’re ready to rock.
Pip install homeassistant
Note: last time I did this I got a file permission error due to the OS halfway through installation… i just started the installation again and it worked nicely.
This setup seems to be working just about perfectly for me - hope the guide helps anyone else who’s thinking of trying this.