How To Get Started with Apple HomeKit

HomeKit is Apple’s entry into the smart-home arena. Following in the footsteps of Google’s recently acquired Nest system (as well as Google’s seemingly forgotten Android @Home initiative), Apple now provides an SDK as well as certification for smart devices in a more contextually aware home.

Apple announced HomeKit back in June, during its annual WWDC conference. The system will allow users to seamlessly hook up smart devices via Bluetooth or Wi-Fi. What will this look like in your home? Well, imagine everything from a toaster than can alert you when your bagel has popped up to a system that adjusts the lighting and turns on the television when you enter a room.

As with its HealthKit, the focal point of Apple's HomeKit initiative is a unifying protocol--standardization via a singular SDK--to act as the conduit for devices or gadgets to communicate with iOS. This goes along with the consistent theme we have seen in iOS 8 and OSX Yosemite: contextual awareness through technologies such as Continuity or handoff. Via HomeKit, smart devices know when you are in a room, when you are going to use something and when you are finished using something--and take action accordingly.

Building the Home of the Future

We don't expect HomeKit to explode in popularity and use--at least not right out of the gate--but Apple's (and Google's) weight will certainly go a long way toward boosting the smart home market.

Homekit

Apple has given us the SDK; now all we have to do is figure out what to do with it--that is, coming up with creative ways of unifying home appliances and gadgets with iOS. There are some obvious candidates for "smart-enablement," in the home, including thermostats, garage door openers and cameras. But developers should also think outside the box--perhaps working to build an automated pet feeder or backyard grill.

Developers should also be keeping in mind future Apple TV software, as well as the much-awaited release of the Apple Watch (slated to arrive in 2015). Both of these systems will have some sort of interaction potential with HomeKit, paving the way for more interesting and contextual apps and projects.

For our pet how-to project, we will actually create a pet feeder (pun intended)--a hypothetical accessory that stores pet food, sets storage temperature and dispenses food to your dog or cat.

Getting Started

Class Hierarchy

It’s important to first familiarize yourself with the various classes that are part of HomeKit, and understand how each class and subclass relate in the hierarchy.

The most prominent class is HMHomeManager, which represents a collection of one or more homes (locations). Within that collection, each house is represented by an HNHome, with each room represented by an HNRoom.

Hierarchy

Each room can contain one or more accessories (HMAccessory), which are the actual physical home automation item.

Looking at the individual Accessory (HMAccessory), it would normally expose or provide a service (HMService) such as "roll down the garage door" or "turn on the security camera." Services belonging to an Accessory are grouped as a HMServiceGroup, making it easy to address accessory services as a single logical entity.

HomeKit diagram 2

Accessories are also organized according to zones (HMZone). This allows developers to group parts of the home according to different locations, such as kitchen or second floor. This provides indicative metadata to allow you to direct communications toward a certain area of the home. (This also plays in well with Apple's Siri voice-enabled app, which will become evident later on.)

Finally, each service is made up of specific attributed characteristics (HMCharacteristic), which expose certain properties for interaction--such as a Boolean (on or off, yes or no), string or floats--to signify a certain state of the service (for example, whether it's turned on or what the current temperature of the accessory is).

Classes

(Source: Apple Dev)

Class

Abstract

NSObject

NSObject is the root class of most Objective-C class hierarchies.

HMAccessory

An HMAccessory object represents a home automation accessory in the home, such as a garage door opener or a thermostat.

HMAccessoryBrowser

An HMAccessoryBrowser object is a network browser used to discover new accessories.

HMAction

HMAction is an abstract base class for actions in Home Kit.

HMCharacteristicWriteAction

An HMCharacteristicMetadata object is used to represent an action in an action set that writes a value to a characteristic.

HMActionSet

An HMActionSet object represents a set of actions (instances of HMAction) to be applied as a single set.

HMCharacteristic

An HMCharacteristic object represents a specific characteristic of a service—for example, if a light is on or off, or what temperature a thermostat is set to.

HMCharacteristicMetadata

An HMCharacteristicMetadata object represents metadata for a characteristic.

HMHome

An HMHome object allows you to communicate with and configure the different accessories in a home.

HMHomeManager

A home manager object manages a collection of one or more homes.

HMRoom

An HMRoom object is used to represent a room in a home.

HMService

An HMService object represents a service provided by an accessory.

HMServiceGroup

An HMServiceGroup object represents a collection of accessory services, making it easier to address the services as a single entity.

HMTrigger

An HMTrigger object represents a trigger event, used to trigger one or more action sets (instances of HMActionSet) when the conditions of the trigger are satisfied.

HMTimerTrigger

An HMTimerTrigger object represents a trigger based on periodic timers.

HMUser

An HMUser object represents a person in the home who may have access to control accessories and services in the home.

HMZone

An HMZone object represents a collection of rooms that the user thinks of as a single area or zone—for example, “Living Room” and “Kitchen” might be grouped into a zone called “Downstairs”.

Protocols

Protocol

Abstract

HMAccessoryBrowserDelegate

HMAccessoryBrowserDelegate defines the interface for an HMAccessoryBrowser object to notify its delegate of new accessories.

HMAccessoryDelegate

The HMAccessoryDelegate protocol defines the communication method for state updates from accessories to their delegates.

HMHomeDelegate

The HMHomeDelegate protocol define the communication method for configuration changes to a home and for the state of executing action sets in the home.

HMHomeManagerDelegate

The HMHomeManagerDelegate protocol defines how home manager objects communicate changes to their delegate.

Setting Up the Environment

We are building a simulated accessory, so we will use HomeKit’s Accessory Simulator, which comes bundled with XCode. (The system may prompt you to download it if it hasn’t been downloaded already; it can be accessed as follows: Choose Xcode > Open Developer Tool > HomeKit Accessory Simulator.)

To add the pet feeder device to the simuator, select Add and choose New Accessory. Then, set its properties, from manufacturer to serial number:

HomeKit screen 1

You will then be presented with:

HomeKit screen 2

During our tests, we then set the Service to expose a switch that would determine whether the feeder is On or Off. (Set to On during vacation, of course).

Service

Next, we set Characteristics, which let us control the accessory. We started by setting up the ability to control the temperature of the device.

Temperature

We added another Characteristic that will let users read the temperature of the accessory.

final screenshow

We set up a custom Characteristic type, setting float as the type format for Celsius. We also set maximum and minimum temperature points, as well as the step value (or incremental value). We used a freely available online generator for the UUID, but you can also use the NSUUID class in Cocoa to generate a unique identifier.

Easy enough, right? We'll cover the coding aspects of HomeKit in greater detail in How to Code the Home of the Future with HomeKit.

Doron Katz A keen passion for emerging technologies, practices and methodologies, Doron embraces the vision of lean development with continuous customer development. Consultant for various startups, as a Project and Product Manager, with a mobile engineering background in iOS, and over 10 years of professional web development experience.

Comments

Comments(3)

nader.gharsallaoui

can you update your post :

-the HomeKit Accessory Simulator is not included with xcode 

-to add the HomeKit framework to the project youn need to have a payed accounts