I’ve been using the usual iOS presence detection method of exposing an input_boolean
through HomeKit and then flipping the switch when I get home, and using that input_boolean
switch based on location changes. But I got tired of seeing those switches in the Home app on my iPhone (and they are particularly confusing for family members). Plus, those input_booleans
can’t be used with the new person
functionality. This method will have update your status with real device_tracker
entities.
So I decided to use the new iOS 13 Shortcuts app and HA webhooks to get around needing anything at all. The only requirement for this method is having a public URL for your HA install. The main benefits are:
- Actually getting a
device_tracker
entity. For me this means I can use theperson
platform more fully. - You don’t need to use the HomeKit platform at all if you don’t want to.
- No weird useless switches in my Home app, when you do use the HomeKit platform.
Before you set anything up in iOS, you’ll need a really simple automation
to enable a new webhook. Change your webhook_id
to something very random!
- alias: iOS Shortcuts Webhook (presence)
trigger:
- platform: webhook
webhook_id: ios_hook_XXXXXXXwhateveryouwantXXXXXXX
allowed_methods:
- POST
local_only: false
action:
- service: device_tracker.see
data_template:
dev_id: "{{ trigger.json.tracker_name }}"
location_name: "{{ trigger.json.location_name }}"
gps_accuracy: 80
(I actually don’t know what the range of values are for gps_accuracy
so would love any insight there. I imagine it should be set fairly low since the Shortcuts app has been unreliable in the past.)
After you have the webhook added, reload your automations or restart HA. Then you can get started in the iOS Shortcuts app.
-
Open the Shortcuts app and create a new “Home” automation (not a “Personal” one). Here I’ve got them for me and another person coming/leaving the house.
-
Name the Shortcut, and choose the person you want to trigger it. Then tap the “Do” area.
-
Ignore all the actual HomeKit stuff and scroll to the bottom, and tap the “Convert To Shortcut” button.
-
Choose the “Web” option.
-
From the list, choose “Get Contents of URL”
-
This is the important part. Put in the URL of the webhook you defined in your automation (eg.
https://<your public HA address>/api/webhook/<whatever webhook_id you defined>
). Then hit the “Show More” button and make a few changes: change the method toPOST
, make sure the body isJSON
, and add two new text fields:tracker_name
andlocation_name
. Thetracker_name
is the id of the new presence entity you’ll be creating. You don’t need to create this beforehand – simply setting it via the webhook will cause it to exist. The other text field islocation_name
and I only ever usehome
andnot_home
here.
After you’ve got this, you can hit the little play button in the lower right corner to test it, and it should instantiate the new device_tracker
the first time, and change state after that (depending on what you set location_name
to). Then hit next, confirm the automation, and you are all set!
I’ve only been using this since iOS 13.1 came out a few days ago, but it seems to work as well as the old input_boolean
method.