Geofencing via OH Android and iOS app?

For presence detection, I now rely on tado, but if they shut down their API calls, that might become a problem.

Is it possible to integrate presence detection in the native openHAB Android and iOS apps? There are a lot of apps which detect location on the background (like e.g. the tado app). The local openHAB server could then do some ‘this is close enough’ calculation.

Edit: probably a lot safer would be that the app does that calculation, and passes a boolean to the server.

Or is there a reason that’s impossible?

Not an answer to your question, but, depending on your need, you might be able to use the Network binding to check when certain devices are connected to the Wi-Fi, if that’s all the “presence” you need.

When it comes to apps and location permissions, I personally uninstall anything that asks for it, so if that is ever added, I hope you can make it so that it doesn’t request the permission until some function has been enabled.

Do you mean that you uninstall apps, instead of denying the permission?

I think I did that in the beginning. But my girlfriend has an iPhone, and I believe they disconnect from the wifi after some time, as an energy saving method. So that was unusuable. If I recall correctly…

Yes, unless it’s a navigation/map app, I consider it “none of their business”, and I simply don’t trust or want anything to do with those that do.

Yes, I don’t know what the need is, I was just thinking that it might be an easy way to handle it. There is a “special iOS wakeup function” in the binding that is supposed to wake them up/reconnect them to Wi-Fi before pinging them. I don’t know what that does for their battery consumption though.

Aha, I’ll have to take a closer look then.

This behavior of iPhone is a security option to prevent tracking. iPhone changes the mac-address after some time. You may switch off this behavior in the settings of iPhone.

I have found that even with the iOS wakeup function and the MAC tracking properly set, the Network binding presence detection is reliable for turning presence ON, but not for turning it OFF, as only after an extended period do you know if it is really gone rather than asleep.

I use the Owntracks iOS app with the GPS binding, supplemented by the location from the iCloud binding. The latter is limited by the need to not poll more frequently than every 5 minutes, although I have found that you can infrequently manually request an update by sending REFRESH to an iCloud devices Location Item/channel. For example, when motion is detected while the overall presence is OFF, a rule sends the REFRESH command (you actually have to send it twice, 20 seconds apart - the first REFRESH gives you what is already in the cloud; the second gets updated data). Of course you then have to use the location to determine if the device is close to the desired location.

The network binding has recently gotten a lot of bugfixes, and I’m not even sure if those are released yet. I assume that you haven’t tested this on a snapshot build of OH?

As far as I can remember, you can configure the time a device needs to be unreachable to be considered “gone”, and how often to poll. Of course, if you want OH to “know” that somebody left within 30 seconds, you’ll have to have very short intervals.

Just FYI - Theengs Gateway does allow for local Bluetooth Home/Away presence detection, for static MAC address Android phones, and also for randomly changing Bluetooth MAC addresses on iPhone, iPad, Apple Watch and AirPods through random MAC address resolving with known Identity Resolving Keys.

I use my Apple Watch with the added security of an Unlocked property to set/disable the alarm system whenever I leave the house or come home.

I’m running OH 5.0.1 and have not studied the Network binding behavior recently. My comments are based on my experience with it over many years.

This is correct. Knowing 30 minutes later didn’t work for me. The tools I’m using let me know within a minute.

I’m not fully convinced by the Network binding. Sometimes my mobile phone is off, or I’m not connected to the WiFi.

I realize the term I was looking for was “geofencing”, not “presence” or “location detection”. That lead me to this topic: Google home geofence example.

I hope that’ll do the trick for me. :slight_smile:

This depends on the polling interval, regardless of what way you acquire the information, unless you have something “event based” that will notify OH when something changes. That would probably be possible using OH’s mobile apps.

It all depends on your need, the Network binding can only tell you “is or isn’t on Wi-Fi” of course. Whether that suffices, depends entirely on what you want to use the information for. Personally, I would never leave the GPS enabled on mobile devices anyway, I only enable it if I actually need it, so to me, it would never be an option to use GPS information anyway. I’m actually very happy that I don’t have a GPS device attached to myself :wink:

Also, if your mobile device isn’t on Wi-Fi, you can’t get the GPS coordinates from it unless you want to subscribe to some “cloud” service that will track your ever move, and then pay for mobile data for it to keep uploading the information. OH must then pull it from this service. So, unless you want to throw all privacy completely out the window, the device needs to be on Wi-Fi anyway.

