esp8266-arduino-homekit-switch
esp8266-arduino-homekit-switch copied to clipboard
Using an ESP8266 as a switch with native Apple HomeKit support
ESP8266 Arduino HomeKit Switch
Using an ESP8266 as a switch with native Apple HomeKit support
Demo/Preview

Start/Setup
Initial
On the first startup, the ESP8266 creates an open access point with the name ESP_Switch_AP. Further functionalities are blocked at this time.
Connect with your network
Connect to the public access point. A portal appears where you can search for existing Wifi networks and connect with them. Once you have entered the credentials, the ESP8266 will restart and connect as a client to the selected Wifi network. If a connection is not possible, e.g. due to wrong credentials or a timeout, the ESP8266 will restart as an access point again and the connection credentials can be re-entered. At this point the output can now be toggled with the connected/flash button.
Add to HomeKit
As soon as the ESP8266 is connected to the network, the Home app can be opened on the iOS device and be added as a new device.#
Paring Code
For the paring the following code has to be entered: 111-11-111.
Alternatively, the following QR code can be scanned:

Wiring

Pins
| Label | GPIO | Property |
|---|---|---|
| D4 | GPIO 2 | Output |
| D5 | GPIO 14 | Input to toggle in parallel to the onboard Flash button |
Workspace
Local Development
Required
- Arduino v1.8.13
- Additional Board Manager:
https://arduino.esp8266.com/stable/package_esp8266com_index.json- esp8266 by ESP8266 Community v2.7.4: https://github.com/esp8266/Arduino
- Libraries:
- HomeKit-ESP8266 by Mixiaoxiao v1.2.0:
https://github.com/Mixiaoxiao/Arduino-HomeKit-ESP8266 - WifiManager by tzapu v0.16.0:
https://github.com/tzapu/WiFiManager
- HomeKit-ESP8266 by Mixiaoxiao v1.2.0:
- Additional Board Manager:
- Python 3.9
- pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py- esptool v3.0
pip install esptool - pyserial v3.5:
pip install pyserial
- esptool v3.0
- pip
Optional
- VSCode
- (Extension) Arduino v0.3.4:
https://github.com/Microsoft/vscode-arduino- Update values of
inlcudePathin.vscode/arduino.jsonto match you environment
- Update values of
- (Extension) Arduino v0.3.4:
Further Configuration
In-/Output
The following definitions can be changed to modify the pins of the inputs and outputs.
Keep in mind the basic properties of the pins, because not every pin can be used as input and output.
// switch.ino
#define PIN_BUTTON 14 // D5 Button
// accessory.c
#define PIN_SWITCH 2 // D4 Output to trigger on/off
Additional Inputs
// switch.ino
void homekit_setup() {
accessory_init();
pinMode(PIN_BUTTON, INPUT_PULLUP);
pinMode(PIN_BUTTON_FLASH, INPUT_PULLUP);
+ pinMode(PIN_BUTTON_DX, INPUT_PULLUP);
ESPButton.add(0, PIN_BUTTON, LOW, true, true);
ESPButton.add(1, PIN_BUTTON_FLASH, LOW, true, true);
+ ESPButton.add(2, PIN_BUTTON_DX, LOW, true, true);
...
}
Paring Code
Change the property .password to use a different paring code
// accessory.c
homekit_server_config_t config = {
.accessories = accessories,
- .password = "111-11-111",
+ .password = "123-45-678",
.setupId = "ABCD"
};
To create a new QR Code the following page can be used: https://github.com/maximkulkin/esp-homekit/tree/master#qr-code-pairing
Requirements:
- Python 3.9
- pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py- qrcode v6.1:
pip install qrcode
- qrcode v6.1:
- pip:
If the accessory category is still a switch, the following terminal command can be entered to execute the Python script and create a new QR code:
# tools/gen_qrcode <accessory category code> <password> <setup id> <output filename>
tools/gen_qrcode 8 123-45-678 ABCD qrcode.png
Verify & Upload
Select the appropriate port (e.g. /dev/tty.usbserial-1234) and Baud Rate 115200 and start the verification and upload in the switch.ino file in VSCode
Author
Simon Golms
- Digital Card:
npx simongolms - Github: @SimonGolms
- Website: gol.ms
Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show Your Support
Give a ⭐️ if this project helped you!
License
Copyright © 2020 Simon Golms.
This project is MIT licensed.