HA Companion App frequently stops sending sensor data

I have 3 wall tablets (Lenovo Tab M10 running Android 10) in my house. I have the HA companion app (v. 2022.1.1) on the tablets and sending the battery status back to HA. I use that status to turn on/off the charger. However, the HA app frequently (at least once per day on a given tablet) stops reporting the battery sensor data. Has anyone else had this issue or know of a fix?

Make sure the app has proper access to run in background sounds like it doesn’t.

In the app settings it says “Home Assistant has access to run in the background”

They’re could still be other settings on the device causing it to be killed by the system. The sensor worker runs every 15 minutes as long as the system didn’t kill the app.

Dontkillmyapp.com usually has some good tips on this

I downloaded Don’tKillMyApp and had it run a test to see if the tablet was killing apps and the result was that it wasn’t. I’ve had the battery optimization disabled on the tablet as well.

When does this happen? After the device is off the charger? You could try looking at the logs in companion app to see if there is a failure at that time. How long do you wait to realize it’s no longer updating the stats? The sensor worker runs on a 15 minute interval and only updates the state of it had changed since the last update.

Actually, yeah, it only happens when the charger is turned off. I hadn’t thought about that. I have an automation set up to trigger if the percentage of battery remaining doesn’t change for 2 hours.

Where are the companion app logs located?

Configuration > companion app > show and share logs

The logs don’t go back far enough. The longest log I have on my 3 tablets only goes back 30 seconds. Below is the entirety of my log

