Home Assistant Core on Android Tablet

try to reinstall termux

also no problems with HA 2022.12.1 instead of 2022.12.0

Able to compile ginko kernel (xiomi note 8) with additional flags. Now I have HA core in docker containers in Termux.

script for checking kernel config

1 Like

Hi!

I managed to install all the necessary things ( in theory)

wen i try HASS - V this fail every time with this line

I’ve try to get root and i have already gave permission to the storage.

have any tips?

Thanks

I’ll refer you to my previous message Home Assistant Core on Android Tablet - #110 by Gnoupi

I don’t see a failure in your log. Well, there is a failure to access some core data that could be used to monitor the system, but I have that as well. Termux just does not allow access to those. It does not prevent HA from functioning, though.

So try to launch it again, give it time to install some sub-dependencies in the back, and monitor CPU activity on side if you have doubts that anything is happening with it.

I was successfully able to install home assistant 2022.12.2 on a Teclast P80X android tablet using these steps, thank you!

I needed two additional steps though.

  1. Cargo kept crashing with a SIGKILL on my tablet due to running out of memory during building (2GB ram). I needed to restrict the number of parallel tasks to 1 by calling:
export CARGO_BUILD_JOBS=1
  1. I forced aiohttp to >3.8.1 by the following two commands:
echo "aiohttp>=3.8.2" > constraints.txt
pip install -c constraints.txt homeassistant

Hi all. Thanks for this great guide. One topic seems to be missing: How to make automations work in time, which are prevented by sleeping of the home assistant server because of energy saving of your android device.
I didn’t find a solution, yet. Maybe one of you has a good idea?
Problem description: If I program an automation, which should be triggered at a certain time, it does not start at this specific time but at least 10 minutes later - sometimes hours later. (the phone time is set correctly, also the command “date” in termux outputs the correct time.) I have the impression that the automation is not running until I use my phone, unlock the screen and it wakes up. Then after several minutes the automation is triggered. The dashboard however, is responsive. I believe this could be related to energy saving mode of my phone. I tried to set in the LineageOS settings the termux app to “do not optimize battery”, but this didn’t make a difference. I’m using LineageOS 17.1 on an old Samsung Galaxy S5 neo.
What can I do?
Edit: I was studying the logs and found following warning entry which has been mentioned above. However, I don’t understand it. Is there a relation to the issue? Maybe it’s not related to the device beeing in energy saving mode. I also found plenty of other forum entries discussing the delay issue, however without solution.

2022-12-26 16:32:27.420 WARNING (SyncWorker_3) [pyroute2.netlink.rtnl.tcmsg.common] tcmsg: [Errno 13] Permission denied: '/proc/net/psched'
2022-12-26 16:32:27.477 WARNING (SyncWorker_3) [pyroute2.netlink.rtnl.tcmsg.common] the tc subsystem functionality is limited

Edit2:
I also created a date & time sensor entity for testing purposes by inserting following in the configuration.yaml:

sensor: 
  - platform: time_date
    display_options: 'date_time'

I placed it on my dashboard and learned that it also updates very irregularly and is always several minutes late:
date_time

I think this might be related to the automations not trigger in time.

Edit3: After reading and investigating a lot, I think there is a general issue running home assistant on android 10 and above with termux, because since android 10, the permission to access /proc/net/ is denied.
This is what I found additionally in my home-assistant.log

2022-12-26 20:47:10.402 CRITICAL (SyncWorker_3) [scapy.loading] Can't open /proc/net/dev !
2022-12-26 20:47:10.709 CRITICAL (SyncWorker_3) [scapy.loading] Can't open /proc/net/route !
2022-12-26 20:47:10.765 CRITICAL (SyncWorker_3) [scapy.loading] Can't open /proc/net/dev !
2022-12-26 20:47:13.463 WARNING (SyncWorker_2) [pyroute2.netlink.rtnl.tcmsg.common] tcmsg: [Errno 13] Permission denied: '/proc/net/psched'
2022-12-26 20:47:13.491 WARNING (SyncWorker_2) [pyroute2.netlink.rtnl.tcmsg.common] the tc subsystem functionality is limited

I don’t see a workaround on non rooted devices.
Edit4: I think I found a solution. All automations work now in time if you follow the steps discussed here:
link to reddit/r/termux
Thanks to u/agnostic-apollo, I found a working solution, I try to summarize here:

  • In LineageOS settings: activate android-debugging, root-debugging and adb over network
  • In termux: pkg install android-tools, and connect it with adb connect, verify with adb devices and test if you can access /proc/net/psched within adb shell
  • edit in file (which belongs to the home assistant’s venv !!!) “lib/python3.11/site-packages/pyroute2/netlink/rtnl/tcmsg/common.py”

