question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Last app sensor nearly always reads as Home Assistant app

See original GitHub issue

Home Assistant Android version: b7e4fb7b9b4b2ada30c23eeb42c255b7f082e619

Android version: varies

Phone model: varies

Home Assistant version:

Last working Home Assistant release (if known):

Description of problem:

The last app sensor is implemented using the usage stats that Android produces. However, it simply takes the last app that was reported as being in use.

On the devices I’ve run this on, this has no relationship to the app that the user thinks they are using, and in fact nearly all the time the last used app reported by the sensor is the Home Assistant app itself. This makes perfect sense - in order to send out the sensor data, the Home Assistant app has been woken up (and hence is in use in the background), and thus has the most recent usage stats record. I guess there is some asynchronisity to the usage gathering, since just occasionally another app is given as the last used one (perhaps it depends on what other apps are running at the same time, and whether they also do lots of background processing).

Looking via Git, I can see that during development this sensor was changed from returning the app package, to returning the app label if available, only falling back to the app package if not. I can understand that that gives a better display string, but it’s fundamentally flawed; the app label is not unique - for example I have multiple apps on my phone that call themselve “Maps” or “Camera”. For this sensor to be useful, it needs to return the package name which has uniqueness that allows scripts to be written knowing that they have identified the correct app. By all means also include additional information about the app as additional attributes, such as the app version, the display name, the app publisher etc.

Traceback (if applicable, to get the logs you may refer to: https://companion.home-assistant.io/docs/troubleshooting/faqs/#android-crash-logs):


Screenshot of problem:

Additional information:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
zmartiescommented, Jan 8, 2022

I’ve put some extra diags in to a local build of the code. I think the sensor should probably be using lastTimeVisible rather than lastTimeUsed. (I’m also worried that the maxByOrNull will have random behaviour if two apps have the same lastTime value - I’ve just seen an example where there were 1 apart, so tiny differences are possible, possibly zero). Got to go now, but will try and investigate a bit more later.

0reactions
dshokouhicommented, Feb 4, 2022

I found some time to test out lastTimeVisible and the results are not as consistent for me when switching apps. I would personally expect every time I take a screenshot of the sensor screen then only the HA app would be visible but it is not.

image

image

When I switch back to using lastTimeUsed everything goes back to reporting as I would expect.

image

Also going to revert back to package name for the state to make it more unique.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sensors | Home Assistant Companion Docs
Read about each sensor below to understand how often to expect updates. ... by the Home Assistant Android app, since the last device...
Read more >
Last Notification Sensor sometimes does not update
If they do not update in hass and I go to the sensor settings in the app and look at the last_notification there...
Read more >
Troubleshooting | Home Assistant Companion Docs
When the app is not in the foreground, sensor updates are tied to location updates, so you need to make sure that location...
Read more >
Frequency of updates? - Home Assistant Companion for Android
Hi I have the HomeAssistant app runing on my Galaxy S10+, and use the data from there for device tracking. But there seems...
Read more >
Make the HA Companion App detect arrive home fast enough ...
Another appraoch, if the above solution is too battery intensive, could be to create an automation in Home Assistant that requests the Companion ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found