[RELEASE] Improved Mobile Presence (Android only)

Improved Mobile Presence

Status Uptime 30 Days Response Time 30 Days


This project allows presence detection at multiple locations (Work / Home / etc.) and syncs some other additional info like battery and power source so they can be used in automations. Updates are real time (usually under a second) and setup is pretty straight forward.


Setup Instructions

This is currently availible on Hubitat Package Manager. If using HPM then skip to step 5
If you need to add pair an additional device after already completing these instructions, see Step 5

Step 1: Install Presence Sensor Android app

Accept any prompts to ignore optimizations (If you do not do this the app will be blocked from communicating with the server so it will not work)

Get it on Google Play

If you are using Android 8.1 or above you need to install the patch AND the app from Google Play
To update to the most recent patch, you must uninstall the old patch first
Patch

Make sure you open the patch app or it will not work

Step 2: Copy app and driver from GitHub

  1. Copy the app and driver into the Apps Code and Drivers Code pages on Hubitat
  2. Make sure to enable OAuth using the OAuth button in the app code editor. You don't actually need to do anything with the info. Just make sure it's enabled.

Step 3: Install App

App should only have one instance in Hubitat otherwise it can cause issues with syncing.

  1. Select Add user app from the Apps tab
  2. Select Presence Sensor

Step 4: Install app

Do NOT install multiple copies of the app as it can cause problems when syncing data.

  1. Select Add User App from the Apps page on Hubitat
  2. Select Presence Sensor and then Save

Step 5: Pair devices

Make sure you saved the app in step 4. When the app is saved, is syncs authentication data. If you do not save first, you will get errors when pairing your phone.

  1. Open the Presence Sensor app in Hubitat
  2. Select New Device
  3. Enter a name and select either Pair this device or Pair another device.
  4. If you selected pair other device, scan the QR code with the Presence Sensor app on your phone. If you selected pair this device, the Presence Sensor app should open automatically. The device will be created in Hubitat automatically with either option.

Step 6: Create Locations in Presence Sensor app

  1. Open Presence Sensor app on your phone
  2. Click on a location to edit or click the add button to create a new one
    a. Name: Location name
    b. Home location: If checked, you will show as present when at this location
    c. Networks: Connecting to any of the checked networks will cause you to show that you are at this location

Everything should be working now

If you have any questions about this process or any other issues let me know.


Device Attributes

The device driver has the following attributes that can be used is custom automations.
a. currentLocation: The location where you currently are
b. previousLocation: The last location you were
c. presence: present if at a home location or not present if anywhere else
d. battery: Battery percentage of phone
e. powerSource: battery if not charging or dc if charging

How to setup locations in the app

  1. Locations have Wifi and Bluetooth triggers
  2. Triggers have the following options:
    a. Negative: Inverts the trigger (Ex. Wifi is not HomeWifi or Bluetooth device is not connected.)
    b. Requirement: If requirement is checked, the trigger is required for location to be active but does not place you in that location by its self.
  3. Power source changes now update in real time (patch update required).

A few examples:

Wifi is HomeWifi
Wifi is HomeWifi5
Bluetooth is SmartWatch (requirement)

Scenario 1 (At home):

Wifi is HomeWifi - false / ignored
Wifi is HomeWifi5 - true
Bluetooth is SmartWatch (requirement) - true / ignored
Result : Present

Scenario 2 (Out running, left phone at home and wearing watch):

Wifi is HomeWifi - false / ignored
Wifi is HomeWifi5 - true
Bluetooth is SmartWatch (requirement) - false
Result : Not Present


Download Links

If you are using Android 8.1 or above, you need to install the Presence Sensor app and the Patch

Presence Sensor App
Get it on Google Play

