Home Assistant Core on Android Tablet

Thanks for the guide and all the comments. Getting the server up and running took some time and sharpening of my linux commandline skills. But knowing python and having installed LineageOS already it wat doable. Main issue was python library dependancies which has already been highlighted above.

I recently had an issue where termux would crash (every 12hrs or so) with “failed to allocate memory”. After some trial and error, it was actually the termux boot causing an issue. Instead I now just open the bootscript manually instead of using the termux:boot app. I also pinned the termux app which hopefully also causes android to not reduce memory allowance. Its now been running smoothly for over a week or so.

Update: it worked fine for quite a while however storage limitations meant that I have switched to a mini pc with HAOS after reading many forum discussions. The easy updates and add-ons remove the headaches of supervised. Android is an easy platform to try if it’s your thing however.

Hi! I tried to follow the guide, but unfortunately when I tried to run ‘pip install homeassistant’ I got this error:
Could not build wheels for bcrypt, cryptography, orjson, which is required to install pyproject.toml-based projects
The device I’m trying to install on is a Samsung S9 with Android 10.
Could someone help me out? Thanks

I have an error due to lru-dict dependency, because it doesn’t work with python 3.11, any way to solve it?

`× Running setup.py install for lru-dict did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      running install
      /data/data/com.termux/files/usr/lib/python3.11/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build                                           running build_ext
      building 'lru' extension                                creating build
      creating build/temp.linux-aarch64-cpython-311
      aarch64-linux-android-clang -DNDEBUG -g -fwrapv -O3 -Wall -fstack-protector-strong -O3 -fstack-protector-strong -O3 -fPIC -I/data/data/com.termux/files/usr/include/python3.11 -c lru.c -o build/temp.linux-aarch64-cpython-311/lru.o
      lru.c:629:17: error: incompatible function pointer types initializing 'PyCFunction' (aka 'struct _object *(*)(struct _object *, struct _object *)') with an expression of type 'PyCFunctionWithKeywords' (aka 'struct _object *(*)(struct _object *, struct _object *, struct _object *)') [-Wincompatible-function-pointer-types]
          {"popitem", (PyCFunctionWithKeywords)LRU_popitem, METH_VARARGS | METH_KEYWORDS,
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/data/data/com.termux/files/usr/bin/aarch64-linux-android-clang' failed with exit code 1
      [end of output]                                   
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lru-dict                                            
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.`
1 Like

Hi @natsukiller,

The compilation error you shared is not related to Python 3.11 incompatibility. It’s because clang now detects function pointer mismatches (like GCC has done for ages).

Install a pre-release lru-dict by using:

pip install git+https://github.com/amitdev/lru-dict@5013406c409a0a143a315146df388281bfb2172d

To disable the incompatible pointer type warning, run:

CFLAGS=-Wno-incompatible-pointer-types pip install lru-dict

1 Like

thank you it worked for me

My hack may cause segfaults. A proper solution is this:

Hello. i want to install ha on redmi s2. everything is installed, but when I try to start ha, it writes this:

(hass) ~ $ hass -v
Unable to find configuration. Creating default one in /data/data/com.termux/files/home/.homeassistant
2023-04-17 02:37:30.487 INFO (MainThread) [homeassistant.bootstrap] Config directory: /data/data/com.termux/files/home/.homeassistant
Bad system call

what do i need to do? I’m a complete zero in programming, I installed according to the instructions
PS: ha is 2023.4.4. all other packages are also the latest versions
PSS: lru-dict installing from “CFLAGS=-Wno-incompatible-pointer-types pip install lru-dict”

A couple of months ago I was able to follow @gj9159a instructions to get HomeAssistant working on LineageOS 20 on Xiaomi Redmi Note 7.

However, I found Lineage rather sluggish when memory was tight, and have reflashed with crDroid 9.1 on Redmi Note 7 (ASOP based ROM), but when I try to install Home Assistant, I get the massive error output shown below when I try to install numpy (I’ve cut out a large chunk of the repetitive stuff in the middle).

Can anyone indicate if this is a compatibility issue with whatever packages & if there is a way to resolve it? Or if its a fundamental problem with trying to do this on a non-LineageOS ROM and I’ll have to reflash?

