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:
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.