I know this sounds crazy, but hear me out - can I trigger an app from HA?

Fixing the underlying issue is best. My trackers work well so there’s sunlight at the end of the road.

1 Like

You should work on a better presence detection. :rofl: I’m quite sure nearly everybody, who uses some kind of presence detection, is having that same experience as you. But mostly this is resolved by evolving to a better presence detection. :wink: I know what you mean, couldn’t resist, sorry. :slight_smile:

But nonetheless, if your presence detection is so unreliable and often not working, you might need to overthink the concept you put behind. No offense intended, really, but it took me around one year to get to a more or less bullet proof presence detection and it was not a very straight forwarded process, trust me. :expressionless: This is meant more like a “show us what you have or start a discussion with your example” kind of thing. :+1:

Coming back to your question: yes, you can send “android intents” to most apps, depends on the app you’re sending to. If the app doesn’t support intents, you’re out of luck.

Search for “ha companion app tasker” to get some examples how this works with tasker, it should get you going, as only the receiver/receiving app is different (not tasker).

So, how did you do your presence detection at all, maybe if you share some insights, somebody could give suggestions to improve it. :slight_smile:

1 Like

I use the companion app. I make sure that battery optimization is off on HA, chrome, and maps, I also ensure location is on high tracking all the time. It’s only one phone that’s consistently an issue, but of the 4, all experience issues here and there.

It’s only been a massive issue in the last month or so, but it’s always been somewhat of an issue.

Thanks, they used to be mostly bulletproof, but up until this past month, they’re absolutely awful.

I have also tried many solutions for presence detection, as most of us a mixture of gps and bluetooth detection. GPS is often a bit slow (without high accuracy mode about 1-3 minutes) and maybe unreliable on some phones. Bluetooth is really fast, but in my case it wasn’t continous, even with the phone 1M away from the esp32 there were drops in recognition.
Since two or 3 months i am using WLAN as a device tracker for beeing home or not.
This idea isn’t really new, all of us tried this with an nmap, ping or a router device tracker. The problem is, that every phone will disable wlan to save battery when not used. So these trackers will show you as not_home every time the phone saves battery.
But if you use the wlan sensor of the companion app, it does not recognize the phone is disconnected from the wlan. For the companion app you are connected all the time, it is really fast when you come to home (most of the time it switches when i enter my appartement door with locked phone in my pocket) and if you leave it’s about 20-30 seconds, the bluetooth solutions wasn’t faster for me.
Give it a try, make a simple template sensor (in my case a binary_sensor):

  - platform: template
    sensors:
      sm_mike_wlan_tracker:
        value_template: "{{ is_state('sensor.sm_mike_wifi_connection', 'MadNet') or is_state('sensor.sm_mike_wifi_connection', 'MadNet 5GHz') }}"
        delay_off:
          seconds: 3
        friendly_name: "Smartphone Mike Wlan Device Tracker"

Don’t forget to enable the sensor in the app! If you need a device_tracker you could use the composite device tracker component.
We are using it on a samsung s21 and s10, and for us it is really bulletproof :wink:

I use a mixture of this:

a nmap ping tracker
android companion app tracker (gps).
I also have it setup that it will turn on high accuracy when entering a wide zone so it’ll react quicker.
I also have a trigger set that when I open my garage, it issues a one-time immediate update for all trackers (wife, mine, kids).

This all works pretty well.

@madface that may be a better alternative than nmap pings. Not sure. I’ll have to try it.

Speed isn’t really the issue. The device_tracker will show my wife (pixel 5) leaves and then just gets stuck in a location never updating again. The geocoded location is always 100% on the mark (unless it’s listed as unknown), but frequent updates work well.

Once she returns home, everything updates again like normal.

I’ve considered just creating a NR flow to leverage geocoded location instead, but the problem I have is that if the sensor goes to sleep and stops reporting high accuracy, it could list the neighbor’s house instead and show her device not at home. In the logs, the phones never report an alternate location (I also increased polling rate to once per minute when charging).

I’ve gone the ping route in the past when this problem first occurred a few years ago, but it got better so I disabled it. Was not my favorite implementation, especially since the app was so much faster when it connected.

Additionally, my asuswrt integration tracks home and not home, so I could leverage when it communicates with the router instead, but that one seems to be slower to pick up devices. Also my kids Samsung (A42s) and my Pixel 6 never really experience this issue. It happens periodically, but it’s more rare than hers.

I have a pixel 4 and no issues. I do suggest you get logs to look at. That way you can tell what’s happening.

2 Likes

did you make sure to check the each of the steps in the link above to make sure location tracking setup is properly? If so did you continue reading those same steps to look at the logs?

Yes on the steps; however, I have not reviewed the most recent logs in detail, mostly because I haven’t had the time. Seems like whatever I’m doing lately, I’m rushing.

