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

I have so many issues with presence, primarily the device_tracker. I have several things automated in my house that depend on presence and when it shows home when we’re not (or vice versa), it makes me freaking crazy. Oftentimes, it’s reporting presence sensors are home when in fact, they’re away, so things dont secure or run like they’re supposed to.

So, I found how I can force an update and that’s with a location changer app. I know the app just reads sensor states, but I wonder if it’s possible to trigger an app in HA or NR when the device_tracker fails to update. I use the geocoded location too, and it’s almost always accurate (except when it’s unknown), so I could use a NR flow to compare the device_tracker and the geocoded location to validate, but triggering the app seems invasive.

Thoughts?

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.