Home Assistant Core on Android Tablet

You need install rust and cargo first:

  • pip install rust
  • pip install cargo

run: rustc -vV | sed -n 's|host: ||p' it returns target system, something like: armv7-linux-androideabi copy it and set to cargo running: export CARGO_BUILD_TARGET=armv7-linux-androideabi

then run:

  • pip install cryptography==3.4.8 --no-binary cryptography
  • pip install homeassistant==2021.11.5

from homeassistant==2021.12.X versions, needs cryptography==35.0.0 but install with this method fail. However installation succes for cryptography==36.0.0 which is incompatible with homeassistant==2021.12.X

if you want to upgrade from homeassistant==2021.11.5 you can overide cryptography==35.0.0 with cryptography==36.0.0 following method described above and modifiying cryptography line on package_constraints.txt copiying from source code and creating a local file placed on /data/data/com.termux/files/home/homeassistant/package_constraints.txt and running:

pip install --upgrade -c package_constraints.txt homeassistant

after first home assistant run, maybe you need install manually some packages

Of course while homeassistant need cryptography==35.0.0 you will need do this with every upgrade

2 Likes

Thanks for this excellent guide. Well done, it must have taken quite an effort.

I think using an old phone is an obvious route to go; as there are lots usually lying around unused. Throwing them out seems a big waste.

I had home assistant running on an old nexus a couple of years ago using a similar setup with Termux.

BUT, ā€¦ as the phone was permanently on charge, the battery eventually failed and ruined the phone.

Iā€™ll follow your guide for a future installation but next time put the charger behind a plug which only charges when the battery needs it.

dear Alex,

I followed your guideline. However I got a lot of error messages during the execution of the sequence of commands.
Finally given the hass -v command, but no results.
I bought a Samsung a7 lite. Are the commands shown also valid for the Tablet a7?

I hope you can help me any further.
Thx in advance.

Had some issues. This is how I installed it on Termux:

# If you get errors run: "termux-change-repo" and change the sources mirrors to ex. termux.me
pkg update

# Upgrade current packages
pkg upgrade -y

# Install required packages
pkg install nano openssh termux-api make libjpeg-turbo wget rust python -y

# Export build target for Rust
export CARGO_BUILD_TARGET="$(rustc -Vv | grep "host" | awk '{print $2}')"

# There's a bug where python 3.10 is being detected as lower than 3.6 (minimumn build version)
# Will cause error: cargo failed with code: 101
# Remove python 3.10 (But keep dependencies)
pkg remove python -y

# We have to install python 3.9.7, but we need to know the system architecture first
# Get your current architecture, based on that choose the next step
echo $CARGO_BUILD_TARGET

# Choose only one, based on the architecture you got (arm or aarch64)
# For arm
wget https://raw.githubusercontent.com/Termux-pod/termux-pod/main/arm/python/python-3.9.7/python_3.9.7_arm.deb
dpkg -i python_3.9.7_arm.deb

# For aarch64 
wget https://raw.githubusercontent.com/Termux-pod/termux-pod/main/aarch64/python/python-3.9.7/python_3.9.7_aarch64.deb
dpkg -i python_3.9.7_aarch64.deb

# Upgrade pip
pip install --upgrade pip

# Install homeassistant
pip install wheel homeassistant

Still, lots of errors when starting hass which Iā€™m trying to solve.

1 Like

Canā€™t build numpy wheel for python 3.9.7 but success for python 3.10.2 likewise cant build cryptography==35.0.0 wheel for python 3.10.2 but succes for python 3.9.7

itā€™s desperateā€¦

2 Likes

Looks like there was a new version of numpy the day after you posted this, have you tried it? https://github.com/numpy/numpy/releases/tag/v1.22.2

Not sure if itā€™s because of this, but I managed to build numpy 1.22.2 with python 3.9.7. Could be because of the aarch64 architecture, though.
This coupled with the previous help about cargo to build cryptography 35.0.0, I managed to get HA 2022.2 running on my Lenovo m10!

