<!--
{
  "availability" : [
    "iOS: 11.3.0 - 15.0.0",
    "iPadOS: 11.3.0 - 15.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "HomeKit",
  "identifier" : "/documentation/HomeKit/HMHome/addAndSetupAccessories(with:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HomeKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HMHome(im)addAndSetupAccessoriesWithPayload:completionHandler:"
  },
  "title" : "addAndSetupAccessories(with:completionHandler:)"
}
-->

# addAndSetupAccessories(with:completionHandler:)

Finds and adds nearby accessories to the home using a HomeKit code provided by your app.

```
func addAndSetupAccessories(with payload: HMAccessorySetupPayload, completionHandler completion: @escaping @Sendable ([HMAccessory]?, (any Error)?) -> Void)
```

## Discussion

Use this method to add accessories that have already been deployed (for example, accessories that have HomeKit support added as a firmware update), or accessories for which scanning a QR code would be difficult. Your app provides the accessory’s HomeKit code using a setup payload. For details on the payload’s content, please join the [MFi Program](https://developer.apple.com/programs/mfi/).

During this process, the user assigns the accessory to a room and configures its services.

## Topics

### Defining the Setup Payload

[`HMAccessorySetupPayload`](/documentation/HomeKit/HMAccessorySetupPayload)

A payload for authenticating a HomeKit accessory.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)