Turn an LED connected to a BLE capable microprocessor into a wireless HomeKit lightbulb. Use the Home app or Siri on your Apple device to switch it on and off.
This example uses Arduino 101 and Raspberry Pi 3. Generally, any programmable BLE peripheral and a box capable of running Node.js with Noble will work.
Download and install the latest version of the Arduino IDE. If you're totally new to microcontrollers take some time to go through an introductory tutorial and learn how to make a LED blink. This will help you to understand how to use the IDE, how to upload a sketch and what is the code actually doing.
Connect the LED to pin 13. The LED has to have a resistor in series to limit the current passing through - max current per I/O pin is 20 mA. Generally, anything between 100 and 1k Ohms will do. If you're lazy you can also skip the wiring and use the onboard LED connected to pin 13.
Note Alternatively, you can use any of the many BLE boards available on the market (BlueBean, RedBearLabs BLE Nano, ...) as long as you keep UUIDs of the services and characteristics in sync with your config.json
file, everything will work just fine.
Compile, run and upload the arduino101.ino sketch using the Arduino IDE. The sketch creates a BLE service with a readable, writable and notifiable characteristic for on/off state.
BLEService lightbulbService("8E76F000-690E-472E-88C3-051277686A73");
BLECharCharacteristic onCharacteristic("8E76F001-690E-472E-88C3-051277686A73", BLEWrite | BLERead | BLENotify);
Take a look into this file to see the full definition of the On characteristic used in the Lightbulb service. Once the BLE central device is setup, it connects to this characteristic and exposes it via Homebridge as a HomeKit accessory of type Lightbulb.
Leave the device powered on and the sketch running while you setup the Homebridge server. The sketch has some built-in logging, so keeping the Serial monitor open may be helpful for debugging.
For help installing an operating system on your new Pi, the official documentation contains a couple of nice videos.
No wiring except for the micro-USB cable providing power is needed. The Pi needs to be connected to the same router (subnet) as the Apple device you plan to use. It doesn't matter whether via Wifi or Ethernet. Otherwise, you won't be able discover and connect to the Homebridge server running on the Pi.
Note Alternatively, you can use a Raspberry Pi 2 with a supported USB BLE dongle instead of the Pi 3.
Running Homebridge on a Raspberry Pi is straightforward. Follow this guide to install Homebridge server and then run the following command to install the homebridge-bluetooth plugin:
[sudo] npm install -g homebridge-bluetooth
Edit the ~/.homebridge/config.json
, name your Homebridge server and add a new accessory to allow the plugin to connect to the BLE service running on the Arduino:
"name": "Arduino",
"address": "01:23:45:67:89:AB",
"services": [ {
"name": "LED",
"type": "Lightbulb",
"UUID": "8E76F000-690E-472E-88C3-051277686A73",
"characteristics": [ {
"type": "On",
"UUID": "8E76F001-690E-472E-88C3-051277686A73"
} ]
} ]
Finally, start the Homebridge server. If you use Linux you may need to run with higher privileges in order to have access to the BLE hardware layer. See this link for more details about running without sudo
.
[sudo] homebridge -D
Note Running with -D
turns on additional debugging output that is very helpful for getting addresses and UUIDs of your BLE devices that needs to match with the config.json
file.
Note Homebridge server doesn't run only on Linux. MacOS and Windows machines are also supported given they have a built-in BLE adapter or an USB dongle. For more details see supported platforms of Homebridge and Noble.
Open Home app and tap the '+' button to add new accessory. When you attempt to add the 'Raspberry Pi 3' bridge, it will ask for a "PIN" from the config.json
file. Once you are paired with your new Rapsberry, Homebridge server all the connected BLE accesories can be added the same way as the bridge.
Once your BLE accessory has been added to HomeKit database, besides using the Home app or Control Center at the bottom of the screen, you should be able to tell Siri to control any HomeKit accessory. Try "Hey Siri, turn on LED". However, Siri is a cloud service and iOS may need some time to synchronize your HomeKit database to iCloud.