I’m having an issue getting accurate locations to report to HA from my android phone when my phone has Wifi Hotspot enabled.
I think turning on Wifi Hotspot is messing up Google’s Fused Location API by preventing it scanning wifi, so all the location updates are being discarded by the HA app for having rubbish accuracy (about 1500m, if I’m reading the logs right).
My issue is I always use Wifi Hotspot when I’m driving, which is when I want my location to be accurately updated!
I’m not a HA expert at all, but after reading the docs I’ve thought of a few possible solutions and wanted to run them past people to see which they think is best.
A) Set the app to enable High Accuracy mode when connected to my car’s bluetooth. Simple, but I don’t actually USE the bluetooth in my car so it’s another thing I’d have to turn on manually.
B) Include “single accurate location” in sensor updates. I don’t know if I fully understand how this works, but I think it would force a GPS location update every 15 minutes?
C) Create an automation in Home Assistant to ping my phone with ‘request_location_update’ every so often when it detects I am not connected to my home wifi.
D) Possibly do something with tasker to enable High Accuracy Location when my phone’s hotspot is on? Haven’t looked into this much.
I’d love to hear about other possible solutions too. Ideally looking for something that just works without interaction but doesn’t kill my battery life too much. Thanks!
When I’m traveling (more on this in a second) turn on high accuracy mode. Turn off when done
When high accuracy mode isn’t on I request a location update every 30 minutes.
For #2 I actually don’t caveat this to “not home”. I used to say “only when not in a zone” but then once in a while I would get stuck. My phone wouldn’t realize it had left the location ever until I forced an update. Once every 30 minutes seemed like a reasonable compromise for battery life and never getting stuck.
For #1, “traveling” took me quite a while to get right. But I don’t just use it for high accuracy mode, I also use it for ETA tracking and not just with cars (sometimes I bike, take transit or walk). Here’s a kind of overview of what I do, feel free to use what makes sense for you. I am traveling if:
State of the device_tracker is not_home
I am not on any wifi (for me, this means I am at a fixed location like 99% of the time)
The detected activity from my phone is not walking or stationary (exception: my expected travel mode is walking, then walking counts)
If the detected activity from my phone is unknown, then is my speed greater then 1.5 m/s (0.5 m/s if walking is my expected travel mode). FYI speed is an attribute of the device_tracker, its not a separate sensor.
The last one is kind of a bummer. I would much prefer to just rely on detected activity since I found its pretty accurate in any state besides unknown. But the problem is anytime it’s unsure what your travel mode is it goes to unknown (which happens a bunch) and unknown is utterly useless. It’s got hard-coded confidence levels and tells you nothing. There’s no way to tell if you’re between biking and driving, stationary and walking or anything else. It hides all that data from you for some reason.
dshokouhi and I tried to report an issue to google about it but didn’t really get traction. So falling back on speed was the best option I could think of.
One other thing, traveling is a template sensor in my config and it has delay_off: 00:02:00. So once those conditions are met it won’t go off unless they aren’t met for at least 2 minutes. This keeps it from flipping off everytime I hit a traffic light.
I think I understand it So you use an automation on your HA server to send a command_high_accuracy_mode notification to your phone whenever either your activity sensor or your speed indicates that you’re travelling? And you use the same automation to ping your phone with a request_location_update every 30 minutes when it detects you AREN’T travelling, just in case the background updates aren’t doing their job?
I like it! Complex but elegant and seems to fit all my requirements, so I may steal it One question, have you noticed a significant impact on battery life? I commute maybe two hours a day so it seems like a lot of high accuracy mode. Do you keep the standard 5 second update interval or change it to something slower?
Oh and also, do you find this automation reacts quickly enough to change your state to ‘travelling’ using the default sensor update times?
Ah good point, I forgot I did this. I changed it to 30 seconds.
It’s a little hard to say. My phone is kind of old at this point (pixel 3) and multiple Massachusetts winters have done a number on its battery. I haven’t noticed it being significantly worse since I set this up but I’m not sure if that’s convincing given my battery wasn’t great to begin with. I guess I’d suggest trying it and keep an eye on it, adjust as necessary.
Oh definitely, it’s very fast. The detected activity sensor is actually really good at its job minus the unknown stuff. Take a look at its history sometime after you’ve been traveling and doing stuff for a day, I’ve found its quite accurate.
For reference, it’s actually not an automation though. It’s just a trigger template binary sensor. Trigger template entities share a lot of similarities with automations but they’re nice since you don’t need a separate boolean helper. The triggers set the state of the entity and then you can use that info anywhere else in HA. That also lets you use delay_off which is key since it keeps it from flipping on and off from brief stoppages without a ton of extra automation code.
Speaking of delay_off one other thing I forgot. My sensor actually has this for delay_off:
delay_off: >-
00:0{{ '2' if is_state('person.mike', 'not_home')
and is_state('binary_sensor.mike_on_wifi', 'off') else '0:10' }}
This way #1 and #2 in my list above turn off traveling almost immediately (10 second delay) but #3 and #4 wait 2 minutes. Since reaching a zone or wifi is basically guaranteed not traveling anymore except in rare cases where I drive right by a zone. Whereas speed going to 0 is less certain, it could go right back up again.
Why would this need to be done manually?
Do you always turn off Bluetooth on the phone? Or does it not connect automatically?
I don’t use my phone generally either in the car but it connects automatically and HA turns on high accuracy when I start the car. And it turns off a few minutes after leaving the car.
Not sure why I have this delay now, it used to switch off more or less on the minute.
Yea there’s been a lot of improvements to make Bluetooth more battery friendly. If your concern with leaving it on is battery life I’d take another look as per hellis’s suggestion.
The only thing to watch out for with this (and the reason I don’t use it personally) is not all cars can connect to more then one device at a time. In my car when my partners phone is connected for music then mine isn’t and so my automation doesn’t trigger. This plus the non-car transit modes made me switch to something not reliant on that.
But if that works for you then it probably is easier. Just figure out your cars Mac address and have your automation trigger off the connected devices sensor. It lists the Mac addresses of all currently connected paired devices as an attribute. Can trigger to turn on when the Mac address enters the list and trigger to turn off when it exits.
EDIT: Side note, the other benefit of the bluetooth disconnect event is you an use it as a parking spot tracker. Unrelated task but since we’re on the topic I have an automation that calls device_tracker.see when my phone’s bluetooth disconnects from my car with my phone’s current location. It’s not totally reliable since my partner’s phone may have been the one connected but if you forgot where you parked it can help you find it sometimes.
Let’s face it, if “easier” was our biggest concern we probably wouldn’t be here I do like your idea of combining data into a “travelling” variable, it seems like having that could be handy for multiple automations.
As for the bluetooth option, I’ll give it a try and see. I believe the app already supports entering high accuracy mode on bluetooth connect without me needing to use a sensor to trigger an automation too.
That’s pretty cool about the car tracker too, I never thought of that. I’ll have to look into how to set it up, if you have any links that’d be great.