This script interfaces with homebridge to expose a relay to Apple's HomeKit, allowing you to integrate numerous devices into your smart home.
-
NodeMCU
-
Relay Module
-
Pin header cables
-
Micro-USB cable
-
First, follow this gist which walks you through how to flash a NodeMCU using the Arduino IDE. The
.ino
file referred to is theNodeMCU-Relay.ino
file included in this repository -
Assuming that you already have homebridge set up, the next thing you will have to do is install homebridge-http using the command:
npm install -g homebridge-http
- Finally, update your
config.json
file following the example below, making sure to adapt it accordingly:
"accessories": [
{
"accessory": "Http",
"name": "Lights",
"on_url": "http://relay.local/SWITCH=ON",
"off_url": "http://relay.local/SWITCH=OFF",
"http_method": "GET"
}
]
As you can see from the config.json
example above, the basic format of the HTTP request is the IP address of your NodeMCU followed by the action you wish to execute.
Here is a table which shows you the available relay actions included with the NodeMCU-Relay.ino
script in this repository which can be included in the config.json
to control different types of appliances:
Name | Full URLs | Description | Example Uses |
---|---|---|---|
Switch | relay.local/SWITCH=ON relay.local/SWITCH=OFF |
Will simply turn on/off the relay permanently as per the Home app. | Lights, Faucets, Fans |
Momentary | relay.local/MOMENTARY=ON relay.local/MOMENTARY=OFF |
Will activate the relay for a brief moment, then deactivate after the amount of time specified in the NodeMCU-Relay.ino script. |
Garages, Gates, Buzzers |
Modulation | relay.local/MODULATION=ON relay.local/MODULATION=OFF |
Will activate then deactivate the relay constantly for the amount of time specified in the NodeMCU-Relay.ino script until turned off. |
Lights, Sprinkler systems |
State | relay.local/status |
Will return current state as 0 or 1 |
N/A |