Openhab android client gps coordinates

Hi,
Was wondering why do we have to use 3rd party apps such as GPS Logger or Owntracks to upload location to openhab cloud via mqtt, shouldn’t it be fairly simple for openhab android client to grab current coordinates from the Android OS that it’s running on?

That client has such a beautiful working features like grabbing current call state (which I use to mute any music in the apartment while receiving a phone call), grabbing alarm time…so I’m sure we can just grab the coordinates and write them to some item, in the same way as alarms, calls etc…or??

edit: I use gadgetbridge (open source smart watch companion app) and I noticed OH client has integration to that!!! it offers me to send some info of the watch to OH server. amazing! I feel our OH client is powerful enough to handle gps geotagging on its own…

1 Like

I can see three reasons that can be the answer to all “why isn’t this implemented” questions.

  1. It is not in fact as easy to implement as you think it might be in a way that meets other priorities of the Android app (battery usage, permissions, complexity of the code base, usability, etc.).

  2. No one has volunteered to implement it. There are currently 56 open issues on the Android app, the majority of which are bugs. Given there is a complete and robust solution for geotraking available, implementing something like this is deemed to not be a priority by any of the volunteers.

  3. It’s already there, you just don’t know about it.

According to a number of comments from the main developer (e.g. Suggestion: allow the app to send the cell ID to get rough location · Issue #2290 · openhab/openhab-android · GitHub) it would appear that 2 is the answer for this one.

clear…regarding battery usage, it would be up to the user to enable this option, I mean it doesnt affect the overall battery drain…most users probably do not enable all these options anyway (report battery percentage, report alarms, report wifi name etc…)

I am not an android developer, but couldn’t you just fetch last known location (that is already written in some file)? lets say you have weather apps etc that keep asking for location, then other apps can just passively take the last known coordinates, not actually request location update.
But that would probably be useless for geofencing as you need frequent updates…

It’s mostly “nobody has implemented it yet”.

There’s a feature request for geofencing: Integrate Geofence-based Presence · Issue #343 · openhab/openhab-android · GitHub
This can be done with a Google Play library which should be more efficient than sending the GPS location to the server.

Depending on your use case you might want to have a look at sending the Wi-Fi SSID.

I meant to mention this too. I use this personally and find it way more timely than anything based on GPS actually, even when I have Maps or Waze open.

Depending on what you are after, there are other approaches you can use too. For example, using something like Tasker and AutoLocation you can set up geofences and a task to update an Item. Rather than reporting actual GPS locations all the time, you can just report location (e.g. home, work, grocery store, etc.). With that you can use cell towers and wifi SSID to drive the location too which is pretty low battery impact as well.

There are lots of ways to achieve geolocation based automation that do not require constantly pushing GPS coordinates to the openHAB server.

I don’t use google services, I use fdroid version of OH…so anyway if that was implemented, I wouldn’t have use of it :slight_smile:

I don’t actually have a use case…i would try to play with it, i have a specific scenario where i spend a lot of time in common areas around the house like kids parks beach etc…so wouldnt want to trigger any rules by being 500meters from the house…I guess you can specify to ignore some ring around the house…

GPS really isn’t going to be accurate enough to track you as you move through your house. Commercial grade GPS is between 3 and 10 meters. If you want to track location around your house you’d want to use something like FIND3 (available for install through openHABian).

This never occurred to me, but makes so much sense.

I dont need tracking in the house, for that i use wifi openwrt script that updates oh server.
I was actually thinking of having a rule fire AC when I’m approaching the apartment, but not fire it if I am in the area of 500m around lets say.
I am not even sure how to accomplish that, maybe I would have it check if phone is on car bluetooth and fire rules only then on approach 2000meters or something…and have it ignore geofence alltogether if i am just walking around. Dont know what are the best practices and how people solve this :slight_smile:
Lets say you want to switch on heating/cooling when you are on your way from work to home, but you dont want anything to fire when you are on your way back from the grocery store on foot, and you happen to run into a neighbour and decide to have a beer in proximity of your house

Hehe, i just mimic car entertainment system behaviour when you have a call.
And of course, unmute when the call is completed :slight_smile:

I tried this with Tasker, but also found that GPS is not accurate/responsive enough for automation to work consistently. Perhaps more importantly, my behaviour isn’t routine enough to create reliable triggers that work 99% of the time.

Since I can’t reliably automate, I just made it possible to manually trigger some tasks with my phone. Specifically, I can unlock my door by pressing a key on my phone using SideActions (for Samsung Galaxy devices), Tasker, and the openHAB app.

I guess I am the same, don’t think I will be able to automate this one…anyway, I just manually start AC in OH android client when I’m leaving work :slight_smile:

What I have found GPS accurate and timely enough for is to raise a dialog on the phone asking if I want to open the garage. I have a geofence set up around the house and then some using AutoLocation. Then from Tasker if I’m driving and enter the geofence Tasker pops up a dialog asking if I want to open the garage. Sometimes it pops up when I get to the stop sign at the corner of the road, other times it doesn’t pop up until I pull into my driveway, but only if I have the map up. Otherwise the updates to the GPS coordinates is so slow that it almost never pops up the dialog on time.

@rlkoshak I have a friend that has a camera in the driveway that reads the carsign and open the garage door if it recognize the car. I think he closes the garage door manually. That solution seems more bulletproof than GPS…

I don’t have a camera pointing at the drive way nor do I have a way to power one if I wanted one, which I don’t really. And I don’t necessarily want the garage door to go up every time I’m parked in front of it. The way I use it, the GPS is good enough. Rarely does it ever miss. I also like to have a man in the loop to confirm the action when it comes to operating heavy equipment like a double wide garage door opener.

With tasker it is possible to read system logs of OwnTracks and I have the Logcat feature look for the following:
Component:
LocationProcessor
Filter
“RegionName” transition:(enter/exit)

Example while at the work region I have tasker flip OwnTracks to the pause mode, when the work region is "exit"ed then flip back to significant change, when I enter the region called close to home it flips to Move mode and 95% of the time triggers the garage to open and flip on some lights.
Add some additional triggers like a car bluetooth to prevent something like a bike ride from triggering the automation as an example.