Using Apple Homekit Mobile App

Updated: May 4, 2020

Time to cook: 90min

Difficulty: +++++




One of the platforms we covered in chapter 2 was HomeKit. An easy to use mobile APP for the connected world from Apple. In this recipe we cover the installation and configuration of HomeBridge which allows you to create your own HomeKit Accessory on a Raspberry Pi, Intel Edison, or any other platform that can run Node.js.


As an example we are going to control a Fibaro Smart Switch using HomeBridge and the Apple HomeKit APP.



 

Ingredients


Prerequisites


Tools

 

The Building plan


In this recipe, we are going to implement HomeBridge within a Node-RED evnvrionment and make use of the nodes contributed by Daniil Molchanov, crxporter and Shaq.


We will perform the installation on a Raspberry Pi. You can use the existing Home ‘HUB’ we already have set up or choose to use another RPI. The only condition is that you have Node-RED installed on it.


Installing HomeBridge


If you have not yet installed Node-RED then run the following command or go to Node-RED Installation Guide.


npm install -g --unsafe-perm node-red


Next, to install node-red-contrib-homekit-bridged node run the following command in your Node-RED user directory - typically ~/.node-red


npm install node-red-contrib-homekit-bridged


Alternative, you can install the Homebridge node via Pallette Within the Node-RED UI.


As a result, you should see Homekit Node in Node-RED




Configure HomeBridge to control the Fibaro Smart Switch


Now , let's create the flow which exposes the Fibaro Smart Switch as an Accessory to HomeKit.



The first node we put on the Flow is the HomeKit Node. As this will represent the Smart Switch, select ‘Parent’ as Service hierarchy and as service, select the ‘Switch’.




  • Next we need to configure the ‘Bridge’ which acts as a HomeKit emulator.



  • Select a recognisable name and set a PIN code. This will be used to add the bridge to your HomeKit APP on your mobile.



The other nodes we need in the flow is a Node which allows us to control the Fibaro switch.

  • Add an OpenHab2-out node and select the Zwave Smart Switch (see also recipe x) switch_binary item.

  • Select as Topic ‘ItemCommand’, as we want to actuate the Switch.




To control the Switch from HomeKit we need to ‘translate’ the payload. The convention HomeKit uses to control a Switch is:


Properties




while the Fibaro Zwave device expects the input ‘ON’ or ‘OFF’.


  • The accomplish this, add a JSON conversion node and a function node with the following code:


var state = msg.payload.On; if (state === true){ msg.payload = 'ON'; } else msg.payload = 'OFF'; return msg;


  • Wire everything up and deploy the flow.


Using the HomeKit APP


Now we have setup the Bridge and configured a first Accessory representing the Fibaro Smart Switch, Let's add the Bridge to our HomeKit APP on our mobile.


  • On Your IoS device, select the Home APP











  • Click on ‘+’ and select ‘Add Accessory’

  • Select ‘I don’t Have a Code or Cannot Scan’






  • Under Nearby Accessories, you should see your Bridge you have set up on the RPI. Select the Bridge





  • A popup appears to notify you that the Accessory you want to add is Uncertified. Select ‘Add Anyway’

  • Enter the Pin code, you have configured previous during the Bridge set up

  • Now the Bridge will be added with the Accessories it has configured. The Fibaro switch should be added in the Home APP.





  • By pressing the Button, the switch can be controlled.

  • A longer press, will show the switch and allow you to toggle it.







As you experience, it’s quite easy to add a device such as the Fibaro Smart Switch to HomeKit and use the HomeKit APP as a remote to control your device. Using the HomeKit APP, you can organize your device per room, invite other family members and setup Scenes.



2 views0 comments