HomeKit Automation Guide
HomeKit offers a number of benefits for building a smart home, particularly around privacy, security and ease of use. A vital feature for smart home platforms, though, is the ability to create automation rules, and HomeKit actually offers more in this area than Apple’s own Home app exposes.
We’re going to go into all the types of automation rules HomeKit supports, and how to implement them. This will involve some third party apps, as this is the only way to access some of these features for the time being.
Automation Rule Basics
Smart home platforms implement rules in different ways, but they generally fall into some broad categories, not all of which are supported by every platform. These can be classified as:
Trigger Actions (if A then B)
The most common, and indeed the basis of the platform IFTTT. One input is used to trigger another action. The input can be a device control event (a device did something), a sensor event (motion, temperature, light level etc), a schedule event (a fixed time or date), or a geofence event (someone arrives or leaves a given location). HomeKit supports all of these to some level.
Conditional Actions (if A and B then C)
An extension of the above with the ability to define filters that must be passed before the actions will be performed. The filters are similar to triggers being device state, sensor thresholds, geofence presence, time and date. If conditions are supported, more than one can typically be combined with AND and OR options (all conditions, or any one of the conditions). HomeKit supports all of these to some level.
Delay Actions (if A then B after X mins)
Actions can be delayed by a given time interval before being performed. This can be as an overall capability allowing the entire rule to be delayed up front, or it can be a delay to undo (or turn off) the actions after the fact. HomeKit supports the latter only.
Stacked Conditionals (if A and B then C while/until D)
This extends conditional rules to include exceptions and limits. These can be loosely defined with terms like while, unless, and until. Some uses of this kind of rule include things like seasonal changes, and manual overrides which can make your home a lot smarter and avoid some of the frustration that can result from inappropriate automatic behaviors. HomeKit does not overtly support these, but these are some ways around that.
Now we know the kinds of things we could do, let’s look at how we can accomplish these in HomeKit and what the limitations are starting with the tools we’ll need.
Third Party Clients
In order to unlock some of the advanced functionality of HomeKit, you'll need some third party apps. Here are a few that have automation specific benefits. Apart from the Eve app, these are not free, but if you want to get the full benefits of HomeKit automations it’s a small outlay compared to your likely spend on accessories.
Home+ by Mattias Hochgatterer is a good all round client with a highly customizable accessory display and comprehensive access to automation capabilities. The overall display of the home is not as practical as the Home app, in that there is no status view, and you can’t arrange the rooms in any way, but you do get a lot of control over how accessories are shown, including which characteristics and services are displayed or hidden.
Controller for HomeKit by Jan Andre is similar to Home+ but very much a power user focused app. This client forgoes any pretense of looking nice and just gives it to you straight, showing all the dirty internals of what’s going on. Additionally it includes configuration backup and restore features, and an additional way of automating actions called Workflows.
While the Eve app by Eve Systems GmbH is ostensibly Eve’s own app for their devices, as they are exclusively a HomeKit manufacturer their app is actually a full featured HomeKit client. The Eve app sports the prettiest design of these three while still enabling greater access to automation features than the Home app. I still prefer Home’s status display, but this one at least gives a lot of presentation control of your rooms and devices, and has, in my opinion, the nicest accessory control interface of all the clients, including Apple’s.
How To Create Trigger Actions
Being the most basic rule type, these are easily created in the Home app. The first step in creating any automation is to select a trigger. The Home app allows almost full use of the trigger types support by HomeKit, with some limitations. Here’s how to create these various trigger actions:
Tap the + in the top right corner.
Select the type of trigger you want to use from the list.
Geofence presence. The Home app calls these “People Arrive” and “People Leave”. These events can be for one or more members of the Home specified as Anyone or by selecting specific users. Interestingly the ability to select specific users is limited to the Home app, the third party offerings can only use Anyone. You can also specify events based on the first to arrive and last to leave rather than specific people, but these can also be based on a filtered group of home members.
Select whether you want to trigger on anyone arriving, or the first person to arrive.
For both of these options, you can tap the info icon to the right to select which people to use for the trigger.
If you specify one or more people for Anyone Arrives/Leaves, any one of those people will trigger the rule.
If you specify one or more people for The First/Last option, this will use only the selected people rather than every member of the home.
Scheduled Time, which is limited to Time of Day and Day of Week rather than allowing specific dates. All of the apps expose the same functionality, either being able to enter a specific time of day (hour and minute) as well as the days of the week that it will trigger, or a Sunrise/Sunset value along with an offset time before or after that. This allows HomeKit to calculate the correct trigger time based on your location and time of year.
Select Sunrise, Sunset or Time of Day.
For the first two, tap the info icon to the right to set an offset either before or after that time.
Turn off any days of the week you don’t want the rule to run in the Repeat section. They are all on by default.
Accessory State. These use data from an accessory to determine a trigger threshold. The Home app breaks these into two types; “An Accessory is Controlled”, limited to on/off type events, and “A Sensor Detects Something”, again limited to certain accessory types, such as motion, air quality, smoke and contact sensors. Third party apps will allow you to select basically any characteristic value from any accessory, and in many cases a range of values, to act as a trigger.
Select an accessory from the list. The accessories available will depend on which trigger option you use.
For An Accessory is Controlled, you’ll be able to choose on/off, open/close type devices.
For A Sensor Detects Something, you’ll be able to select sensors that report specific events like open/closed, motion/no motion, etc. For other sensor types you’ll need to use a third party app. Here’s how to create HomeKit sensor triggers in third party apps.
Tap Next in the top right corner.
Select the triggering value from the options presented. This will depend on the accessory you chose.
With the trigger defined, you can now complete the rule by assigning the actions to be performed. This part exposes another difference between the Home app and third parties. The Home app allows the selection of specific accessories and actions, not just Scenes. Third Party apps can only select Scenes. The Home+ app tries to mitigate this somewhat by allowing you to select accessory actions during the rule creation and then creating a Scene automatically for you in the background.
Tap Next in the top right corner.
Select the scene to run as the action, or select specific accessories to control at the bottom of the list.
Tap Next at the top right.
Review the rule and adjust any accessory actions as required then tap Done.
How to Create Conditional Actions
The Home app does actually allow some limited conditional actions to be defined, but they’re scattered through the rule creation screens. Conditions in the home app are essentially limited to People and Time based constraints. For Time based conditions, you can select Day, Night, or a specific time window. For People it’s “When I am Home”, “When Somebody is Home”, “When nobody is home”, and “When I am not home”.
Where these options appear depends on the type of Trigger being used
For People based Triggers, the Time option is presented on the first page after selecting the trigger type, where you select the people to use for the trigger.
For Time based triggers, the People option appears below the Repeat bar for selecting days of the week.
For Accessory based triggers, both the Time and People options appear on the screen after selecting an accessory, where the trigger value is selected.
HomeKit does allow considerably more flexibility than these options, though. To create them requires third party apps, although once created the Home app does show the conditions and allow them to be toggled off individually.
Each of the third party apps handles conditions in a similar way. When creating a rule a conditions section will be present where one or more conditions can be added. There is some variation in the naming of the options, but generally all three offer Accessory State and Time based conditions. The Time options are the same as the Home app, with either a specific time window, or a period before or after sunset and sunrise.
Home+ and Controller both offer the People conditions as well, with the same options as Home. The Eve app doesn’t have any location based condition options, but these can be added using the Home app after you’ve specified any other conditions you need.
To add an accessory based condition to a rule in each app, open the automation and then:
Tap Add Condition.
Tap Accessory State.
Select the Accessory to use.
Select the characteristic to use.
Specify the operator and value.
Using Controller for HomeKit:
Tap the event to edit.
Scroll down and tap Add condition at the bottom.
Tap Value of a characteristic.
Select the accessory to use.
Select the characteristic to use.
Tap the newly added condition.
Use the Characteristic value and Comparison operator buttons to modify.
Tap the row under Conditions
Tap Add Value Condition
Select a room
Turn on the characteristic to use
Tap the operator and select the value to use.
Eve filters the available characteristics to those it thinks make sense for the device type. This just helps to keep the list of options a bit cleaner, but it can hide some useful values in certain cases, especially accessories with multiple functions. If you do need to access custom characteristics, then Home+ exposes everything the accessory offers (even more than Controller does), including the ability to do string comparisons.
One important distinction between the apps here, Eve and Home+ need ALL conditions to be met, where Controller allows you to specify ANY or ALL.
How to Create Delay Actions
Delays both before and after an automation (or even during) can be a useful tool when crafting more advanced automation behaviours that include linked automations or timed activities. HomeKit is a bit lacking in this area when compared to other platforms, and only supports one kind of delay; an undo timer.
In the Home app any automation your create will have a Turn Off option at the bottom of the rule, or at the end of the creation steps. The default, naturally, is Never. This can be changed to a number of preset values from 1 minute up to 4 hours. This is a useful feature that allows for anything that was turned on by the rule to be automatically turned off again.
Commonly this would be used for motion triggered lights so they turn off after a period of no motion. The motion sensor triggers the rule, the lights turn on, and the countdown starts. A key point here is that the countdown is reset every time the rule is triggered, which means so long as motion is detected again in the specified time, the lights won’t turn off.
But what if you want to delay when an action starts? That gets a bit trickier. A good way to do this is to use a dummy switch. While this is a useful automation tool, HomeKit doesn’t support this functionality natively. A good solution is to use Homebridge and the homebridge-dummy plugin. This plugin allows for stateless, stateful, and timed switches to be added easily to your HomeKit setup.
An example of this use is my nightlight function. My Goodnight scene turns everything off, and I typically kick that off with a Siri command right before I head to the bedroom. Because I’m not triggering the scene with an automation, I can’t use the automatic Turn Off feature (which also wouldn’t work if the light was already on when the scene ran). The problem is that it makes it very dark and I need a way to get there in one piece.
The solution is to use a timed switch with a 2 minute delay. The Goodnight scene now turns on the hall light with a 1% brightness, that gets me to the bedroom, and turns on the dummy switch as well. Another automation is triggered when the dummy switch turns off which turns off the light.
Another option is to use Siri Shortcuts. You can actually use Shortcuts to build automated behaviors now, but only in the default Home app. Check out the guide on using shortcuts in automations. Essentially you’d be looking to use the Wait action to insert delays, both fixed and calculated from other data, and then send whatever commands to your accessories you need.
How to create stacked conditionals
This level of complexity was something completely absent from HomeKit for a while, but we are starting to get the tools to build these more complex automation rules, although again, it’s not obvious at first glance.
We can use some kludges to achieve these results and I’ve touched on these a bit so far, such as the use of dummy buttons and Shortcuts. Still, it is here that we start to run into hard limitations for the time being.
If we want to have a branching condition, for example, being one which does different actions depending on conditional results. This would typically be an if-then-else function; if condition A and B then do C, otherwise if B and D do E. You may also have additional conditions on the second action.
We can do this in HomeKit by creating multiple automations off the same trigger and use the conditions to determine which path to take. The toggle switch example uses this approach in a simple way, but you can build up the conditions to make it “smarter”.
We can do this a bit more directly using Shortcuts as we can use an actual IF-THEN-OTHERWISE scripting action (this alternative is also covered in the toggle switch example), and these can be nested as well for more complexity. There are still some limitations with this approach though, as you can’t access the People conditions or sunset/sunrise time constraints within a shortcut. If you need those you’ll have to make do with the multiple automation method.
Having an action continue UNTIL something happens or WHILE a condition is true can also be achieved with a dummy switch and multiple triggers. The process is very similar to creating a delay action. It could look something like this:
A trigger would activate and run a scene, flipping on a dummy switch in the process.
When the UNTIL event occurs, this is used as a trigger for another automation that flips the dummy switch off.
The dummy switching off is the trigger for another automation that completes the full sequence.
A practical example
I have an outdoor water feature that is fully automated through presence and time conditions via an Eve Energy smart outlet. This works well as it only turns it on during the day when someone is home, and turns it off as required.
However, on a windy day it sprays water all over the place, so I wanted a way to turn it off while it’s too windy. I need to use IFTTT for this particular case as HomeKit doesn’t support wind speed as a sensor input, but the same process would apply for other scenarios with HomeKit supported values.
As an aside there are few ways to hook IFTTT into HomeKit, Homebridge being one of them, but I’m using the awesome Pushcut app for this. It’s not free, but it’s a lot simpler and adds a bunch of other automation capabilities.
What we want here is a rule like this:
IF anyone is home AND it’s daytime, Turn on the fountain WHILE the wind speed is low.
That’s the simple way to do it, and some more advanced automation platforms support that kind of rule structure. HomeKit absolutely does not. But we can achieve the same result with multiple rules like this:
At 6am, if the wind switch is off AND if someone is home, turn on the fountain
When anyone arrives home, if it’s daytime AND if the wind switch is off, turn on the fountain
When the last person leaves, turn off the fountain
When the wind switch turns on, turn off the fountain (the switch will reset after whatever delay you set on it)
When the wind switch turns off, if it’s daytime AND if anyone is home, turn on the fountain
At 6pm, turn off the fountain.
So if the wind is over a certain speed, IFTTT flips a Homebridge dummy switch. The event triggers an action to turn off the fountain (I also set a particular lamp to Yellow so I know what’s happened).
The switch has a 30 minute delay, so it will turn off only if the wind has been below threshold for 30 minutes (because repeated triggers will reset the timer). When it turns off the Fountain is restored IF the day and presence conditions are still valid.
The rules 1 and 6 can be simply added to your Good Morning and Good Night scenes, or a similar scheduled scene you already use to simply this a bit. You could also leave rule 5 out and just leave it off until someone comes home again.
If you think about using accessory changes to trigger other actions, combined with multiple conditions, you can start to see how you can achieve a lot of interesting results that can result in more intelligent home automation behavior.
HomeKit may not overtly offer the kind of features seen in some more enthusiast focused platforms, but that doesn’t mean you can’t do them.
With the addition of some third party tools, and thinking about how to use triggers and conditions a bit differently, it’s possible to unlock much smarter and more complex automated behaviors than just using the features exposed in the Home app.
Still, Apple will hopefully be expanding these features to make these tasks easier and more robust over time, adding those capabilities for third party apps even if they choose to keep the default app focused on the everyday consumer.