openhab / openhab-android

openHAB client for Android
https://play.google.com/store/apps/details?id=org.openhab.habdroid
Eclipse Public License 2.0
591 stars 318 forks source link

Integrate Geofence-based Presence #343

Open jjhuff opened 6 years ago

jjhuff commented 6 years ago

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.

mueller-ma commented 6 years ago

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

jjhuff commented 6 years ago

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.

mueller-ma commented 6 years ago

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

digitaldan commented 6 years ago

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.

jjhuff commented 6 years ago

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

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

mueller-ma commented 6 years ago

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

digitaldan commented 6 years ago

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".

jjhuff commented 6 years ago

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 notifications@github.com 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 .

mueller-ma commented 6 years ago

@jjhuff Does this rely on Google Maps?

jjhuff commented 6 years ago

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

On Sat, Aug 26, 2017, 09:36 mueller-ma notifications@github.com 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 .

mueller-ma commented 6 years ago

Ok, please keep a option for users without GMaps

jjhuff commented 6 years ago

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 notifications@github.com 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 .

mueller-ma commented 6 years ago

Well, I hope #30 will be fixed anytime

jimtng commented 6 months ago

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.

mueller-ma commented 6 months ago

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.

jimtng commented 6 months ago

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?

mueller-ma commented 6 months ago

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.