openhab-android icon indicating copy to clipboard operation
openhab-android copied to clipboard

Integrate Geofence-based Presence

Open jjhuff opened this issue 8 years ago • 18 comments

I'm in the process of migrating from SmartThings, and I'm missing how easy geofence-based presence detection was on ST. With OH2, I need to setup MQTT, secure it, expose it to the 'net, AND all my family's devices need to have another app installed and configured.

This seems like ideal functionality to just integrate into the Android (and iOS) app.

I'm thinking something like:

  1. A setting to enable it (prompt for location permission at that point)
  2. Select an item to control
  3. Pick a location and radius (unless we can get that from the server?)
  4. Setup the geofence using Android's geofencing (better battery life -- we don't need to completely track the user!)
  5. Use the REST API to update the item when entering/exiting

I'm happy to do the work, but I wanted to discuss the approach, design, concerns before diving in.

jjhuff avatar Aug 16 '17 20:08 jjhuff

MQTT, secure it, expose it to the 'net, AND all my family's devices need to have another app installed and configured.

I wouldnt know how to do this without exposing some interface to the internet. You will need at least openhab or openhab cloud companion to connect to.

unless we can get that from the server?

Technicaly you could use homekit tags in some way. See comment of @digitaldan https://github.com/openhab/openhab.android/issues/334#issuecomment-316101305 Suggestion: tags named "hostname-isInRadius1" or "wifiMac-isInRadius1" or similar uniq information.

Use the REST API to update the item when entering/exiting The easiest solution would be to have a simple switch which is on, when a person is inside the radius. Maybe you can also transmit a timestamp for entered/exited and last update.

Also have a look at #269 which is quite similar

mueller-ma avatar Aug 17 '17 10:08 mueller-ma

I wouldnt know how to do this without exposing some interface to the internet. You will need at least openhab or openhab cloud companion to connect to. Yup, but fewer is better. If one was only concerned about local usage, the network plugin with an expiration could be an option. I could also see potential of a more limited 'presence' channel offered by openhabcloud.

Technicaly you could use homekit tags in some way. See comment of @digitaldan #334 (comment) Suggestion: tags named "hostname-isInRadius1" or "wifiMac-isInRadius1" or similar uniq information. I'm not sure what you're thinking here, but I don't know much about HomeKit or it's OH integration

Also have a look at #269 which is quite similar Ahh, yes it does!

I'll see what I can put together.

jjhuff avatar Aug 17 '17 16:08 jjhuff

We should get some thoughts of @digitaldan about this feature in generell and from @kaikreuzer about homekit tags usage in clients

mueller-ma avatar Aug 17 '17 18:08 mueller-ma

Geo tagging would be a great feature for sure.

Select an item to control

Use the REST API to update the item when entering/exiting

The easiest solution would be to have a simple switch which is on, when a person is inside the

I agree this would be a simple solution and best for battery life. I also like that it would be easy to duplicate on IOS and does not require any special configuration.

digitaldan avatar Aug 17 '17 19:08 digitaldan

Ok great. I should have a basic PoC working shortly.

Thoughts on how to get the home location (and radius) from the server?

jjhuff avatar Aug 17 '17 20:08 jjhuff

Would be great if you could implement this in a way that makes it easy to send other stuff to oh

mueller-ma avatar Aug 17 '17 20:08 mueller-ma

thoughts on how to get the home location (and radius) from the server?

I would keep this very simple and just associate entering/exiting a geofence with an existing switch in OH. The user can then decide if that switch is "home".

digitaldan avatar Aug 26 '17 15:08 digitaldan

Yup, that's exactly what I have implemented -- working great! As it is, the center and radius is defined in app preferences. That's certainly workable, but starts to become a pain as the number of users grows.

On Sat, Aug 26, 2017, 08:53 Dan Cunningham [email protected] wrote:

thoughts on how to get the home location (and radius) from the server?

I would keep this very simple and just associate entering/exiting a geofence with an existing switch in OH. The user can then decide if that switch is "home".

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/openhab/openhab.android/issues/343#issuecomment-325140532, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZqxBESNQUwGhaLjQqP6FI4Wn7n8huks5scD9zgaJpZM4O5d4P .

jjhuff avatar Aug 26 '17 15:08 jjhuff

@jjhuff Does this rely on Google Maps?

mueller-ma avatar Aug 26 '17 16:08 mueller-ma

As of now, no. Just lat/lng fields. Super user friendly!

On Sat, Aug 26, 2017, 09:36 mueller-ma [email protected] wrote:

@jjhuff https://github.com/jjhuff Does this rely on Google Maps?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/openhab/openhab.android/issues/343#issuecomment-325144681, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZq7OnrImGGda7EZIY3ffS0ttF8naWks5scEl6gaJpZM4O5d4P .

jjhuff avatar Aug 26 '17 16:08 jjhuff

Ok, please keep a option for users without GMaps

mueller-ma avatar Aug 26 '17 16:08 mueller-ma

On Android or desktop? It does depend on Google play services, but I think that was already a dependency.

On Sat, Aug 26, 2017, 09:41 mueller-ma [email protected] wrote:

Ok, please a option for users without GMaps

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openhab/openhab.android/issues/343#issuecomment-325145215, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAZqydntklGUhD2PiiTZ-HL0xcBHlUgks5scEq0gaJpZM4O5d4P .

jjhuff avatar Aug 26 '17 16:08 jjhuff

Well, I hope #30 will be fixed anytime

mueller-ma avatar Aug 26 '17 17:08 mueller-ma

How about the mobile devices (android, ios) simply sends its lat/long coordinates? This can be disabled by the app, and the interval can be customised. It'd be much like the current reporting of wifi ssid, BT, etc.

The geofencing is up to the rule writers. This way it can check device's proximity against a list of locations, e.g. "home", "school", "local shops", "post office", etc. It's way easier to configure this in the rules.

jimtng avatar Jan 07 '24 12:01 jimtng

The reason I didn't implement it this way is that getting GPS coordinates requires some error handling. Getting the wifi ssid for example always succeeds, but GPS may fail.

mueller-ma avatar Jan 07 '24 19:01 mueller-ma

The reason I didn't implement it this way is that getting GPS coordinates requires some error handling. Getting the wifi ssid for example always succeeds, but GPS may fail.

Could you provide some links/pointers on this? I'm unfamiliar with android development in general. Would it be possible to send it when it can and just log the errors when it couldn't? Is it a matter of permissions?

jimtng avatar Jan 09 '24 00:01 jimtng

You can look at the commit https://github.com/openhab/openhab-android/commit/264682e8e19be163e4bc2baa2f1bd1e61db039af. Sending GPS coordinates is mostly the same, except for getting the value to send.

There's probably no Android event when the coordinates change, like there is for bluetooth connects. So you can ignore everything related to ACL_CONNECTED in the commit.

mueller-ma avatar Jan 09 '24 16:01 mueller-ma