PluginBench
Skill
Pass
Audit score 90

homekit

dpearson2699/swift-ios-skills

Control smart-home accessories and commission Matter devices with HomeKit and MatterSupport.

What is homekit?

HomeKit manages home automation accessories, rooms, action sets, and triggers. MatterSupport handles Matter device commissioning. Use this skill when building smart-home management features, automating accessory control, or onboarding Matter devices into your ecosystem.

  • Manage homes, rooms, and accessory hierarchies
  • Read and write accessory characteristics in real-time
  • Create action sets (grouped actions) and execute them
  • Set up timer-based and event-based triggers for automation
  • Commission Matter devices into your smart-home ecosystem
  • Enable notifications for characteristic value changes

How to install homekit

npx skills add https://github.com/dpearson2699/swift-ios-skills --skill homekit
Prerequisites
  • Enable HomeKit capability in Xcode (Signing & Capabilities)
  • Add NSHomeKitUsageDescription to Info.plist
  • For Matter commissioning: add MatterSupport Extension target and configure MatterAddDeviceExtensionRequestHandler
  • Add NSBonjourServices entries for _matter._tcp, _matterc._udp, and _matterd._udp if commissioning Matter devices
Claude Code
Cursor
Windsurf
Cline

How to use homekit

  1. 1.Create a single HMHomeManager instance and set its delegate to receive async load notifications
  2. 2.Wait for homeManagerDidUpdateHomes(_:) to fire before accessing homes
  3. 3.Access the primary home or list all homes from homeManager.homes
  4. 4.Iterate through home.accessories and their services/characteristics to discover devices
  5. 5.Read characteristic values with characteristic.readValue() or write with characteristic.writeValue()
  6. 6.Enable notifications on characteristics to observe real-time changes
  7. 7.Create action sets with home.addActionSet() and add characteristic write actions
  8. 8.Create triggers (timer or event-based) and attach action sets to them

Use cases

Good for
  • Building a smart-home control app with room-based organization
  • Creating automation scenes (e.g., 'Good Night' that turns off lights)
  • Setting up time-based triggers to execute actions at specific times
  • Responding to sensor events (motion detection, door open/close)
  • Onboarding Matter devices through a custom ecosystem app
Who it's for
  • iOS app developers building smart-home features
  • Developers creating third-party smart-home ecosystem apps
  • Engineers implementing home automation and trigger logic

homekit FAQ

When should I use HomeKit vs. AccessorySetupKit?

Use HomeKit for home-model work: homes, rooms, accessories, services, characteristics, action sets, triggers, and automations. Use AccessorySetupKit for lower-level Bluetooth or Wi-Fi accessory discovery and authorization. After AccessorySetupKit setup, use CoreBluetooth/GATT for Bluetooth or NetworkExtension for Wi-Fi flows.

Why can't I access homes immediately after creating HMHomeManager?

HomeKit loads data asynchronously. Implement HMHomeManagerDelegate and wait for homeManagerDidUpdateHomes(_:) to fire before accessing manager.homes.

How do I turn on a light or control an accessory?

Get the characteristic from the accessory's service, then call characteristic.writeValue(targetValue) with the desired value (e.g., true for on, false for off).

What's the difference between action sets and triggers?

Action sets are groups of characteristic writes that execute together. Triggers (timer or event-based) automatically execute action sets when conditions are met.

What platforms does HomeKit support?

HomeKit is available on iPhone, iPad, Apple TV, Apple Watch, Mac Catalyst, and Vision Pro. Requires Swift 6.3 / iOS 26+.

Full instructions (SKILL.md)

Source of truth, from dpearson2699/swift-ios-skills.


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. Targets Swift 6.3 / iOS 26+.

Contents

Setup

HomeKit Configuration

  1. Enable the HomeKit capability in Xcode (Signing & Capabilities)
  2. Add NSHomeKitUsageDescription to Info.plist:
<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

Availability Check