(hass) ~ $ MATHLIB=m pip install numpy==1.24.2
Collecting numpy==1.24.2
  Using cached numpy-1.24.2.tar.gz (10.9 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: numpy
  Building wheel for numpy (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for numpy (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [962 lines of output]
      Running from numpy source directory.
      setup.py:67: DeprecationWarning:

        `numpy.distutils` is deprecated since NumPy 1.23.0, as a result
        of the deprecation of `distutils` itself. It will be removed for
        Python >= 3.12. For older Python versions it will remain present.
        It is recommended to use `setuptools < 60.0` for those Python versions.
        For more details, see:
          https://numpy.org/devdocs/reference/distutils_status_migration.html
          
          
          
          
          
          #lots of subsequent output, ending with the below
          
          
          
          
          
          
          ret.c99_z = casinhl(z1.c99_z);
                      ^
      numpy/core/src/npymath/npy_math_complex.c.src:1765:17: note: include the header <complex.h> or explicitly provide a declaration for 'casinhl'
      numpy/core/src/npymath/npy_math_complex.c.src:1765:17: error: call to undeclared library function 'catanhl' with type '_Complex long double (_Complex long double)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
          ret.c99_z = catanhl(z1.c99_z);
                      ^
      numpy/core/src/npymath/npy_math_complex.c.src:1765:17: note: include the header <complex.h> or explicitly provide a declaration for 'catanhl'
      19 errors generated.
      error: Command "aarch64-linux-android-clang -DNDEBUG -g -fwrapv -O3 -Wall -fstack-protector-strong -O3 -fstack-protector-strong -O3 -fPIC -ftrapping-math -Ibuild/src.linux-aarch64-3.11/numpy/core/src/npymath -Inumpy/core/include -Ibuild/src.linux-aarch64-3.11/numpy/core/include/numpy -Ibuild/src.linux-aarch64-3.11/numpy/distutils/include -Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/src/_simd -I/data/data/com.termux/files/usr/include/python3.11 -Ibuild/src.linux-aarch64-3.11/numpy/core/src/common -Ibuild/src.linux-aarch64-3.11/numpy/core/src/npymath -c build/src.linux-aarch64-3.11/numpy/core/src/npymath/npy_math_complex.c -o build/temp.linux-aarch64-3.11/build/src.linux-aarch64-3.11/numpy/core/src/npymath/npy_math_complex.o -MMD -MF build/temp.linux-aarch64-3.11/build/src.linux-aarch64-3.11/numpy/core/src/npymath/npy_math_complex.o.d" failed with exit status 1
      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 ASIMDFHM
        Generated   : none
      INFO: CCompilerOpt.cache_flush[857] : write cache to path -> /data/data/com.termux/files/usr/tmp/pip-install-omlvtrez/numpy_19147465a3e342479d58d27c5195b878/build/temp.linux-aarch64-3.11/ccompiler_opt_cache_clib.py
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for numpy
Failed to build numpy
ERROR: Could not build wheels for numpy, which is required to install pyproject.toml-based projects
(hass) ~ $

pip list gives the below list of packages:

(hass) ~ $ pip list
Package            Version
------------------ -------
aiohttp            3.8.4
aiohttp-cors       0.7.0
aiosignal          1.3.1
async-timeout      4.0.2
attrs              23.1.0
cffi               1.15.1
charset-normalizer 3.1.0
cryptography       40.0.2
frozenlist         1.3.3
idna               3.4
maturin            0.14.17
multidict          6.0.4
pip                23.1
pycparser          2.21
setuptools         67.6.1
tzdata             2023.3
wheel              0.40.0
yarl               1.8.2
(hass) ~ $

I’m using Python 3.11.3

Hi @djdery,

Please uninstall lru-dict, and reinstall using:

pip install git+https://github.com/amitdev/lru-dict@5013406c409a0a143a315146df388281bfb2172d

Hi @smithbill17,

I ran into this error on Lineage 19.x, so don’t think you need to re-flash.

If you’re using the packaged Termux python 3.11, then try: pkg i python-numpy.

If not, you’ll have to build a patched package from the termux-packages repo.

See the explanation on the Termux wiki

Hello @talss89 .
I did everything as you said and in the end I get this:

(hass) ~ $ pip install git+https://github.com/amitdev/lru-dict@5013406c409a0a143a315146df388281bfb2172d
Collecting git+https://github.com/amitdev/lru-dict@5013406c409a0a143a315146df388281bfb2172d
  Cloning https://github.com/amitdev/lru-dict (to revision 5013406c409a0a143a315146df388281bfb2172d) to /data/data/com.termux/files/usr/tmp/pip-req-build-du45fk9s
  Running command git clone --filter=blob:none --quiet https://github.com/amitdev/lru-dict /data/data/com.termux/files/usr/tmp/pip-req-build-du45fk9s
  Running command git rev-parse -q --verify 'sha^5013406c409a0a143a315146df388281bfb2172d'
  Running command git fetch -q https://github.com/amitdev/lru-dict 5013406c409a0a143a315146df388281bfb2172d
  Running command git checkout -q 5013406c409a0a143a315146df388281bfb2172d
  Resolved https://github.com/amitdev/lru-dict to commit 5013406c409a0a143a315146df388281bfb2172d
  Preparing metadata (setup.py) ... done
(hass) ~ $ pip list
Package                    Version
-------------------------- ---------
aiohttp                    3.8.4
aiohttp-cors               0.7.0
aiosignal                  1.3.1
anyio                      3.6.2
astral                     2.2
async-timeout              4.0.2
atomicwrites-homeassistant 1.4.1
attrs                      22.2.0
awesomeversion             22.9.0
bcrypt                     4.0.1
certifi                    2022.12.7
cffi                       1.15.1
charset-normalizer         3.1.0
ciso8601                   2.3.0
cryptography               40.0.1
frozenlist                 1.3.3
h11                        0.14.0
home-assistant-bluetooth   1.9.3
homeassistant              2023.4.4
httpcore                   0.16.3
httpx                      0.23.3
idna                       3.4
ifaddr                     0.1.7
Jinja2                     3.1.2
lru-dict                   1.1.8
MarkupSafe                 2.1.2
maturin                    0.14.17
multidict                  6.0.4
numpy                      1.24.2
orjson                     3.8.7
pip                        23.1
pycparser                  2.21
PyJWT                      2.6.0
pyOpenSSL                  23.1.0
python-slugify             4.0.1
PyTurboJPEG                1.7.0
pytz                       2023.3
PyYAML                     6.0
requests                   2.28.2
rfc3986                    1.5.0
setuptools                 67.6.1
sniffio                    1.3.0
text-unidecode             1.3
typing_extensions          4.5.0
tzdata                     2023.3
ulid-transform             0.6.3
urllib3                    1.26.15
voluptuous                 0.13.1
voluptuous-serialize       2.6.0
wheel                      0.40.0
yarl                       1.8.1
(hass) ~ $ hass -v
2023-04-17 12:28:10.337 INFO (MainThread) [homeassistant.bootstrap] Config directory: /data/data/com.termux/files/home/.homeassistant
Bad system call

You need to remove lru-dict first.

Try:

pip uninstall lru-dict

then:

pip install git+https://github.com/amitdev/lru-dict@5013406c409a0a143a315146df388281bfb2172d

@talss89

(hass) ~ $ pip uninstall lru-dict
Found existing installation: lru-dict 1.1.8
Uninstalling lru-dict-1.1.8:
  Would remove:
    /data/data/com.termux/files/usr/lib/python3.11/site-packages/lru.cpython-311.so
    /data/data/com.termux/files/usr/lib/python3.11/site-packages/lru_dict-1.1.8.dist-info/*
Proceed (Y/n)? y
  Successfully uninstalled lru-dict-1.1.8
(hass) ~ $ pip install git+https://github.com/amitdev/lru-dict@5013406c409a0a143a315146df388281bfb2172d
Collecting git+https://github.com/amitdev/lru-dict@5013406c409a0a143a315146df388281bfb2172d
  Cloning https://github.com/amitdev/lru-dict (to revision 5013406c409a0a143a315146df388281bfb2172d) to /data/data/com.termux/files/usr/tmp/pip-req-build-fv_k_o5d
  Running command git clone --filter=blob:none --quiet https://github.com/amitdev/lru-dict /data/data/com.termux/files/usr/tmp/pip-req-build-fv_k_o5d
  Running command git rev-parse -q --verify 'sha^5013406c409a0a143a315146df388281bfb2172d'
  Running command git fetch -q https://github.com/amitdev/lru-dict 5013406c409a0a143a315146df388281bfb2172d
  Running command git checkout -q 5013406c409a0a143a315146df388281bfb2172d
  Resolved https://github.com/amitdev/lru-dict to commit 5013406c409a0a143a315146df388281bfb2172d
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: lru-dict
  Building wheel for lru-dict (setup.py) ... done
  Created wheel for lru-dict: filename=lru_dict-1.1.8-cp311-cp311-linux_armv7l.whl size=22808 sha256=5c14a44f0cd119ab7e7c61f5e3413ee1090090d707ff6472f3eb1297bd38298d
  Stored in directory: /data/data/com.termux/files/home/.cache/pip/wheels/06/a3/a4/1451203259031f09c1d125226a23d74f822a56c09c33bca1ce
Successfully built lru-dict
Installing collected packages: lru-dict
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
homeassistant 2023.4.4 requires pip<23.1,>=21.0, but you have pip 23.1 which is incompatible.
Successfully installed lru-dict-1.1.8
(hass) ~ $ hass -v
2023-04-17 12:55:18.002 INFO (MainThread) [homeassistant.bootstrap] Config directory: /data/data/com.termux/files/home/.homeassistant
Bad system call
````(hass) ~ $ pip install pip==23.0.1
Collecting pip==23.0.1
  Using cached pip-23.0.1-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 23.1
    Uninstalling pip-23.1:
      Successfully uninstalled pip-23.1
Successfully installed pip-23.0.1

[notice] A new release of pip is available: 23.0.1 -> 23.1
[notice] To update, run: pip install --upgrade pip
(hass) ~ $ hass -v
2023-04-17 12:57:53.419 INFO (MainThread) [homeassistant.bootstrap] Config directory: /data/data/com.termux/files/home/.homeassistant
Bad system call`

(hass) ~ $ pip install pip==23.0.1
Collecting pip==23.0.1
Using cached pip-23.0.1-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 23.1
Uninstalling pip-23.1:
Successfully uninstalled pip-23.1
Successfully installed pip-23.0.1

[notice] A new release of pip is available: 23.0.1 → 23.1
[notice] To update, run: pip install --upgrade pip
(hass) ~ $ hass -v
2023-04-17 12:57:53.419 INFO (MainThread) [homeassistant.bootstrap] Config directory: /data/data/com.termux/files/home/.homeassistant
Bad system call

1 Like

@talss89 you are a genius sir. Your pkg i python-numpy did the trick. I also needed your detail about uninstalling & reinstalling lru-dict

In the end, I think this is a full list of the instructions I needed to get HomeAssistant set up based on @gj9159a post (I’m not sure if there is anything that is unnecessary in the end, but I’m pasting it here in case it helps others):

# set SELinux=Permissive
su
setenforce 0

apt update
apt upgrade
pkg install openssh
passwd #setting the password
sshd #go to kitty/putty on PC
termux-setup-storage #confirm on the device
pkg install tsu python nano termux-api make libjpeg-turbo make rust python-cryptography libcrypt libffi binutils mosquitto wget -y

pkg install git
pkg i python-numpy

python -m venv --without-pip hass
source hass/bin/activate
pip install wheel
pip install tzdata
pip install maturin
pip install setuptools
MATHLIB=m pip install aiohttp_cors==0.7.0
MATHLIB=m pip install numpy==1.24.2
MATHLIB=m pip install PyTurboJPEG==1.6.7
export RUSTFLAGS="-C lto=n"
export CARGO_BUILD_TARGET="$(rustc -Vv | grep "host" | awk '{print $2}')" 
export CRYPTOGRAPHY_DONT_BUILD_RUST=1
pip download homeassistant==2023.2.3
wheel unpack homeassistant-2023.2.3-py3-none-any.whl
nano homeassistant-2023.2.3/homeassistant/package_constraints.txt
#We are looking for aiohttp and change its version to 3.8.3, as well as numpy to version 1.24.2, then press CTRL-X, Y, ENTER.
nano homeassistant-2023.2.3/homeassistant-2023.2.3.dist-info/METADATA
#We are looking for aiohttp and change its version to 3.8.3, press CTRL-X, Y, ENTER.
rm homeassistant-2023.2.3-py3-none-any.whl
wheel pack homeassistant-2023.2.3

pip uninstall lru-dict
pip install git+https://github.com/amitdev/lru-dict@5013406c409a0a143a315146df388281bfb2172d

pip install homeassistant-2023.2.3-py3-none-any.whl
pip install --upgrade pip
hass -v
#wait 5 minutes and restart the device
source hass/bin/activate #don't forget to activate the environment
hass -v #after a couple of minutes, you can try to log in
3 Likes

Great, so glad it worked out, and thank you for contributing your process, this is exactly what I needed!

I’m building a full Home Assistant Core .deb package with dh-virtualenv, so we can all leave this confusion behind and just install with pkg i homeassistant, so your process is really useful to see. I’ll review and merge with my build script.

There are known issues with network reconnects triggering an error loop (socket _accept_connection() error 22), and a discovery bug that relies on /etc/resolv.conf. I have patches for both in the pipeline, but for now you may want to use a restart automation.

Will share once I have something working.

1 Like

Had this error, managed to fix it somehow (can’t remember how) and worked for several days without any issues. Today I restarted Termux and now I get this error again.
I can start with --safe-mode but nothing in the logs (no errors, no warnings, no failures)

EDIT:
I think I solved it. Try this:

pkg in proot
termux-chroot
source hass/bin/activate
hass -v
1 Like

I’ve built an installer for HA Core on Android / Termux (ARM64). It’s alpha, but works on my LineageOS 19 rooted device, and on Termux / ARM64 machines in the cloud.

For anyone eager to try, there is a one-liner web install (although please be prepared for this to possibly break Termux entirely - this is not production ready):

curl -sL https://github.com/talss89/termux-home-assistant-installer/releases/download/v2023.4.4-alpha.3/remote-install.sh | bash

Would be interested to see how this works for others. Please raise issues via the GitHub repo.

5 Likes

Congratulations for the work Talss89!
Awesome works on my Samsung Tab S2 lineage os 18(homeassistant 2023.5.3)! I just have an error for ha-av how can I fix?

talss89, I express my great gratitude to you for the work done! This is exactly what was needed and was asking for! I hope you won’t abandon the script and will update it as much as possible, thank you!

With hass - v boot, did you have any errors with ha-av?