HomeKit as a Presence Sensor

I just read this thread and had to give this one a try! As of now I used OwnTracks for presence detection which basically works well, but sometimes the location stucks for hours. Homekit as an alternative sounds very promising.

So I created an input.boolean to act as a switch and configured an automation (in Homekit) to turn on the switch when I arrive, vice-versa when I leave. I also created a binary.sensor to use it for an automation. This automation created a device_tracker entity which gets updated via the below automation.

alias: Update presence and device tracker Andreas
trigger:
  - platform: state
    entity_id: binary_sensor.presence_andreas
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: binary_sensor.presence_andreas
    from: 'on'
    to: 'off'
condition: []
action:
  - service: device_tracker.see
    data:
      dev_id: tracker1
      location_name: '{{ ''home'' if is_state(trigger.entity_id, ''on'') else ''not_home'' }}'
      source_type: router
mode: queued
max: 10

the issue
I noticed that when I restart Home Assistant on my Raspi the state from home switches to not home.

question
Has anyone else observed this behaviour, if so what can I do to change it? I couldnt find a solution during internet research.

all the best

Andrew

Just a guess. You said:

So I created an input.boolean to act as a switch and configured an automation (in Homekit) to turn on the switch when I arrive, vice-versa when I leave.

Do you have an entry of initial: in the input boolean? If so, remove it completely.

thanks for the reply, I created the input.boolean via the helper section within Home Assistant, unfortunately I cannot set the initial_state there. AFAIK the intial state is optional and not set by default. Also the automation doesnt contain an initial_state.

as of now I created a flow with Node-RED to check if my binary.sensor is on, but I am marked as not_home. If so it updates the status accordingly.

Can someone tell what the default radius is that homekit used before someone is arrive or leave?

I cant find that info anywhere but if you create an automation you can enter an address (instead of private) and then you can adjust the radius. the smallest one is 100m or around 330 feet. attached a screenshot how it looks like. I think the default radius is 100m/330 feet.


1 Like

Same here.

And this is what I do also, but using the HA automation instead of Node-Red.

sorry to revive an old thread, would you be kind enough to share your automation to re-set the status. i was trying to use device_tracker.see, but i can’t seen to get it to fire.

Is the issue being the automation not being able to be triggered?
Use Home Assistant trigger type and start event, to trigger your automation.
I then added a delay of 1 min (action type: wait for time to pass) - might not be required; you can tweak this
And then, yes, use device_tracker.see under the call service type.

1 Like

d’oh, i was trying to trigger on the state of the binary sensor, but since it doesn’t change, it wasn’t triggering. thank you!

I am biased, but the way I described in this thread is by far the simplest. It doesn’t require the HA app and it doesn’t even require you to be using the HomeKit integration. It does require a hub like an AppleTV though. If you use this you will just end up with a device_tracker and no binary sensors or any “middle man” entities.

3 Likes

i was just reading that thread and was going to try it out as well. Thank you for posting this!

1 Like

anyone else having issues with the location re-setting to not_home. i was working on some automations today and did a few restarts. at one point i checked the status of my device_tracker for the homekit integration and it was reset to not_home. so i looked in the logbook, and sure enough, about 3-4 minutes after the automation i use to set it to home if a restart happens, it jumps back to not_home. the switch is correct in both the home app and in HA. not sure what would be causing this.

1 Like

Hi, I’m pretty new to homekit
Would a non apple product like the xiaomi homekit hub works?
Because the automation tab on the home app still request for a hub

Hi all,

Since iOS 16.x I see sometimes that our iPhones (me and partner) suddenly outside the home range a poited (gps) even they connected to WiFi. After 1-10min they point again inside the home range.

I have now put a delay in HA before the automation change us from home to not_home.

Still not found why our phones are out of range (100-150m away) and still not solve it…

Before 16.x it was so stable…

Hi all,
I am quite new to HA and to this community (actually, it is my first post). Thanks @ptdalen and @ha_steve for this great contribtion, which did help a newbie a lot.
So I wanted to share some updates:

Configuration of HomeKit Integration
Works now completely in the UI of the HomeKit Integration. No manual update of configuration.yaml needed.

Presence Group
Still needed in configuration.yaml. As of now, no possibilities in the UI.

Binary Sensor in Device Tracker
My approach for presence detection was:

  • Device Tracker using NMAP Tracker Integration for my iPhone (because Netgear Integration not working).
  • A binary sensor, triggered by the input_boolean by the automation in HomeKit (as described above).

As a variant from above described approach, I did integrate the binary sensor into a presence group, I used ha-composite-tracker:

House Mode Adaption in the HomeKit
I do use my Composite Tracker to trigger the above mentioned input_select.house_mode. For my comfort, I show this input_select in the HomeKit. Be aware, that the name of input_select will not be shown on the iPhone automatically. You have to adapt it manually, as described here:

Thank you for posting the link to iOS presence detection WITHOUT Homekit or HA app (totally native). I agree its a much cleaner solution!

The only “nerdy” thing about it is the setting up of the Shortcut. That gets quite technical. But still falls within the native capabilities of HA and iOS without needing another app or hacks!

I’m currently testing IRL to see how it performs.

I struggled with the HA companion app location responsiveness, plus you need to keep it open in the background on iPhone I think

I hope it works out for you! For what it’s worth, after several years I actually stopped using my own solution. This is because the Private BLE integration (built-in) is incredibly responsive, and requires no internet. If you use iOS devices and have Bluetooth (or Bluetooth proxies) set up, it is incredibly fast and reliable.

1 Like

What are you using now @zacs can you share your setup? What stopped you from using just HomeKit presence detection?

I stopped using it after one or two false negatives. I lazily did not look into troubleshooting though, because I wanted to get away from internet-dependent sensors as much as possible.

I have a few Bluetooth proxies around my house – specifically GL.iNet GL-S10s. Once you have a few Bluetooth proxies (or even just Bluetooth on your HA server using a USB dongle), you can just use the Private BLE integration. For iOS devices you’ll need to figure out what your IRK is as described at that link. Once this is set up, it is rock solid in terms of detecting your iPhone (or iPad or Apple Watch etc).

This method doesn’t require the internet at all, so I appreciate its higher level of fault tolerance (and its immediate detection). Because of this, it’s all that I needed for presence sensing.

Ah I see, I am currently using an older version of the same concept, it uses Zero Pi W to search for bluetooth addresses and not searching for private ble so it’s not as reliable since iOS turns off the Bluetooth broadcasts … thanks for posting the links!