FAQ

  • Are you running servers to support the functionality of this app?
    • Yes but no personally identifiable information is ever sent to or accessible by the server. No past events are logged or stored. That is communicated to the server is:
      • Device ID (you can see this in the app settings)
      • Name of current location (Wi-Fi / Bluetooth data is processed locally on your device - only the name of the location is sent)
      • Battery percentage
      • Power source
      • Authentication info to use the Hubitat API
  • I'm getting "Update Error" notifications.
    • Update error #1 - Error in the app
      • Error in the Android app before attempting a connection
    • Update error #2 - Error connecting to the server
      • This usually happens if your device does not have internet or if the app tried to sync while your device was switching between networks. The app will retry the connection. Unless you get this a lot and don't see data going to Hubitat, this can be ignored.
    • Update error #3 - Error on the server
      • Usually this happens because the server does not have the necessary info to authenticate to the Hubitat API. Open the app in Hubitat and click save. This will refresh the authentication info stored on the server. If you still have issues, try to pair the app again.
  • I have an iPhone. Does this work?
    • No, there is no version of the app for iPhones. Developer accounts for the App Store are kinda expensive, it would require a complete rewrite of the app and I do not have (or plan on getting) an iPhone.
  • Why do I have to install the patch app?
    • Because starting in Android 8.1, it's not possible for an app to be notified when the Wi-Fi state changes. The patch app targets a lower version of Android and just relays the information to the main app.

Donate

Donations are not required but are greatly appreciated. If you would like to donate, click the link below.
Donate

Shoutout to @abuttino for donating a Hubitat Elevation and convincing me to switch.

6 Likes

What exactly makes this better than any other phone presence solution? Why is the version for 8.1 or higher not on the Play store?

What makes it better?

  • I can attach events to leaving multiple different locations (ex. Adjust the thermostat when I leave work so the temp is how I like it when I get home)
  • It uses changes in Wifi networks to detect presence. This makes it faster since it's not just checking my GPS coordinates on a timer. I have been using this (along with a few hundred other people) on SmartThings for a few years. My presence normally updates before I even get out of the car. I am working on triggering it with personal door codes as well to fill in time gaps caused by weak Wifi or phone not connecting quickly.

Why is there not a version for 8.1 or higher not on the Play Store?

  • There is only one version of the app (which is the one on the Play Store). Because of power saving restrictions starting in android 8.1, it requires a second app that targets a lower version of android to get around the power saving. Since Google does not allow apps that target a lower version of Android on the Play Store, I have to have a second app. The only thing the second app does is forward events to the main app. I am working on a way to make this a bit cleaner.
1 Like

@Johndc7

Thank you very much for putting this together!

I can't get it to work. I put the android app on my phone and the apk (i have a pixel4).
I then installed the driver into hubitat followed by the app. I clicked on oauth and update before i saved. in the apps list it says oauth enabled.

i then go to provision the app in the apps tab. When i do that i select add a new device, give it a name and hit enter to get to the "Pair this device". At this moment i get the error "the address wasn't understood., An error occurred during a connection to st.callahtech,com. You might need to install other software to open this address".

In the system log i get this entry " 2020-11-02 06:15:27.595 pm debugSKDIgrAwn"

I don't know what the 350) refers to but the SKDIgrAwn is the device ID for the presence sensor i am trying to add according to the screen.

Any ideas what i'm doing wrong?

par

Same issue here

Somehow I got mine to work just now....

1 Like

It’s definitely good to have options. Seems like some hoops to jump through for the patch and such. It also looks like it needs to talk to a server you’re running, which might rub people the wrong way unless you’re open about what you’re doing (if anything) with their location data. Will this still work when your server is down?

Here is another option for this looming for something that’s cross-platform (Android/iOS) and has some similar features (battery, charging state, if they are on a WiFi network) and doesn’t have a backend server requirement outside your HE’s cloud endpoint: [RELEASE] OwnTracks Presence

I do like the current and previous locations and how you can tie those into a rule.

I just got it working. I'll play around a bit with this to see how well it works. The geofencing on the hubitat app haven't worked that well, I hope this works better. I'll report back in a few days.

I suspect androids battery management system is not compatible with this app. Or at least the most recent Android running in a pixel 4xl device.

I did install the companion apk and I removed all battery optimizations for both apps (and rebooted just to be sure) but once the phone enters deep sleep the app reports that it's away. I think my search for Better geofencing method in Android continues.

