home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.35k stars 656 forks source link

WearOS Location Sensor #3029

Open janstadt opened 2 years ago

janstadt commented 2 years ago

Is your feature request related to a problem? Please describe. No.

Describe the solution you'd like Provide sensors for gps/location for wearOS. Im particularly interested in getting it added for the galaxy 4 LTE devices.

Describe alternatives you've considered, if any N/A

Additional context

dshokouhi commented 2 years ago

So for this we definitely need sensor setting support added in the UI so users can adjust the accuracy because I am sure whatever default we decide on will not be good enough for everyone.

At what update intervals are you expecting? I don't think the values from the phone side make sense here because updates every minute will not be good for a wearable battery.

I also wonder how doze will impact this as we cannot turn off battery optimisations on the wearable.

janstadt commented 2 years ago

Id say 30 minutes or 1 hour would be sufficient. Maybe if optimization is turned on you could switch to 1 hour if the user has it set for 30? I know very little about android wear so i am open to all options.

dshokouhi commented 2 years ago

Maybe if optimization is turned on you could switch to 1 hour if the user has it set for 30? I know very little about android wear so i am open to all options.

Google has blocked the ability for apps to request to ignore battery optimizations on Wear OS so that won't be possible. Good to know that 30 min to 1 hour for the update interval will work for you. Lets see what others think on this too.

janstadt commented 2 years ago

Maybe if optimization is turned on you could switch to 1 hour if the user has it set for 30? I know very little about android wear so i am open to all options.

Google has blocked the ability for apps to request to ignore battery optimizations on Wear OS so that won't be possible. Good to know that 30 min to 1 hour for the update interval will work for you. Lets see what others think on this too.

I mean, it all depends on how the battery (which is truly terrible) handles a background service pinging HA. I'd love it to be less, but i know these things are heavily dependent on the hardware running wearOS/HA. If its possible to like disable ALL sensors except location once enabled and the battery can make it close to a day with more frequent pings, that'd be awesome.

dshokouhi commented 2 years ago

my point about battery optimizations is that while we may request 30 min or 1 hour we may be subject to doze which means the update will not get sent until some time after the interval or when the device screen comes on. There is no way around that.

Sensor updates like battery are separate from location updates too, the current schedule is fine so we don't need to touch that.

kevin-david commented 1 year ago

It's unfortunate there's no way to disable battery optimization. I was hoping I could write something to (with a time limit, think Glympse app) do "live" location tracking from the watch without being connected to the phone over LTE, given I can't find an app that exists yet.

TheFes commented 1 year ago

I'd like to have a working device_tracker for my watch as well. I have an LTE version, and will sometimes be leaving my phone home. I'd still like my location to be updated then.

seanmccabe commented 1 year ago

I'd like to have a working device_tracker for my watch as well. I have an LTE version, and will sometimes be leaving my phone home. I'd still like my location to be updated then.

Same, I'm on LTE, and was hoping with HA it would have my watch location, so even if I leave my phone home, I will be away due to the watch and can run various automations despite one device being home.

Will the location be updated say if another app updates it? Often I'm just out walking the dog, as such the Health app updates the location to track the route, can HA use this info and send on change?

dshokouhi commented 1 year ago

Will the location be updated say if another app updates it?

Yup those are considered "passive" updates we can receive those at the interval we will define, the phone app will receive passive updates every 30 seconds like when you have google maps open. Behavior wise it should be similar to the phone app with probably the exception of less frequent updates to preserve battery life. If we stick to the defaults on the phone side battery will not last as long on a wearable.

seanmccabe commented 1 year ago

I do expect it to work like the phone (since the app should work standalone), so perhaps configurable interval. Maybe times we want a more frequent update, despite the drain.

Alternative perhaps is only send update when position has changed by x meters? I used to have GPSLogger set like that, so it wasn't sending so many frequent updates and would get passive updates from Samsung Health tracking the route. I would set to 100m+ before sending an update.

seanmccabe commented 1 year ago

8 months on, just wondering if there is any progress on this?

I take my watch out without my phone so often and the companion app is great, but still have to fire so many automations manually because HA isn't seeing the watch as away, despite HA seeming to expect location data.

jegres1709 commented 1 year ago

I have also some usecases for this feature( e.g. nuki lock) It would be pretty cool to have location data delivered by the watch.

seanmccabe commented 11 months ago