image

One thing though, for me it refused to start because of a missing component library: "libzstd.so.1" not found. This caused ā€œimageā€ to not load, then person, then frontend, so basically nothing could launch.
I fixed this with installing it manually: pip install zstd.
I still have to solve PyNaCl not building, so for now I donā€™t have mobile_app working. But at least the rest is fine.

Hope this helps.

I also canā€™t install numpy==1.22.2 with Python 3.9.7

For PyNaCl this worked for me:

(hass) ~ $ SODIUM_INSTALL=system pip install pynacl==1.4.0
Collecting pynacl==1.4.0
  Using cached PyNaCl-1.4.0.tar.gz (3.4 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: six in ./hass/lib/python3.9/site-packages (from pynacl==1.4.0) (1.16.
Requirement already satisfied: cffi>=1.4.1 in ./hass/lib/python3.9/site-packages (from pynacl==1.4.0(1.15.0)
Requirement already satisfied: pycparser in ./hass/lib/python3.9/site-packages (from cffi>=1.4.1->pycl==1.4.0) (2.21)
Building wheels for collected packages: pynacl
  Building wheel for pynacl (PEP 517) ... done
  Created wheel for pynacl: filename=PyNaCl-1.4.0-cp39-cp39-linux_armv7l.whl size=191568 sha256=292bf96e7a90809d6aac71e41f678d8774980e134e34b16b7faf4f024d8947
  Stored in directory: /data/data/com.termux/files/home/.cache/pip/wheels/3b/bb/4f/1cac0cbc50558d501046fb2942596ca9004b1055553856b8
Successfully built pynacl
Installing collected packages: pynacl
Successfully installed pynacl-1.4.0

Edit:

Finally i could install numpy on python 3.9.7 without building it. I Just downloading a wheel from piwheels.org for correct python version and system arch, and installing it locally using pip.

Captura de pantalla 2022-02-06 160058

In spite of that wheel is for Bullseye and not for android, for the time being, hass starting and works fine except for some reason i cant run hass as daemon hass --daemon it show error: unrecognized arguments: --daemon . Then when i restart hass from hass ui the system not restart

About the --daemon, itā€™s because they decided it was not needed anymore as they cleaned up their main: https://github.com/home-assistant/core/pull/64345

Iā€™m currently trying out daemonize, installed via pkg install daemonize. Seems to work so far.

PyNaCl is not installing for me, something about missing sodium.h. Iā€™ll have to check it further later.
Edit: Ok, a pkg install libsodium helped with that one.

How did you do to get running home assistant as a daemon process?

I have already installed daemonize using pkg install daemonize but i donā€™t know how configure itā€¦

I didnā€™t configure anything really, I just launched the app with it (you need a full path):
daemonize /data/data/com.termux/files/home/hass/bin/hass

It seems to work so far, I havenā€™t really wondered more to be honest and I havenā€™t checked how it launched with the venv, I just did the usual source hass/bin/activate before. Though I assume that if something was not on the venv it would have taken much longer to launch.

I am no able to instal numpy 1.22.2 with python 3.9.7 aarch64 in termux

[Errno 2] No such file or directory: 'aarch64-linux-android-ar'


  error: Command "aarch64-linux-android-ar rcs build/temp.linux-aarch64-3.9/libnpymath.a build/temp.linux-aarch64-3.9/numpy/core/src/npymath/npy_math.o build/temp.linux-aarch64-3.9/build/src.linux-aarch64-3.9/numpy/core/src/npymath/ieee754.o build/temp.linux-aarch64-3.9/build/src.linux-aarch64-3.9/numpy/core/src/npymath/npy_math_complex.o build/temp.linux-aarch64-3.9/numpy/core/src/npymath/halffloat.o" failed with exit status 127
  INFO:
  ########### CLIB COMPILER OPTIMIZATION ###########
  INFO: Platform      :
    Architecture: aarch64
    Compiler    : clang

  CPU baseline  :
    Requested   : 'min'
    Enabled     : NEON NEON_FP16 NEON_VFPV4 ASIMD
    Flags       : none
    Extra checks: none

  CPU dispatch  :
    Requested   : 'max -xop -fma4'
    Enabled     : ASIMDHP ASIMDDP
    Generated   : none
  INFO: CCompilerOpt.cache_flush[817] : write cache to path -> /data/data/com.termux/files/usr/tmp/pip-install-aazs6vru/numpy_0ced138abad94b64af4403d88e3490be/build/temp.linux-aarch64-3.9/ccompiler_opt_cache_clib.py
  ----------------------------------------
  ERROR: Failed building wheel for numpy



Not sure if clang has the issue

WARN: CCompilerOpt.generate_dispatch_header[2289] : dispatch header dir build/src.linux-aarch64-3.9/numpy/distutils/include does not exist, creating it
  INFO: building 'npymath' library
  INFO: compiling C sources
  INFO: C compiler: aarch64-linux-android-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fstack-protector-strong -O3 -fstack-protector-strong -O3 -fPIC -ftrapping-math

Does anyone know the issue ? I am not able to get Hass last version up and running.

Does not work for me.

I can launch home assistant running :

1. source hass/bin/activate
2. daemonize /data/data/com.termux/files/home/hass/bin/hass

but same issue as

1. source hass/bin/activate
2. hass 

On both the process does not run as daemon. When i reboot home assistant from UI, home assistant stops but not restart

Seems that daemonize needs more arguments to work properly

Hi, has anyone been able to install the latest version with termux? what packages have you used (nexus 7) or what version of HASS and packages are correct? i am using LineageOs 18 (Android 11).

try
pkg install binutils
then install numpy again

1 Like

Instead of daemonize use utilites from termux-services.
Install termux-services package:

pkg install termux-services

Edit ~/.termux/boot/start
There is my version:

#!/data/data/com.termux/files/usr/bin/sh

termux-wake-lock

runsvdir $PREFIX/var/service

Create service folder:

mkdir $PREFIX/var/service/hass

Create run file and make it executable:

touch $PREFIX/var/service/hass/run
chmod 700 $PREFIX/var/service/hass/run

Edit newly created run file:

#!/data/data/com.termux/files/usr/bin/sh

source ~/hass/bin/activate
exec /data/data/com.termux/files/home/hass/bin/hass 2>&1

That way you can all your startup scripts convert to services.
For example:

~ $ ls $PREFIX/var/service/
hass  mosquitto  sshd   z2m

If you need, for some reason, stop one of services use:

sv down SERVICE

Disable/enable autorun service:

sv-disable SERVICE
sv-enable SERVICE
2 Likes

Tried what you mentioned but Iā€™m getting ā€œā€¦the SSL module is not availableā€. Looks like the downgrade to python 3.9 messed up with SSL

I tried installing this for the first time and got this error

Encountered an error while trying to install package
-cffi

I tried installing cffi seperately,with no luck.
I have no experience in python,and would appreciate any help.

For the record, Iā€™ve just updated to 2022.4.1 without issues on upgrade. That said, I got issues with PyNaCl when starting, not finding ld in the path for some reason:
checking for ld used by aarch64-linux-android-clang... no

Actually, after looking into it more, looks like itā€™s a known issue for clang: [Bug]: clang: ld: command not found Ā· Issue #8191 Ā· termux/termux-packages Ā· GitHub

Installing binutils solves the issue for the time being:
pkg install binutils

1 Like

@Ritual I have not encountered errors related to this package.
Do you have more details about the error, a longer log message perhaps? Also, try to give more details on your configuration (tablet, system, etc)

I was trying to install it on oneplus x.
I wanted to try before i buy a raspberry and install on it.
But with no luck.
I tried it on lineage(Android 11) and rr remix Android 7
I got many different errors on both those roms.
I got the previous error which i posted from the playstore version,which got resolved once i downloaded the apk from github.
I got many errors after that and i tried resolving it for few hours and ultimately gave up.
Thank you tho.