Class

HMService

A controllable feature of an accessory, like a light attached to a garage door opener.

Declaration

class HMService : NSObject

Overview

An HMService instance represents a service provided by an accessory. Accessories have both user-controllable services, like a light, and services that are for the use of the accessory itself, like a firmware update service.

You don’t create services directly. Instead you find them in the services array of an HMAccessory instance.

A single accessory may have more than one user-controllable service. For example, most garage door openers have a service for opening and closing the door, and another service for the light on the garage door opener. These services are what Apple’s Home app labels as "accessories".

You inspect or change a service’s HMCharacteristic instances to discover state, or modify behavior.

Topics

Getting Service Characteristics

var characteristics: [HMCharacteristic]

An array of characteristics for the service.

class HMCharacteristic

A specific characteristic of a service, like the brightness of a dimmable light, or its color temperature.

Identifying the Service

var name: String

The user specified name of the service.

func updateName(String, completionHandler: (Error?) -> Void)

Updates the name of the service to the specified string.

var uniqueIdentifier: UUID

A unique identifier for the service.

Getting the Service Type

var serviceType: String

The type of the service.

Accessory Service Types

The service types supported by HomeKit.

var localizedDescription: String

The localized description of the service.

Reading Service Properties

var isPrimaryService: Bool

A Boolean value that indicates whether this service is the primary service on the accessory.

var isUserInteractive: Bool

A Boolean value that indicates whether this service supports user interaction.

Associating a Secondary Service

var associatedServiceType: String?

The type of the service associated with an outlet or a switch.

func updateAssociatedServiceType(String?, completionHandler: (Error?) -> Void)

Associates the service type of the plugged-in device with a switch or an outlet service.

Finding the Linked Services

var linkedServices: [HMService]?

An array of service objects that represents all the services to which the service links.

Getting the Service’s Provider

var accessory: HMAccessory?

The accessory that provides this service.

Relationships

Inherits From

Conforms To

See Also

Accessories

Interacting with a Home Automation Network

Find all the automation accessories in the primary home and control their state.

class HMAccessory

A home automation accessory, like a garage door opener or a thermostat.

class HMCharacteristic

A specific characteristic of a service, like the brightness of a dimmable light, or its color temperature.