@dshokouhi I notice the "yet" in the linked closed issue.

Is location tracking still planned given the app supports it and HA appears to be expecting it?

dshokouhi commented 11 months ago

Is location tracking still planned given the app supports it and HA appears to be expecting it?

I wouldnt say planned but I guess you can say "accepted? nobody I know of has started to work on this. Also its not that HA is expecting anything its just that the mobile app integration automatically adds it to any device registered. The entity is just awaiting to show updates. In reality it should be hidden however that will require HA core changes first I believe.

dreimer1986 commented 9 months ago

Regarding the power usage and some people here maybe hoping to crank the interval up to way more than every 30 min... I had a lil... Wear App problem on my phone recently. I did not even notice that it was completely dead and did not even try to open at all anymore. (Samsung Watch variant in my case). This seemed to have resulted in some funny side effects. Bluetooth connection was unused and the watch connected to HA with LTE. Notifications still showed up from time to time, so I guess the connection to the phone was realized that way, too.

Small change, but my battery lasted only about 6-8 hours that way. And this was with WIFI off. Just by using LTE, a basic phone feature all the time. GPS is nice and good, but it will eat your battery for breakfast. Try to use Google Maps on the watch and you will realize that a battery percentage easily can decrease to 0 in less than 3 hours.

Of course I came up here because I don't like the unknown result in HA, too. But don't forget to be realistic here. This thingie is a watch, in my case it has a ultra small 350 mAh battery aka compared to my phone (4926 mAh) about 1/14 of the capacity.

30 min sounds like a good default value for me. If someone really has fun recharging the watch twice a day... make it selectable. With some luck the app even wakes up often enough for some higher interval. ^^

Hyug commented 2 months ago

Hello, what's up on that ?

brooksben11 commented 1 month ago

In my case at least, I honestly think passive GPS updates would suffice for the vast majority of cases (maybe all?). Outside of forgetting my phone (which I honestly don't know if I've ever actually done?), the only time I only have my watch is when going for a run, in which case I'm already using GPS continuously to track myself.

Guergeiro commented 1 month ago

In my case at least, I honestly think passive GPS updates would suffice for the vast majority of cases (maybe all?). Outside of forgetting my phone (which I honestly don't know if I've ever actually done?), the only time I only have my watch is when going for a run, in which case I'm already using GPS continuously to track myself.

I have this exact use case. Normally I run without my phone. I have a script that sends a Signal message to my family when I'm halfway the run in a specific route (hardcoded) which I trigger from my watch. I would like to send a message with my current coordinates, for example, when something happens would be nice to inform them. Atm, if something happens, they just go looking for me in this predefined route (which never happend, thankfully), but it constraints me a lot.

Tbh, I wouldn't mind an "on demand" request of position instead of passive updates every 30min because of battery. Or just allow the user to configure this value. I would most likely have it every 5min for my run and then just deactivate this when I'm not running.

yuejon commented 1 month ago

I agree. At least give us the option to enable or disable it rather than outright not letting us use the GPS.

dshokouhi commented 1 month ago

In my case at least, I honestly think passive GPS updates would suffice for the vast majority of cases (maybe all?). Outside of forgetting my phone (which I honestly don't know if I've ever actually done?), the only time I only have my watch is when going for a run, in which case I'm already using GPS continuously to track myself.

by default the watch will get location from the connected phone so once implemented it should be all passive whle its connected, the apps dont have control over this it seems

https://developer.android.com/training/wearables/apps/location-detection

When you request location data in a watch app, the system retrieves the location from either the phone or the watch using the most power-efficient method.

Or just allow the user to configure this value. I would most likely have it every 5min for my run and then just deactivate this when I'm not running.

Assuming existing code for high accuracy mode will just work on Wear OS this should work however it needs to be implemented and merged over and tested. Also you currently cannot access sensor settings on Wear OS directly so that will have a direct impact here.

I agree. At least give us the option to enable or disable it rather than outright not letting us use the GPS.

i dont understand the context of this statement. This request requires a lot of code changes and its not a simple switch to enable as you suggest. That is why its a feature request.

The ask earlier was what additional considerations we may need to think about while developing because we cant assume that the logic for the phone will be good for a watch.

Jorgel-90 commented 3 weeks ago