I found your topic because I was thinking the same and searching for a solution :slight_smile:

I just tried it with the GPSTracker Binding and the OwnTracks app and that works. I can get the location coordinates from the OwnTracks app via the Binding in an Item.

Note: I’m already using standalone OwnTracks on a Raspi for quite a while and sending my location via MQTT to my local OwnTracks server via a always-on VPN connection to my home LAN. From there I also use the location in openHAB. That’s why I don’t need the openHAB cloud + GPSTracker Binding for my personal Android phone.

But as almost everywhere there are family members with iPhones :slight_smile: And they are not connected via VPN to my LAN when outside. For them the openHAB cloud + GPS Tracker Binding + OwnTracks app is a promising option.

If the item with the location changes its state, you can do a distance calculation to your home coordinates and depending on the distance you can enable/disable whatever stuff you want.

No Google or other cloud service besides openHAB itself is involved.

I’m using this JavaScript to calculate the distance:

/**
 * Calculate the distance between two points on Earth
 * @param {number} lat1 Latitude of point 1
 * @param {number} lon1 Longitude of point 1
 * @param {number} lat2 Latitude of point 2
 * @param {number} lon2 Longitude of point 2
 * @returns {number} The distance between the two points in meters
 */
const calculateDistance = function (lat1, lon1, lat2, lon2) {
  const earthRadius = 6371e3; // metres
  const deg2rad = (deg) => deg * (Math.PI / 180);
  const dLat = deg2rad(lat2 - lat1);
  const dLon = deg2rad(lon2 - lon1);
  const lat1R = deg2rad(lat1);
  const lat2R = deg2rad(lat2);
  const a =
    Math.sin(dLat / 2) * Math.sin(dLat / 2) +
    Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1R) * Math.cos(lat2R);
  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  return Math.round(earthRadius * c * 1000) / 1000;
};
1 Like

I was indeed able to create a ‘Routine’ (in the Google Home lingo), which triggered when I left ‘home’. I could even set the radius. My tests were looking good.

But there was an annoying notification, which I was unable to switch off, due to ‘privacy’ reasons. I then switched off notifications from that app entirely (via Android settings). I think it was the ‘Google Assistant’ app; it had that symbol of three balls or what is it.

But after a few days, I noticed the ‘Routine’ didn’t work anymore. I checked, and saw that the trigger ‘leaving home’ is no longer available. I removed both the Home and the Assistant apps and re-installed them, I granted both rights to location and notifications (although the Assistant app claims not to send notifications).

No luck… There does seem to be a general ‘Home’ or ‘Away’ setting, but I want different things to happen with different residents. Where did that location trigger go… Does anyone have insight in how Google Home works? Maybe @LeeC77?

(I also opened a question on that terrible Google ‘help’ platform, but that’s worthless, sadly…)

I’m using the network binding, but with two important things:

  1. deactivate the “change MAC” in the devices. Both iPhone and Android in newer OS versions allow that to be set not globally, but for specific WiFis. I do that, because I’ve got a white list of devices and don’t allow unknown devices use my WiFi.
  2. play around a bit with the setting in the network binding. It depends on router type and configuration which will work best for you.

For me 5mins of inactivity are enough for my “empty house” use case. all other “more direct” presence detectors rely too much on battery hungry tech… :wink:

2 Likes

Not sure I fully folllow your question? You have to install Google Home (if not part of the stock install) and enable the openHAB Google Assistant Action on each Andriod Phone you want to track. This will mean that each Android phone/Google Home will see all the openHAB switches you created and tagged. Just delete, in Google Home, the ones you don’t want and then move the ones you do to the correct address/’Home’ you set up in Google Home. See privous post.

I now realize I forgot to update here. I ended up contacting Google’s help. They told me that (very) recently, location based ‘starters’ are no longer possible. So I abandoned the Google Home route. I went with OwnTracks instead.

Unfortunately, but not at all unexpectedly, the iPhone doesn’t play nice with the OwnTracks app. Sometimes the misses leaves/arrives, but a location update isn’t received until 10 minutes later. I suspect the ‘Low Power Mode’ (or how is it called) interferes with the app. I hope the iCloud binding does better (but I’m a bit lost on how to add the phone as thing).

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.