Looking for HomeKit sample code

I need some help with controlling accessories programmatically, not just by user interaction with the normal switches and sliders. I'm working on smart controls that, for instance, might open a window depending on some environmental variables.


I've been able to add my app into a view within HomeKit Catalog, so that's cool, but I cannot make the final connection where my decision-making app can take control and change the characteristics of an accessory; to turn on a light, change the thermostat setting, open a window, whatever. HomeKit is a relational database and I suppose I need to write to records in that database but it's not obvious (to me) how to do that, even after reading the developer guide. (One issue is that I'm trying to do this in Swift, and the developer guide is Obj-C.)

Seen anything like that?

The HomeKit Framework Reference (and most other "Reference" documentation) allows you to choose between Swift and ObjC (or to view both simultaneously) when looking at the class and protocol documentation.

https://developer.apple.com/library/ios/documentation/HomeKit/Reference/HomeKit_Framework/index.html


If you aren't familiar with ObjC at all, it is probably well worth the investment to spend a few days learning the basics. I suspect it will be WWDC 2017 before we see any public Apple frameworks written natively in Swift and being bridged to ObjC, so being able to understand and convert between the two will be a handy skill for a while.

I found a decent example here. It's similar to the HomeKit Catalog but is written mostly - if not completely - in Swift 2.0. I'm still lost but getting closer.


The thing that's hard for me to grasp is how I'm going to place a characteristic under control of my program. I'll use the browser examples to identify the service and characteristic that I want to place under control, but then I need to pass that information to my app, so that it will "know" to go open the window at home:service:characteristic.


What if I already "know" the details about a particular service and characteristic - can I skip all the browsing and choosing, and just hard code a statement to change the value of the characteristic?

Oh nuts, I just learned there's a newer version of Homekit Catalog here. All in Swift. This should keep me busy for a while.

New problem with the latest HomeKit Catalog, linked above: It builds and starts successfully in an iPhone 6 simulator (on iOS 9.) but it cannot browse accessories. I get the following error in the Macbook's system.log:


Jul 17 16:59:53 Waynes-MacBook-Pro homed[3273]: Accessory manager failed to start discovering accessories for server browser <HAPAccessoryServerBrowserBTLE: 0x7fe37b300080> with error Error Domain=HMErrorDomain Code=48 "Failed to power on Bluetooth because Bluteooth LE is unsupported on this system." UserInfo=0x7fe37b20f3e0 {NSLocalizedDescription=Failed to power on Bluetooth because Bluteooth LE is unsupported on this system.}

I didn't see that log file myself, but have the same issue. The App shows nothing for a home or accessories even though I have created a few in the HomeKit Accessory Simulator. The Simulator also looks different that what has been in the videos. I think they changed it or something that makes things not work anymore to be able to test your HomeKit code with.


Bummer


Mark

Looking for HomeKit sample code
 
 
Q