import HomeKit

let homeManager = HMHomeManager()

// HomeKit is available on iPhone, iPad, Apple TV, Apple Watch,
// Mac Catalyst, and Vision Pro.
// Authorization is handled through the delegate:
homeManager.delegate = self

HomeKit Data Model

HomeKit organizes home automation in a hierarchy:

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.

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

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 HomeKit and MatterSupport for home-model work: homes, rooms, HMAccessory services and characteristics, action sets, triggers and automations, HomeKit accessory setup UI, and Matter commissioning. If the same request asks about lower-level Bluetooth or Wi-Fi accessory discovery or authorization, name AccessorySetupKit as the boundary for discovery descriptors, picker authorization, ASAccessorySession events, and migration. After AccessorySetupKit setup, explicitly name both post-setup handoff targets: CoreBluetooth/GATT for Bluetooth accessories and NetworkExtension for Wi-Fi accessory network flows; neither handoff is HomeKit automation logic.

// System UI for accessory discovery
home.addAndSetupAccessories { error in
    if let error {
        print("Setup failed: \(error)")
    }
}

Listing Accessories and Services

for accessory in home.accessories {
    print("\(accessory.name) in \(accessory.room?.name ?? "unassigned")")

    for service in accessory.services {
        print("  Service: \(service.serviceType)")

        for characteristic in service.characteristics {
            print("    \(characteristic.characteristicType): \(characteristic.value ?? "nil")")
        }
    }
}

Moving an Accessory to a Room

guard let accessory = home.accessories.first,
      let bedroom = home.rooms.first(where: { $0.name == "Bedroom" }) else { return }

home.assignAccessory(accessory, to: bedroom) { error in
    if let error {
        print("Failed to move accessory: \(error)")
    }
}

Reading and Writing Characteristics

Reading a Value

let characteristic: HMCharacteristic = // obtained from a service

characteristic.readValue { error in
    guard error == nil else { return }
    if let value = characteristic.value as? Bool {
        print("Power state: \(value)")
    }
}

Writing a Value

// Turn on a light
characteristic.writeValue(true) { error in
    if let error {
        print("Write failed: \(error)")
    }
}

Observing Changes

Enable notifications for real-time updates:

characteristic.enableNotification(true) { error in
    guard error == nil else { return }
}

// In HMAccessoryDelegate:
func accessory(
    _ accessory: HMAccessory,
    service: HMService,
    didUpdateValueFor characteristic: HMCharacteristic
) {
    print("Updated: \(characteristic.value ?? "nil")")
}

Action Sets and Triggers

Creating an Action Set

An HMActionSet groups characteristic writes that execute together:

home.addActionSet(withName: "Good Night") { actionSet, error in
    guard let actionSet, error == nil else { return }

    // Turn off living room light
    let lightChar = livingRoomLight.powerCharacteristic
    let action = HMCharacteristicWriteAction(
        characteristic: lightChar,
        targetValue: false as NSCopying
    )
    actionSet.addAction(action) { error in
        guard error == nil else { return }
        print("Action added to Good Night scene")
    }
}

Executing an Action Set

home.executeActionSet(actionSet) { error in
    if let error {
        print("Execution failed: \(error)")
    }
}

Creating a Timer Trigger

var timeOfDay = DateComponents()
timeOfDay.hour = 22
timeOfDay.minute = 30

let firstFireDate = Calendar.current.nextDate(
    after: Date(),
    matching: timeOfDay,
    matchingPolicy: .nextTime
)!

let trigger = HMTimerTrigger(
    name: "Nightly",
    fireDate: firstFireDate,
    recurrence: DateComponents(day: 1)  // Repeat every day after firstFireDate
)

home.addTrigger(trigger) { error in
    guard error == nil else { return }

    // Attach the action set to the trigger
    trigger.addActionSet(goodNightActionSet) { error in
        guard error == nil else { return }

        trigger.enable(true) { error in
            print("Trigger enabled: \(error == nil)")
        }
    }
}

