Skill detail
homekit
Controls smart-home accessories and commissions Matter devices using Apple HomeKit and MatterSupport, covering homes, rooms, accessories, characteristics, action sets, triggers, and Matter onboarding.
Inspect before use
Read the source instructions and check the requirements before you install this skill.
SKILL.md
The saved excerpt is a snapshot from when this skill was listed. The external source remains the complete and most current version.
---
name: homekit
description: "Control smart-home accessories and commission Matter devices using HomeKit and MatterSupport. Use when managing homes/rooms/accessories, creating action sets or triggers, reading accessory characteristics, onboarding Matter devices, or building a third-party smart-home ecosystem app."
---
# HomeKit
Control home automation accessories and commission Matter devices. HomeKit manages
the home/room/accessory model, action sets, and triggers. MatterSupport handles device commissioning into your ecosystem.
## Contents
- [Setup](#setup)
- [HomeKit Data Model](#homekit-data-model)
- [Managing Accessories](#managing-accessories)
- [Reading and Writing Characteristics](#reading-and-writing-characteristics)
- [Action Sets and Triggers](#action-sets-and-triggers)
- [Matter Commissioning](#matter-commissioning)
- [MatterAddDeviceExtensionRequestHandler](#matteradddeviceextensionrequesthandler)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)
## Setup
### HomeKit Configuration
1. Enable the **HomeKit** capability in Xcode (Signing & Capabilities)
2. Add `NSHomeKitUsageDescription` to Info.plist:
```xml
<key>NSHomeKitUsageDescription</key>
<string>This app controls your smart home accessories.</string>
```
### MatterSupport Configuration
For Matter commissioning into your own ecosystem:
1. Add a **MatterSupport Extension** target and set its principal class to a
`MatterAddDeviceExtensionRequestHandler` subclass
2. Add `NSBonjourServices` entries for `_matter._tcp`, `_matterc._udp`, and
`_matterd._udp`
3. Add `com.apple.developer.matter.allow-setup-payload` only if the caller
supplies a Matter setup payload programmatically
### Framework Boundary
| Need | Framework |
|---|---|
| Homes, rooms, accessories, characteristics, actions, triggers | HomeKit |
| Commission Matter into the app ecosystem | MatterSupport |
| Select and authorize a nearby Bluetooth or Wi-Fi accessory | AccessorySetupKit |
| Exchange Bluetooth GATT data after selection | CoreBluetooth |
| Join or configure an accessory's Wi-Fi network after selection | NetworkExtension |
## HomeKit Data Model
HomeKit organizes home automation in a hierarchy:
```text
HMHomeManager
-> HMHome (one or more)
-> HMRoom (rooms in the home)
-> HMAccessory (devices in a room)
-> HMService (functions: light, thermostat, etc.)
-> HMCharacteristic (readable/writable values)
-> HMZone (groups of rooms)
-> HMActionSet (grouped actions)
-> HMTrigger (time or event-based triggers)
```
### Initializing the Home Manager
Create a single `HMHomeManager` and implement the delegate to know when
data is loaded. HomeKit loads asynchronously -- do not access `homes` until
the delegate fires.
```swift
import HomeKit
final class HomeStore: NSObject, HMHomeManagerDelegate {
let homeManager = HMHomeManager()
override init() {
super.init()
homeManager.delegate = self
}
func homeManagerDidUpdateHomes(_ manager: HMHomeManager) {
// Safe to access manager.homes now
let homes = manager.homes
let primaryHome = manager.primaryHome
print("Loaded \(homes.count) homes")
}
func homeManager(
_ manager: HMHomeManager,
didUpdate status: HMHomeManagerAuthorizationStatus
) {
if status.contains(.authorized) {
print("HomeKit access granted")
}
}
}
```
### Accessing Rooms
```swift
guard let home = homeManager.primaryHome else { return }
let rooms = home.rooms
let kitchen = rooms.first { $0.name == "Kitchen" }
// Room for accessories not assigned to a specific room
let defaultRoom = home.roomForEntireHome()
```
## Managing Accessories
### Discovering and Adding Accessories
Use the [Framework Boundary](#framework-boundary) table before adding an
accessory; only HomeKit/MatterSupport work continues in this skill.
Read the full source on GitHub (opens external page)