My son recently got a smartwatch. We chose a smartwatch so we can communicate with each other and we could check where he was. We did not chose a smartphone as this would be a thing he plays with all the time, a smartwatch is limited to some extend.

I chose a WearOS watch so I could install HA on it to track the location, only to find out now that it doesn't get GPS data on WearOS. Hopefully this feature will became available in the future!

dshokouhi commented 1 week ago

another update on this, geofencing is not recommended by Google due to power usage. This means a potential device tracker may not be usable for zone detection which begs to question how usable it will be at all now. Wifi is not kept on normally so that is not suitable either.

https://developer.android.com/develop/sensors-and-location/location/geofencing

Note: On Wear devices, the Geofencing APIs don't make efficient use of power. We don't recommend these APIs on Wear.

this combined with #3976 which I am sure will impact location updates is something to consider.

seanmccabe commented 1 week ago

I think we have all expressed here that as long as the location thing is optional (so those that don't want to use it don't have to) we are happy with the battery drain.

The battery drains with other apps using the location, all of which I'm sure the devs of these apps are aware of too, and all something we have experienced with these apps. At least if it's coming from HA its something we want.

dshokouhi commented 1 week ago

we are happy with the battery drain.

when this does get developed and the drain is determined for a watch to not last a full day we wont be adding this, now that we know Google called it out that means it can be very bad drain. They dont typically call these things out like that.

The battery drains with other apps using the location, all of which I'm sure the devs of these apps are aware of too

those apps are all foreground apps that use GPS, dont think there are any apps that keep a long running geofence call up on a watch

brooksben11 commented 1 week ago

I'm not a developer, so perhaps this is much more difficult than it seems. But is there no way to have the HA app be able to see when another app is actively using GPS and just pass that data along to HA on a regular/frequent basis like other sensors? And then when nothing else is actively using GPS, only ask for and then publish location data once every 30 minutes or hour? I suspect this would satisfy many/most folks (certainly me).

And then of course as with other sensors, make it an opt-in sensor so folks who don't want it experience none of the associated battery drain.

dshokouhi commented 1 week ago

But is there no way to have the HA app be able to see when another app is actively using GPS and just pass that data along to HA on a regular/frequent basis like other sensors?

thats what the phone app does and thats what Wear will do, making the code shareable here is the challenge and time consuming part. These are called passive updates and we get them every 30 seconds on the phone.

however thats fully dependent on other apps now imagine a severely delayed zone change, thats the issue we need to consider. Location tracking does you no good if zones dont change timely. Nobody will want a device tracker that updates the zone 30 min later.

brooksben11 commented 1 week ago

however thats fully dependent on other apps now imagine a severely delayed zone change

Can't speak for others, but my only real use-case is when I'm already using another app on the watch to actively track my location. The rest of the time, I'd still find a lot of value in my location being updated even only every hour versus not at all.

seanmccabe commented 1 week ago

we are happy with the battery drain.

when this does get developed and the drain is determined for a watch to not last a full day we wont be adding this, now that we know Google called it out that means it can be very bad drain. They dont typically call these things out like that.

Given the drain happens anyway with apps that track activity and location this seems a cop-out.

The battery drains with other apps using the location, all of which I'm sure the devs of these apps are aware of too

those apps are all foreground apps that use GPS, dont think there are any apps that keep a long running geofence call up on a watch

It doesn't need to be long term does it? And if it is entirely optional to the end user then it is on the end user to accept the battery drain. You offer the same thing on phone and warning regarding high frequency updates on location, unsure how this is any different?!

seanmccabe commented 1 week ago

But is there no way to have the HA app be able to see when another app is actively using GPS and just pass that data along to HA on a regular/frequent basis like other sensors?

thats what the phone app does and thats what Wear will do, making the code shareable here is the challenge and time consuming part. These are called passive updates and we get them every 30 seconds on the phone.

however thats fully dependent on other apps now imagine a severely delayed zone change, thats the issue we need to consider. Location tracking does you no good if zones dont change timely. Nobody will want a device tracker that updates the zone 30 min later.

I'm sure in an automation we could adjust this too. I would only really need location updates when the phone is disconnected from the phone (which seems to be the primary use case for most here). At which point some updates are better than none, and a configurable timeframe (same as the other sensors) makes sense for the end user. Given as well that many users are already using GPS apps when they disconnected from the phone (many the point for a smart watch) there will be location updates coming through. Just on the HA app to configure how often to send this back.