Creating an Event Trigger

let motionDetected = HMCharacteristicEvent(
    characteristic: motionSensorCharacteristic,
    triggerValue: true as NSCopying
)

let eventTrigger = HMEventTrigger(
    name: "Motion Lights",
    events: [motionDetected],
    predicate: nil
)

home.addTrigger(eventTrigger) { error in
    // Add action sets as above
}

Matter Commissioning

Use MatterAddDeviceRequest to commission a Matter device into your ecosystem. This is separate from the HMHome home-automation model; it handles the Matter setup flow and calls into your MatterSupport extension.

Basic Commissioning

import MatterSupport

func addMatterDevice() async throws {
    guard MatterAddDeviceRequest.isSupported else {
        print("Matter not supported on this device")
        return
    }

    let topology = MatterAddDeviceRequest.Topology(
        ecosystemName: "My Smart Home",
        homes: [
            MatterAddDeviceRequest.Home(displayName: "Main House")
        ]
    )

    let request = MatterAddDeviceRequest(
        topology: topology,
        setupPayload: nil,
        showing: .allDevices
    )

    // Presents system UI for device pairing
    try await request.perform()
}

When providing a setup code directly, import Matter and pass an MTRSetupPayload as setupPayload; this is the case that requires the setup-payload entitlement.

Filtering Devices

// Only show devices from a specific vendor
let criteria = MatterAddDeviceRequest.DeviceCriteria.vendorID(0x1234)

let request = MatterAddDeviceRequest(
    topology: topology,
    setupPayload: nil,
    showing: criteria
)

Combine criteria with .all([.vendorID(...), .not(.productID(...))]) or use .any(...) when any one criterion is enough.

MatterAddDeviceExtensionRequestHandler

For full ecosystem support, create a MatterSupport Extension. The extension handles commissioning callbacks. Override the needed methods, but do not call super from those overrides.

import MatterSupport

final class MatterHandler: MatterAddDeviceExtensionRequestHandler {

    override func validateDeviceCredential(
        _ deviceCredential:
            MatterAddDeviceExtensionRequestHandler.DeviceCredential
    ) async throws {
        // Validate the device attestation certificate
        // Throw to reject the device
    }

    override func rooms(
        in home: MatterAddDeviceRequest.Home?
    ) async -> [MatterAddDeviceRequest.Room] {
        // Return rooms in the selected home
        return [
            MatterAddDeviceRequest.Room(displayName: "Living Room"),
            MatterAddDeviceRequest.Room(displayName: "Kitchen")
        ]
    }

    override func configureDevice(
        named name: String,
        in room: MatterAddDeviceRequest.Room?
    ) async {
        // Save the device configuration to your backend
        print("Configuring \(name) in \(room?.displayName ?? "no room")")
    }

    override func commissionDevice(
        in home: MatterAddDeviceRequest.Home?,
        onboardingPayload: String,
        commissioningID: UUID
    ) async throws {
        // Use the onboarding payload to commission the device
        // into your fabric using the Matter framework
    }
}

Common Mistakes

DON'T: Access homes before the delegate fires

// WRONG -- homes array is empty until delegate is called
let manager = HMHomeManager()
let homes = manager.homes  // Always empty here

// CORRECT -- wait for delegate
func homeManagerDidUpdateHomes(_ manager: HMHomeManager) {
    let homes = manager.homes  // Now populated
}

DON'T: Confuse HomeKit setup with Matter commissioning

// WRONG -- using HomeKit accessory setup for a Matter ecosystem app
home.addAndSetupAccessories { error in }

// CORRECT -- use MatterAddDeviceRequest for Matter ecosystem commissioning
let request = MatterAddDeviceRequest(
    topology: topology,
    setupPayload: nil,
    showing: .allDevices
)
try await request.perform()

DON'T: Forget required configuration