I will hopefully have more time to do so today.

Not that it matters much without the logs, but I will say this - Google Maps location is always current and geocoded location is always current. I can also force a new location with a mock location changer app and most of the time the device_tracker updates. I had an issue the other night while testing and it flat refused to display the mock location and then the actual location.

what version of the app are you on?

2022.6.0-full

we need to see the logs to confirm if you are experiencing the issue where google randomly stops sending app updates and then later on will continue. Some users have it and others do not. The latest beta found on github detects when there is an unexpected gap and will restart the location service. This version is not available yet on the play store but can be installed from github.

I will work on that. My wife went out this morning and the location did not update, so I pulled logs when she returned, but there are only 127 lines of logs that span 2 minutes. I completely missed the issue.

Is there a way to increase the log size?

You’ll need to use another method like the app logcat reader which requires special USB permissions to look at historical logs.

Got it, thank you. Will obtain and configure and hopefully have some logs to provide.

Ok, I have some logs. Was able to pull data using the HA companion app logs, as well as logcat.

Is there something specific you need to see? Maybe only the LocBroadcastReceiver entries? I just want to make sure there’s nothing in the logs i need to scrub. Looks like only my coordinates are listed in the HA logs, but it’ll take me some time to scrub the logcat ones.

LocBroadcastReceiver should be enough, basically we depend on Google to send the app updates. You can see when that happens when you see a log entry for a location update received. If you stop seeing those occur then you are also experiencing that issue.

How frequent are updates supposed to occur? The HA update is much smaller because of the frequent overwrites. I pulled it and then another a couple minutes later, but it seems that I was a little premature on the 2nd HA log.

||Line 144: 08-07 09:13:13.916 30611 30611 D LocBroadcastReceiver: Received geofence update.|
|---|---|
||Line 146: 08-07 09:13:14.129 30611 30611 D LocBroadcastReceiver: Event sent to Home Assistant|
||Line 147: 08-07 09:13:14.131 30611 30611 D LocBroadcastReceiver: Last Location: |
||Line 148: 08-07 09:13:14.131 30611 30611 D LocBroadcastReceiver: Coords:(xx.8903019, -xxx.3004275)|
||Line 149: 08-07 09:13:14.131 30611 30611 D LocBroadcastReceiver: Accuracy: 9.669|
||Line 150: 08-07 09:13:14.131 30611 30611 D LocBroadcastReceiver: Bearing: 217.0|
||Line 151: 08-07 09:13:14.131 30611 30611 D LocBroadcastReceiver: Begin evaluating if location update should be skipped|
||Line 152: 08-07 09:13:14.131 30611 30611 D LocBroadcastReceiver: Received location that is 1131 milliseconds old, 1659888793000 compared to 1659888794131 with source fused|
||Line 154: 08-07 09:13:14.359 30611 30676 D LocBroadcastReceiver: Location update sent successfully|

This is from logcat:


[08-07 09:13:13.916 30611:30611 D/LocBroadcastReceiver] Received geofence update.
[08-07 09:13:14.129 30611:30611 D/LocBroadcastReceiver] Event sent to Home Assistant
[08-07 09:13:14.131 30611:30611 D/LocBroadcastReceiver] Last Location: 
Coords:(xx.8903019, -xxx.3004275)
Accuracy: 9.669
Bearing: 217.0
[08-07 09:13:14.131 30611:30611 D/LocBroadcastReceiver] Begin evaluating if location update should be skipped
[08-07 09:13:14.131 30611:30611 D/LocBroadcastReceiver] Received location that is 1131 milliseconds old, 1659888793000 compared to 1659888794131 with source fused
[08-07 09:13:14.359 30611:30676 D/LocBroadcastReceiver] Location update sent successfully
[08-07 09:19:10.847 30611:30611 D/LocBroadcastReceiver] Received geofence update.
[08-07 09:19:11.450 30611:30611 D/LocBroadcastReceiver] Event sent to Home Assistant
[08-07 09:19:11.451 30611:30611 D/LocBroadcastReceiver] Last Location: 
Coords:(xx.891012, -xxx.2943736)
Accuracy: 3.9
Bearing: 130.90874
[08-07 09:19:11.451 30611:30611 D/LocBroadcastReceiver] Begin evaluating if location update should be skipped
[08-07 09:19:11.451 30611:30611 D/LocBroadcastReceiver] Received location that is 816 milliseconds old, 1659889150635 compared to 1659889151451 with source fused
[08-07 09:19:11.783 30611:31470 D/LocBroadcastReceiver] Location update sent successfully

Also, as I write this, my wife went to the store. The geocoded location is perfectly accurate, but the device_tracker, as usual, has only moved ~100’ from our house. I won’t be able to pull anything until she gets home.