Edit: I left my home for an hour and just got back. I've been in the home for the past 30 minutes without touching my phone and the app reports me as being away. I'm fairly sure it's Android that is the culprit, I think the idea is pretty neat though. I like the use of representative state transfer to transfer state from the phone to hubitat, but Android is notorious for shutting down daemons running in the background, and while I don't know for sure I'm fairly certain this is what is going on.

Check your permissions, make sure you have the location enabled on your device as well as the permissions in the app. If you look at the logs on your hubitat, you can see every time that it syncs. If there is some type of info coming through then that would eliminate that possibility of it being a battery management issue.

I have a Pixel 5 so I can vouch for that it works on Pixel devices on the latest software.

I checked the log this morning on hubitat. Looks like it reports as being away to the service about every 10 minutes or so?
let me double check permissions and other settings.

EDIT: I double checked and permissions for location was only on while app is in use. i changed that to allowed all the time. let me see if that was the problem. so far i have two successful checkins.

1 Like

I do not log or store history of any data that goes through the server. The database only has records needed for authentication with the cloud api and a copy of the latest event (in case of errors). There is no personally identifiable information is stored, logged or even reaches the server. All data processing is either done locally on the device or locally on hubitat.

I have considered using the server for setup only but I feel like it adds some extra reliability and the potential for new features. As for the patch, unfortunately there is a battery optimization that was implemented in Android 8.1 that prevents apps from listening to WiFi network changes. The patch takes advantage of the compatibility mode on Android by targeting a lower version. It is the only way to get around it as far as I know (I am open to suggestions). I suspect this is the reason why OwnTracks is missing this functionality (as well as the battery / charging state) on Android.

Looks like OwnTracks could be a good option for iPhone users though.

1 Like

I've run it for 6 hours, seems to work well. Changing the app settings to location allowed all the time did the trick.

Thanks, I'll play with this a bit next for automation!

And sincerely, thanks for sharing. I really wanted a decent arrival precense sensor and nothing on my phone has worked well. This shows good promise.

Sadly this app is really a WiFi presence so when I lose internet it sets my presence as away so it's not doable -- geofencing is the only way to get proper presence sensing.

Well since hubitat is run locally, your presence would never update if you lose internet :slight_smile:

Being serious, there is also a timeout setting in the device options. You can set it to only show away if you are disconnected for more than X minutes. Arrivals will show up immediately.

Maybe that could help...

Is this app available on the Hubitat Package Manager? I will try it out.

It is not on Hubitat Package Manager yet. I need to get it added but I've been busy moving and getting all of my stuff set back up for the last few weeks.

I will try to get it added this weekend.

Edit: I submitted a request to have it added to HPM. Once they accept, it will be available.

This app is working exceptionally well with a minor tweaks.
I found that my wifi occasionally restarts and the presence sensor thought it meant I was gone. Not so much an issue when detecting arriving but definitely and issue while at home and wifi restarts and hubitat thinks I'm leaving.

But with event engine, I setup a rule that detects if my mobile presence reports that I'm gone and I use the delay option. I set delay for 60 seconds because my wifi outages rarely last 60 seconds, and if they do and I'm home I'd like to know anyway.

With that the presence sensor has been 100% correct over the past week. It perfectly detects when I'm gone with a 60 second delay (about halfway down the block) and instantly when I'm back. I highly recommend this approach to detect presence, as long was you don't turn off wifi in the phone it just works.

I'm also liking this app, I've given up on geofencing(at least for now). Using Wifi has been far more reliable for me. I haven't had any false "aways" for a couple weeks. I use a Google Nest mesh wifi system with two points, It has been great. Much more reliable than the Asus AiMesh system I was using before.

Wouldn't this be the same as setting the timeout on the device page to 1 minute?

1 Like

I have the google nest wifi, with a hardwired backhaul between my 4 pucks. Its been unreliable but got a bit better once i did a factory reset and started over.

I did have the 1 minute timeout on the device page, but i didn't find that it helped much. I find that the combo with event engine works really well.