replace

with open('/proc/net/psched', 'r') as psched:

[t2us, us2t, clock_res, wee] = [

int(i, 16) for i in psched.read().split()

]

with

psched=os.popen('adb shell cat /proc/net/psched').read().rstrip('\n')

[t2us, us2t, clock_res, wee] = [

int(i, 16) for i in psched.split()

]

  • finally, to prevent your phone from falling into deep sleep, it is necessary to run termux-wake-lock

With these steps home assistants automations should work in time, if you run it on an android phone within termux.

3 Likes

Thank you! This (post 169) worked for me with homeassistant==2022.12.0 (but not with 2022.12.1).
Im using a tablet with android 10 (unrooted).

For those having trouble installing numpy and cryptography under termux, this packages need to be installed via pkg to avoid compilation errors:
pkg install python-numpy python-cryptography

https://wiki.termux.com/wiki/Python#Package_management

1 Like

An installation option with which you can use the latest version of Home assistant (now it’s homeassistant==2023.2.3). My device: 32 GB ROM, 2 GB RAM, Android 7.1.2.
#If some package failed to download or assemble, then you need to repeat the command again (maybe even several times).

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
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 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
#if you need FTP access, then:
pkg install busybox termux-services
source $PREFIX/etc/profile.d/start-services.sh
sv-enable ftpd
sv up ftpd #to disable: sv down ftpd
4 Likes

Thanks to all guys who commented previously.
For the latest HA build, to solve aiohttp (==3.8.1) incompatibility with python 3.11 , see below:

#Downgrade to python3.10
pkg install tur-repo
pkg update
pkg install python3.10
pkg install python-is-python3.10

I have an old Allview phone unrooted Andoird 7.0 (RAM=2GB) and getting daily crashes of Termux 0.118.0 (F-droid). I reduced the number of Termux crashes with Termux:Boot uninstall.
Do you have similar problems ?

@gj9159a Thank you very much for these detailed explanation. It worked for me on a Samsung Galaxy Tab S2.

1 Like

Hello everyone.

I was able to run Home Assistant 2023.2.3 server on Xiaommi Mi A2 Lite (android 10).
But I ran into the same problem as @Gnoupi in GitHub issue - tons of thousands of error messages about BaseSelectorEventLoop._accept_connection after internet disconnected.

Can someone suggest how to fix this?

configure, for example, via Macrodroid, Termux reboot or the entire device after the connection is restored. Ie, the connection is lost, then restored, and only then the device is rebooted. Of course, you should have the Home Assistant server configured to automatically start after Termux is started (and automatically start Termux itself after Android is started).

I configured the server to automatically reboot through its own automation if this error is displayed in the log. But this is not a solution to the problem. I want this error not to occur at all.

I did a fresh flash of Lineage 20 (Android 13) on my Xiaomi Redmi Note 7 (lavender), rooted with Magisk 25.2 and installed Home Assistant in Termux by following @gj9159a excellent instructions.

All seemed to work fine but then i ran into the “permission to access /proc/net is denied” problem.

I tried following @porcupine_moon instructions, but found I couldn’t complete the part about editing the lines in common.py as I didn’t seem to have a … /site-packages/pyroute2 directory and I’m not clever enough to know why not.

I then discovered I was getting a similar permissions error just executing ifconfig

After a bit of Googling, it seems this is because I have SELinux=Enforcing. The simple instructions here explained how to set SELinux=Permissive in Termux

After setting SELinux to Permissive, Home Assistant worked fine on my phone without any issues.

I’m aware that setting SELinux to Permissive opens my phone to exploits (and I’m assuming setting it in Termux is both system wide & permanent until i set it back to Enforcing?) but if its necessary to run Home Assistant on Android 13 and that’s pretty much all the phone is used for, then I’m assuming its relatively safe to leave it as Permissive?

Slight aside question:

Having got Home Assistant installed & running on my rooted Android phone, does anyone know how I could create a sensor for display on a dashboard which shows the current battery level of the Android phone? (the phone on which HomeAssistant is running, not the client).

To do this, I installed Home Assistant companion app from GP on the phone server. The application collects information from various sensors and sends it to the server. In particular - the battery charge and whether it is on charge.

What a genius idea! Thank you :+1:

I tried LineageOS sometime ago and ran into problems. I heard about PostmarketOS (which totally replaces Android) and spent quite some time finding my way through the documents.
I now am happy with it and published a guide for my old Nexus5
Not a core installation though, I use docker.
Might be worth a look if postmarketos is available for your phone,

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.