4 months ago I finished the last hardware part of my automatic curtains. And as mentioned in that post, the final step in finishing up this project, is developing an iPhone app. But let’s face it: using an App to control the curtains is simply too cumbersome. There must be a better way …
With the avant of iOS 10, Apple has focussed on improving HomeKit. If you’re new to HomeKit, this is how Apple describes it:
HomeKit is a framework for communicating with and controlling connected accessories in a user’s home. You can enable users to discover HomeKit accessories in their home and configure them, or you can create actions to control those devices. Users can group actions together and trigger them using Siri.
So, controlling my curtains using HomeKit would be a better approach than writing an App. If my curtains communicate using HomeKit, not only would it allow me to control my curtains using Apple’s Home app, but also using many other Apps allready available in the AppStore. More importantly, I would be able to control my curtains using Siri: “Hey Siri, could you please open the curtains?”
To officially intergrate HomeKit into my curtain system, I would need to register for the Apple MFi licensing program. A costly certification which would not make sense for any home brewed project. Luckily, there are many open source projects that mimic the features of a HomeKit Accessory Server. They might not fully follow the HAP MFi Specification, but they do the job.
Currently, the two most well known Node.js implementations of a HomeKit are:
Both systems allow you to implement your own accessory using their API’s. In my case, this would mean I need to write some sort of bridging module, that converts the HomeKit commands into MQTT messages. Since MQTT is the protocol I use for my curtains (and all my other home sensors).
As I learned in the past, it’s always a good idea to check if someone already wrote the piece of code you’re about to write. And so I was very thrilled to see that a good fellow named Sebastian Raff has put a lot of time in an awesome open source project, named homekit2mqtt.
This system only needs one simple JSON-configuration file to get my curtains up and running on HomeKit:
{
"WindowCovering1": {
"service": "WindowCovering",
"name": "Gordijn 1",
"topic": {
"setTargetPosition": "/curtains/curtain_1/target",
"statusTargetPosition": "/curtains/curtain_1/target",
"statusCurrentPosition": "/curtains/curtain_1/state"
},
"payload": {
"targetPositionFactor": 10.24,
"currentPositionFactor": 10.24
},
"manufacturer": "Generic",
"model": "WindowCovering"
},
// repeat the section above for the 3 other curtains ...
}
Note: Gordijn is the dutch word for Curtain.
The configuration above is pretty self explanatory. The only two value’s that might need a little explanation, are the two 10.24 factors: my curtain system has a range of 0 (closed) to 1024 (open). HomeKit uses a range of 0 (closed) to 100 (open). By setting the factor to 10.24, all HomeKit values are multiplied by 10.24 resulting in values my curtain system can use. Details like this really show the amount of work Sebastian has put into this project.
And with the above in place, I could start the homekit2mqtt instance. Of course, this application needs to run on an always-on computer. Luckily, the Raspberry Pi in Magic Mirror has some CPU power to spare.
So with a little help of Sebastian, I got it up and running, and I’m now able to control my self built atomatic curtains using Siri! Additionally I made some favorite scenes that allow me to control the curtains from the iOS Control Panel.
Welcome to the future!