--------- beginning of main
02-04 20:06:58.665 32358 32358 D ApplicationPackageManager: hasSystemFeature android.hardware.touchscreen io.homeassistant.companion.android
02-04 20:06:58.753 32358 32358 D ApplicationPackageManager: hasSystemFeature android.hardware.touchscreen.multitouch.jazzhand io.homeassistant.companion.android
02-04 20:06:58.945 32358 32358 I SurfaceFactory: [static] sSurfaceFactory = com.mediatek.view.impl.SurfaceFactoryImpl@34d72d2
--------- beginning of system
02-04 20:06:58.947 32358 32358 D AppResolutionTuner: loadTunerAppList + 
02-04 20:06:58.954 32358 32358 D AppResolutionTuner: loadTunerAppList - 
02-04 20:06:58.954 32358 32358 D SurfaceExt: initResolutionTunner, mPackageName:io.homeassistant.companion.android,mContainPackageName:falsemXScaleValue:1.0,mYScaleValue:1.0
02-04 20:06:59.014 32358 32358 D RenderScript HIDL Adaptation: IRenderScriptDevice::getService()
02-04 20:06:59.017 32358 32358 D RenderScript HIDL Adaptation: IRenderScriptDevice::getService() returned 0x0
02-04 20:06:59.017 32358 32358 D RenderScript HIDL Adaptation: Using Fallback Path.
02-04 20:06:59.083 32358 32358 D         : Successfully queried cache dir: /data/user_de/0/io.homeassistant.companion.android/code_cache
02-04 20:06:59.083 32358 32358 D RenderScript: Setting cache dir: /data/user_de/0/io.homeassistant.companion.android/code_cache
02-04 20:06:59.173 32358 32358 I System.out: recordForce value 6
02-04 20:06:59.176 32358 32358 D WebviewActivity: Current webview package com.google.android.webview and version 98.0.4758.87
02-04 20:06:59.269 32358 32358 D ApplicationPackageManager: hasSystemFeature android.hardware.location.gps io.homeassistant.companion.android
02-04 20:06:59.316 32358  2372 I FA      : Tag Manager is not found and thus will not be used
02-04 20:06:59.330 32358  2370 I System.out: [OkHttp] sendRequest>>
02-04 20:06:59.330 32358  2370 I System.out: [OkHttp] sendRequest<<
02-04 20:06:59.381 32358 32358 D ViewRootImpl[WebViewActivity]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
02-04 20:06:59.394 32358 32358 V PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@74edf23, this = DecorView@ca3dc20[WebViewActivity]
02-04 20:06:59.418 32358  2320 E chromium: [ERROR:simple_index_file_posix.cc(36)] opendir /data/user/0/io.homeassistant.companion.android/cache/WebView/Default/HTTP Cache/Code Cache/js: No such file or directory (2)
02-04 20:06:59.418 32358  2318 E chromium: [ERROR:simple_index_file_posix.cc(36)] opendir /data/user/0/io.homeassistant.companion.android/cache/WebView/Default/HTTP Cache/Code Cache/wasm: No such file or directory (2)
02-04 20:06:59.418 32358  2320 E chromium: [ERROR:simple_index_file.cc(575)] Could not reconstruct index from disk
02-04 20:06:59.418 32358  2318 E chromium: [ERROR:simple_index_file.cc(575)] Could not reconstruct index from disk
02-04 20:06:59.487 32358 32358 E GraphicExt: Can't load libboost_ext_fwk
02-04 20:06:59.487 32358 32358 E GraphicExt: GraphicExtModuleLoader::CreateGraphicExtInstance false
02-04 20:06:59.488 32358  2245 I GPUD    : @gpudInitialize: successfully initialized with GL, dbg=0 mmdump_dbg=0 mmpath_dbg=0
02-04 20:06:59.530 32358  2245 D Surface : Surface::connect(this=0x710eea8000,api=1)
02-04 20:06:59.532 32358  2245 D Surface : Surface::setBufferCount(this=0x710eea8000,bufferCount=3)
02-04 20:06:59.574 32358 32358 I GED     : ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 2, oppidx_max 2, oppidx_min 0
02-04 20:06:59.595 32358  2245 W Gralloc3: mapper 3.x is not supported
02-04 20:06:59.599 32358  2245 E ion     : ioctl c0044901 failed with code -1: Invalid argument
02-04 20:06:59.648 32358 32403 D SensorWorker: Updating all Sensors.
02-04 20:06:59.662 32358 32404 I WM-Processor: Moving WorkSpec (69cde21b-5e44-4288-b570-6e8da4a1a8c0) to the foreground
02-04 20:06:59.676 32358 32358 D UrlRepository: localUrl is: false and usesInternalSsid is: false
02-04 20:06:59.677 32358 32358 D UrlRepository: Using external URL
02-04 20:06:59.710 32358  2333 D ApplicationPackageManager: hasSystemFeature android.hardware.telephony io.homeassistant.companion.android
02-04 20:06:59.791 32358 32358 I WM-SystemFgDispatcher: Started foreground service Intent { act=ACTION_START_FOREGROUND cmp=io.homeassistant.companion.android/androidx.work.impl.foreground.SystemForegroundService (has extras) }
02-04 20:06:59.826 32358  2386 W IMGSRV  : glGetString:4370: Override GL_RENDERER PowerVR SGX Doma 
02-04 20:06:59.845 32358  2386 I chatty  : uid=10159(io.homeassistant.companion.android) Chrome_InProcGp identical 4 lines
02-04 20:06:59.845 32358  2386 W IMGSRV  : glGetString:4370: Override GL_RENDERER PowerVR SGX Doma 
02-04 20:06:59.996 32358  2386 W IMGSRV  : glGetString:4370: Override GL_RENDERER PowerVR SGX Doma 
02-04 20:07:00.008 32358  2386 I chatty  : uid=10159(io.homeassistant.companion.android) Chrome_InProcGp identical 20 lines
02-04 20:07:00.009 32358  2386 W IMGSRV  : glGetString:4370: Override GL_RENDERER PowerVR SGX Doma 
02-04 20:07:00.200 32358 32403 D ApplicationPackageManager: hasSystemFeature android.hardware.location.gps io.homeassistant.companion.android
02-04 20:07:00.350 32358 32370 I mpanion.androi: Background concurrent copying GC freed 26084(1285KB) AllocSpace objects, 5(100KB) LOS objects, 29% free, 14MB/20MB, paused 287us total 235.801ms
02-04 20:07:00.428 32358 32403 D SensorReceiver: Nothing to update
02-04 20:07:00.430 32358 32439 I WM-WorkerWrapper: Worker result SUCCESS for Work [ id=69cde21b-5e44-4288-b570-6e8da4a1a8c0, tags={ io.homeassistant.companion.android.sensors.SensorWorker } ]
02-04 20:07:00.434 32358 32358 I WM-SystemFgDispatcher: Stopping foreground service
02-04 20:07:00.472 32358  2386 W IMGSRV  : glGetString:4370: Override GL_RENDERER PowerVR SGX Doma 
02-04 20:07:00.472 32358  2386 W IMGSRV  : glGetString:4370: Override GL_RENDERER PowerVR SGX Doma 
02-04 20:07:04.401 32358 32358 D UrlRepository: localUrl is: false and usesInternalSsid is: false
02-04 20:07:04.401 32358 32358 D UrlRepository: Using external URL
02-04 20:07:05.288 32358  2421 D WebviewActivity: External bus {"type":"connection-status","payload":{"event":"connected"},"id":1}
02-04 20:07:06.358 32358  2421 D WebviewActivity: External bus {"type":"theme-update","id":2}
02-04 20:07:06.532 32358 32358 D WebviewActivity: Color from webview is "#101e24-SPACER-#111111"
02-04 20:07:06.532 32358 32358 D WebviewActivity: Color from webview is "#101e24-SPACER-#111111"
02-04 20:07:06.534 32358 32403 D WebViewPresenterImpl: Try getting color from webview color "#101e24".
02-04 20:07:06.540 32358 32403 I WebViewPresenterImpl: Found color -15720924.
02-04 20:07:06.540 32358 32403 D WebViewPresenterImpl: Try getting color from webview color "#111111".
02-04 20:07:06.541 32358 32403 I WebViewPresenterImpl: Found color -15658735.
02-04 20:07:06.949 32358  2421 D WebviewActivity: External bus {"type":"config/get","id":3}
02-04 20:07:06.950 32358 32358 D ApplicationPackageManager: hasSystemFeature android.hardware.nfc io.homeassistant.companion.android
02-04 20:07:06.979 32358 32358 D WebviewActivity: externalBus({"id":3,"type":"result","success":true,"result":{"hasSettingsScreen":true,"canWriteTag":false,"hasExoPlayer":true}});
02-04 20:07:07.288 32358 32358 D WebviewActivity: Callback null
02-04 20:07:07.289 32358 32358 D WebviewActivity: Color from webview is "#101e24-SPACER-#111111"
02-04 20:07:07.289 32358 32358 D WebviewActivity: Color from webview is "#101e24-SPACER-#111111"
02-04 20:07:07.290 32358 32403 D WebViewPresenterImpl: Try getting color from webview color "#101e24".
02-04 20:07:07.290 32358 32403 I WebViewPresenterImpl: Found color -15720924.
02-04 20:07:07.308 32358 32445 D WebViewPresenterImpl: Try getting color from webview color "#111111".
02-04 20:07:07.308 32358 32445 I WebViewPresenterImpl: Found color -15658735.
02-04 20:07:08.693 32358 32358 D LightSensor: Light sensor listener unregistered
02-04 20:07:09.922 32358  2421 D WebviewActivity: External bus {"type":"config_screen/show","id":4}
02-04 20:07:10.062 32358 32358 W ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@8e50edb
02-04 20:07:10.174 32358 32358 D ApplicationPackageManager: hasSystemFeature android.software.picture_in_picture io.homeassistant.companion.android
02-04 20:07:10.274 32358 32358 D UrlRepository: Using external URL
02-04 20:07:10.274 32358 32358 D UrlRepository: Using external URL
02-04 20:07:10.282 32358 32358 D UrlRepository: Using external URL
02-04 20:07:10.282 32358 32358 D UrlRepository: Using external URL
02-04 20:07:10.301 32358 32358 D ApplicationPackageManager: hasSystemFeature android.hardware.nfc io.homeassistant.companion.android
02-04 20:07:10.329 32358 32358 V FeatureOptions: country_code is 'US', is not arab country.
02-04 20:07:11.221 32358 32358 D ApplicationPackageManager: hasSystemFeature android.hardware.type.automotive io.homeassistant.companion.android
02-04 20:07:11.252 32358 32358 V PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = DecorView@70b195[]
02-04 20:07:11.253 32358 32358 D ViewRootImpl[SettingsActivity]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
02-04 20:07:11.257 32358 32358 V PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@edc2238, this = DecorView@70b195[SettingsActivity]
02-04 20:07:11.277 32358 32358 I Choreographer: Skipped 72 frames!  The application may be doing too much work on its main thread.
02-04 20:07:11.298 32358 32358 E GraphicExt: GraphicExtModuleLoader::CreateGraphicExtInstance false
02-04 20:07:11.298 32358  2245 D Surface : Surface::connect(this=0x7065c20000,api=1)
02-04 20:07:11.303 32358  2245 D Surface : Surface::setBufferCount(this=0x7065c20000,bufferCount=3)
02-04 20:07:11.303 32358  2245 D Surface : Surface::allocateBuffers(this=0x7065c20000)
02-04 20:07:11.666 32358  2245 I OpenGLRenderer: Davey! duration=1593ms; Flags=1, IntendedVsync=2679500115099932, Vsync=2679501315099956, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=2679501326582781, AnimationStart=2679501326620550, PerformTraversalsStart=2679501329813165, DrawStart=2679501520372473, SyncQueued=2679501528851627, SyncStart=2679501535366242, IssueDrawCommandsStart=2679501535885165, SwapBuffers=2679501712942781, FrameCompleted=2679501714726550, DequeueBufferDuration=0, QueueBufferDuration=886000, 
02-04 20:07:11.677 32358  2245 I OpenGLRenderer: Davey! duration=1609ms; Flags=1, IntendedVsync=2679500115099932, Vsync=2679501315099956, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=2679501326582781, AnimationStart=2679501326620550, PerformTraversalsStart=2679501329813165, DrawStart=2679501716899396, SyncQueued=2679501717694473, SyncStart=2679501718819011, IssueDrawCommandsStart=2679501718960396, SwapBuffers=2679501724606858, FrameCompleted=2679501725998473, DequeueBufferDuration=0, QueueBufferDuration=681000, 
02-04 20:07:11.805 32358 32358 I Choreographer: Skipped 30 frames!  The application may be doing too much work on its main thread.
02-04 20:07:12.078 32358 32445 D SensorWorker: Updating all Sensors.
02-04 20:07:12.125 32358 32389 I WM-Processor: Moving WorkSpec (ba8d3fed-057b-40b8-9c43-6ee7b991307f) to the foreground
02-04 20:07:12.215 32358  2245 D Surface : Surface::disconnect(this=0x710eea8000,api=1)
02-04 20:07:12.337 32358 32358 I WM-SystemFgDispatcher: Started foreground service Intent { act=ACTION_START_FOREGROUND cmp=io.homeassistant.companion.android/androidx.work.impl.foreground.SystemForegroundService (has extras) }
02-04 20:07:12.600 32358 32358 V PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@74edf23, this = DecorView@ca3dc20[WebViewActivity]
02-04 20:07:12.696 32358 32445 D LightSensor: Light sensor listener registered
02-04 20:07:12.711 32358 32358 D LightSensor: Light sensor listener unregistered
02-04 20:07:12.741 32358 32445 D ApplicationPackageManager: hasSystemFeature android.hardware.location.gps io.homeassistant.companion.android
02-04 20:07:12.905 32358 32445 D UrlRepository: localUrl is: false and usesInternalSsid is: false
02-04 20:07:13.049 32358 32443 I WM-WorkerWrapper: Worker result SUCCESS for Work [ id=ba8d3fed-057b-40b8-9c43-6ee7b991307f, tags={ io.homeassistant.companion.android.sensors.SensorWorker } ]
02-04 20:07:13.054 32358 32358 I WM-SystemFgDispatcher: Stopping foreground service
02-04 20:07:18.517 32358 32445 D LogcatReader: Read logcat for pid 32358

Asides from using the dontkillmyapp benchmark app did you take a look at this page and try the padlock trick they mentioned? I know they call out the P2 but these steps tell me there is probably some other hidden setting you may need to dig deep on to find a way to give the app better access

The fact that it happens when the device is off the charger highly suggests the app is still being killed in the background. The logs are also based off the PID given to the application by android and that also gets reset if the app was killed by the system.

If all else fails the next release will contain a notification command to update the sensors however if the app is killed it may not receive the command.

I’ve spent an hour googling and trying to find every possible way to stop it from being killed in the background and I have all the settings correct from what I’m reading. I don’t have the padlock icon on the app. But it is listed as “not optimized” for battery, which is the reoccurring theme from what I’m seeing on google.