[RELEASE] Generic and Virtual Drivers

I've created a virtual driver which I've found very useful to use with Homebridge Hubitat v2 to leverage HomeKit's native presence detection, powered by phone GPS location.

I know this can be achieved with the Hubitat app, but I had a lot of problems on my old phone with geolocation running down the battery. This method at least relies on something handled natively with a built-in app and seems to have a little less power impact. It also allows for family member presence detection without them having to install the Hubitat app.

Or search on Hubitat Package Manager for BirdsLikeWires and you should see my generic drivers repository.

Virtual Switchable Presence

This provides a weird device which will flip between "present" and "not present" when its virtual switch is turned on or off. It will report a timestamp of when it was last switched.

The way I have this set up is to add a virtual device to HE using this driver, then share it out to HomeKit via Homebridge using Homebridge Hubitat v2. Then set up two automations per switch; one to turn the switch on for arriving, the other to turn the switch off for leaving.

You can now use the status of the virtual switch or presence of the virtual device to trigger events using the far-more-reliable Hubitat automations. Sadly this does not improve the reliability of automations that HomeKit is handling (ie. flipping these switches) which for me has been one of the biggest problems of the Apple system.

Setup

I'd recommend using Capability Filtering in Homebridge Hubitat v2 to temporarily remove the switch function from the virtual device. This will cause HomeKit to create the device as a presence sensor. Then remove the switch filter and you will have a presence sensor which has a switch, rather than a switch with a presence sensor. This prevents the switches from being too easily flipped on and off manually in Apple's Home UI; it becomes a two-step process.

77160B8C-BA80-47AC-BD03-3DA50F4FE6B3_4_5005_c

I also keep them in a room called "House" and not set as a favourite, so they won't appear on the initial Home page.

1 Like

This is cool. Right now I use a Homebridge Automation to flip a virtual switch for this purpose, but this is very cool. I might replace the two I have with this over time.

Thank you for posting!

1 Like

There's quite a few of these "hybrid" drivers floating around. "Hybrid" meaning they cross-connect two different Capabilities. In this case, Presence and Switch. Setting either, sets the other to be the same.

I've been using my version of this driver for 3 years and haven't thought about it since, 'til reading this Topic :smiley:

I really like the idea of "hiding" the switch capability during the initial announcement to HomeKit and then putting it back... all to get a HomeKit to display as Presence. :slight_smile:

For the "hybrid" drivers I have created there's one Sensor Capability coupled to one Actuator Capability. Sensors can't be set, Actuators can be. Presence is a sensor, switches are an Actuator.

1 Like

Like csteele I have been using one of the other versions of this and it works well. Yours has some more logging and info capabilities. Thanks for the tip on filtering the switch out, I am going to give that a try.

One other tip, I think this might have been added in iOS15 as I only noticed it recently. In homekit long press and get into the settings of the switch part of the device. Find "Status" and open that. Then turn off Include in Home status. This prevents the "switch" from showing on your main screen as a turned on switch which had been annoying me until I found this.

1 Like

Absolutely right; it's been there a while, but also important to prevent accidental triggering too. :+1:

Made some changes which will affect you if you pull the readings out of Hubitat through the Maker API. These are now the available states:

image

  • absent/present - epoch time sensor last went absent (ms)
  • absent/presentCounter - how long sensor has been absent (ms)
  • absent/presentDate - date and time sensor went absent (YYYY-MM-DDTHH:MM:SS)
  • absent/presentTime - how long sensor has been absent (Xd Xh Xm)

The usual presence and switch states remain, of course. The driver updates the values every minute.