Matter ecosystem commissioning needs the MatterSupport extension, principal handler class, and Matter Bonjour services. Add the setup-payload entitlement only when your app provides setup codes directly.

DON'T: Create multiple HMHomeManager instances

// WRONG -- each instance loads the full database independently
class ScreenA { let manager = HMHomeManager() }
class ScreenB { let manager = HMHomeManager() }

// CORRECT -- single shared instance
@Observable
final class HomeStore {
    static let shared = HomeStore()
    let homeManager = HMHomeManager()
}

DON'T: Write characteristics without checking metadata

// WRONG -- writing a value outside the valid range
characteristic.writeValue(500) { _ in }

// CORRECT -- check metadata first
if let metadata = characteristic.metadata,
   let maxValue = metadata.maximumValue?.intValue {
    let safeValue = min(brightness, maxValue)
    characteristic.writeValue(safeValue) { _ in }
}

Review Checklist

  • HomeKit capability enabled in Xcode
  • NSHomeKitUsageDescription present in Info.plist
  • Single HMHomeManager instance shared across the app
  • HMHomeManagerDelegate implemented; homes not accessed before homeManagerDidUpdateHomes
  • HMHomeDelegate set on homes to receive accessory and room changes
  • HMAccessoryDelegate set on accessories to receive characteristic updates
  • Characteristic metadata checked before writing values
  • Error handling in all completion handlers
  • MatterSupport extension target and principal handler configured
  • Matter discovery NSBonjourServices entries added
  • com.apple.developer.matter.allow-setup-payload used only when providing setup codes
  • MatterAddDeviceRequest.isSupported checked before performing requests
  • Matter extension handler implements commissionDevice(in:onboardingPayload:commissioningID:)
  • Action sets tested with the HomeKit Accessory Simulator before shipping
  • Triggers enabled after creation (trigger.enable(true))

References

Related skills

More from dpearson2699/swift-ios-skills and the wider catalog.

IOios-accessibility logo

ios-accessibility

dpearson2699/swift-ios-skills

Build accessible iOS/macOS apps with VoiceOver, Voice Control, and assistive technology support.

2.7k installsAudited
IOios-localization logo

ios-localization

dpearson2699/swift-ios-skills

Localize iOS/macOS apps with String Catalogs, generated symbols, and locale-aware formatting.

2.4k installsAudited
IOios-networking logo

ios-networking

dpearson2699/swift-ios-skills

Modern iOS/macOS networking with URLSession, async/await, and structured concurrency.

2.5k installs
IOios-security logo

ios-security

dpearson2699/swift-ios-skills

Secure iOS apps with Keychain Services, CryptoKit encryption, biometric authentication (Face ID, Touch ID), Secure Enclave key storage, LAContext, App Transport Security (ATS), certificate pinning, data protection classes, and secure coding patterns. Use when implementing app security features, auditing privacy manifests, configuring App Transport Security, securing keychain access, adding biometric authentication, or encrypting sensitive data with CryptoKit.

1.1k installs
IOios-simulator logo

ios-simulator

dpearson2699/swift-ios-skills

Manages iOS Simulator devices and tests app behavior using xcrun simctl. Covers device lifecycle (create, boot, shutdown, erase, delete), app install and launch, push notification simulation, location simulation, permission grants via privacy subcommand, deep link testing via openurl, status bar overrides, screenshot and video recording, log streaming with os_log filtering, get_app_container paths, and #if targetEnvironment(simulator) compile-time checks. Use when creating or managing simulator devices, testing push notifications without APNs, simulating GPS locations, granting or resetting privacy permissions, capturing screenshots or screen recordings from the command line, streaming device logs, debugging simulator boot failures, troubleshooting CoreSimulator issues, or checking simulator hardware limitations.

1.2k installsAudited
MAmapkit logo

mapkit

dpearson2699/swift-ios-skills

Build map and location features in iOS/macOS apps with MapKit and CoreLocation async APIs.

1.7k installsAudited