[UPDATED] HTTP Presence Sensor


HTTP Presence Sensor for Hubitat

A virtual presence sensor for Hubitat that determines its state by trying to access an HTTP endpoint. If it gets good responses, it reports present. If it gets a few bad responses in a row, it reports not present.

Use Cases

  • Pinging a device (that has an HTTP endpoint) to see if it is on the house's wifi network. If that device is present, then it means someone is home.
  • When running HomeBridge on a Raspberry Pi, sometimes the homebridge process stops responding to HomeKit and Hubitat. Use this virtual device to regularly check and see if HomeBridge is still up and running. If it isn't, you can use Rule Machine rules to cycle the power on the Raspberry Pi. (I have my RPi plugged into a z-wave outlet for this reason.)


The best way to install this code is by using Hubitat Package Manager.

However, if you need to install manually:

  1. Open your Hubitat web page
  2. Go to the "Drivers Code" page
  3. Click "+ New Driver"
  4. Paste in the contents of httpPresenceSensor.groovy
  5. Click "Save"
  6. Go to the "Devices" page
  7. Click "+ Add Virtual Device"
  8. Set "Device Name" and "Device Network Id" to anything you like. Set "Type" to "HTTP Presence Sensor".
  9. Click "Save Device"
  10. On the device list, click the name of your new sensor
  11. Set "Endpoint URL" to the url that you want the sensor to regularly ping. Example: On my HomeBridge setup, the hubitat plugin exposes an endpoint at "". This is what I enter for the Endpoint URL.
  12. Click "Save Preferences"

Thanks for sharing, I really like how you break down everything, super easy to understand.

Alright this is very interesting. Thoughts of having a simple response ping to determine mobile device presence?

Nice idea. I do something similar but my pinging is run from my router and uses the maker API to update a presence device. I never thought about doing this with HTTP though.

I notice when my phone (iphone) gives different responses when on/off the network. I wonder if that could be used for presence detection. Not sure how android answers back.

Offline: response:[status:408, errorMessage:No route to host (Host unreachable)]
Online: response:[status:408, errorMessage:Connect to [/] failed: Connection refused (Connection refused)]

You got me thinking. :slight_smile:

Very possibly. I haven't tried this against an iphone yet, because I know they go into sleep modes where they disconnect from the wifi, even if they are at home. But if you can get it working, please let me know!

I didn't do this with an actual "ping" because I first wrote it for SmartThings, which can't do a ping, but can do a local http GET. But when I found that HomeBridge had very nice HTTP endpoints (for both the SmartThings and Hubitat plugins), I went with HTTP.

Yup. I've measured and logged the iphone and have found that it goes into sleep mode for up to 15 minutes. Setting that kind of delay will avoid false positives. This is what I currently use when pinging for both of my phones. I have a fingbox on my network that looks like it also does something similar. It will mark a device offline after 20 minutes. A little more conservative but I've never had it go offline for more than 15 when sleeping.

Ya. I wish we could do a ping. Then fully integrating and lan presence solution would be much easier.

Ok, I'm getting the same responses as you when I do a simple GET to my iPhone's local IP address. Interesting. So I'd need a customized version of this device driver that looked at the different statuses. And I think with the iPhone's wifi going to sleep, you'd need to treat this virtual presence sensor as:

  • If it is present, then the iPhone is definitely at home
  • If it is not present, we don't know

Maybe combine it with another presence sensor using @Cobra's Presence Central app. Interesting...

I think I have it figured out. Code coming in a minute.

Ok, here's a version for an iPhone!


1 Like

Sorry to ask stupid question but I don't understand http endpoints can I use this with Android phones?

Unfortunately I don't have an Android phone to test with, but you could try my iPhone presence sensor and see if Android phones behave the same way.

I have tried with my Android it has found my phone as present but has not realised that the device is no longer on the wifi

I will give this a try when I get home. I believe between this, homebridge and locative I may have a “reliable” presence solution.

I assume one could setup a simple http endpoint on an Android phone so that this plugin can detect it ? https://play.google.com/store/apps/details?id=jp.ubi.common.http.server&hl=en

Unfortunately I don't have an Android phone to test with. It probably has some small difference in the http status codes and messages it returns, vs iPhone. This or my other device handler could definitely be adapted to it, but I don't have one to test with.

For you guys out there using an android does this work for you OK?
I have given my phone DHCP reservation on my router and put the address in the device using this Handler but it remains not present.
I have configured the ip address as
Tried various options but it just doesn't work.
Any thoughts?

Might want to try this version:

That's better. Works a treat. Thanks. :smile:
The worst bit about this is I thought I had downloaded both versions. I hadn't. Same one twice. :blush:

1 Like

I am running Locative right now. Is this something that would help keep this more accurate at detecting presence?