I bought two of those cheap wifi remote controlled switches called Sonoff.
These switches allow you to turn them on and off with an app on your phone.
Inside these switches are a ESP8266 , which means that we can flash the chip with our own custom firmware.
And with the help of a Raspberry pi we can enable homekit.
Firstly I reflashed the sonoff with my custom firmware, using the Arduino IDE. (Google how to flash ESP8266)
(This disables the use of the official sonoff app)
Remember to change the hostname, if you have multiple sonoff.
#define HOSTNAME "sonoff_00"
Raspberry Pi – Homebridge
Download and install Raspbian on the Raspberry Pi.
When this is done we can install Homebridge, which is the service that sits between your apple devices and the sonoff switch.
The full install guide can be found here:
TLDR; (Raspberry Pi 3)
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git make
sudo apt-get install g++
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
#install Avahi and other dependencies
sudo apt-get install libavahi-compat-libdnssd-dev
Next we need to install Script2, which is a homebridge plugin that allows you to run bash-scripts though the homebridge
npm install -g homebridge-script2
Start at bootup
Lastly we need to start Homebridge whenever the Raspberry pi boots up.
And the following method was found here:
We need to create the following two files.
# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)
Description=Node.js HomeKit Server
#could be /usr/local/bin/homebridge - check where the homebridge folder exists
And to enable the newly created service. (first time only)
sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge
We also need to create a new user and the folder for the config.json file
#create a new user
sudo useradd -M --system homebridge
#creates a new folder
sudo mkdir /var/lib/homebridge
#changes the owner of the folder to new homebridge-user
sudo chown homebridge:homebridge /var/lib/homebridge
To configure the script2, we need to create a config.json file in the /var/lib/homebridge folder.
Mine looks like this:
"username": "AA:BB:CC:DD:EE:FF", (THIS NEEDS TO BE CHANGED)
"pin": "XXX-XX-XXX" (THIS NEEDS TO BE CHANGED - WITH NUMBERS)
"description": "Sonoff Homebridge",
"name": "Bedroom lamp",
"on": "curl http://sonoff_00.local/on",
"off": "curl http://sonoff_00.local/off",
"state": "curl --max-time 1 http://sonoff_00.local",
"name": "Living room lamp",
"on": "curl http://sonoff_01.local/on",
"off": "curl http://sonoff_01.local/off",
"state": "curl --max-time 1 http://sonoff_01.local",
Restart the homebridge service
sudo systemctl restart homebridge
Now you should be able to add the sonoff homebridge to your Home-app on the iphone/ipad, and control the switches.