This is a fork of a nice plugin. Because I'm not smart enough for Github, I forked it. The perfect solution would be an integration of the changes and extensions I did into the original plugin. But hey… I can do some coding, but that Github-Universe is bejond my capabilities…
Main changes: you can choose which Type the device is (outlet, lightbulb) which is optional. I changed the timeout values to more realistic ones. The plugin now gives a proper "no answer" if there is a timeout. The original one just reported the last known state which is mislading.
This is Sonoff basic plugin for Homebridge. You will need some soldering works to gain access to flash ESPEasy firmware.
-
Switch on / off.
You can now ask Siri to turn on / off any device!
Sonoff Basic | Soldering Iron Pen | Header Pins |
Tin Lead Rosin Core (<0.5mm) | Female-to-female Dupont Wire Cables | TTL to USB Adaptor |
Notes: You can easily get these hardware from eBay at cheap price.
-
Open the case of Sonoff and take out the board.
-
Lay it on the table and solder 5 header pins as show in the picture below. WARNING: Please make sure the switch is not connected to live socket.
-
Plug in the four dupoint wires.
-
Connect the wires to TTL to USB adaptor.
The correct position is as following:
- Red: 3v3
- Green: TXD
- Yellow: RXD
- Blue: GND
**Notes: ** Some TTL to USB adaptor may not working in this way. If the device is not connected correctly, swap the position of Green (TXD) and Yellow (RXD) wire.
-
Download ESPEasy R148 firmware from here. This is the version that works perfectly with Sonoff basic. I was facing serious connection issue when I flashed with R120 firmware as recommended in the official website.
-
Unzip the downloaded package.
-
Press and hold the button on Sonoff basic, plug the TTL to USB adaptor to PC. Release the button once plugged.
-
Press
WIN
+R
on keyboard and typedevmgmt.msc
to open device manager. Check under Ports (COM & LPT) section to find out the COM port used by the adaptor.
-
Press
WIN
+R
on keyboard and typecmd
to open command line. -
Go the folder where ESPEasy located.
-
Execute the
flash
to start flashing the firmware into Sonoff. -
Enter following details when prompted.
**Notes: ** Comport is the port you got from Step 8.
-
Wait around 3~5 minutes. You should see following output when firmware is successfully flashed.
-
Unplug the USB and plug in again to let Sonoff reboot.
-
Wait about 3~5 minutes and Sonoff will creates a new Wi-Fi access point called ESP_0.
-
Connect your PC to the network with password
configesp
. -
Open web browser and go to
http://192.168.4.1
. -
Go through the setup to connect Sonoff to your Wi-Fi network.
-
[Optional] The design of ESPEasy web interface is really hurting my eyes. I have customized a style sheet here. Go to
Tools
>Settings
>Load
, upload the esp.css to change the interface. -
Now, go to
HARDWARE
section, select GPIO-13 (D7) for Wifi Status Led to enable the green LED light on Sonoff. Submit the changes. -
Go to
DEVICES
section, editTask #1
. Insert the values as the picture below and submit.
-
Edit
Task #2
, insert values as picture below and submit.
-
We have enabled the hardware GPIO to work, now we need to configure the rules for HTTP request.
-
Go to
RULES
section, insert the following codes and submit.On PowerOn Do gpio,12,1 EndOn On PowerOff Do gpio,12,0 EndOn On Button#State Do If [Button#State] = 0 gpio,12,0 gpio,13,1 Else gpio,12,1 gpio,13,0 EndIf EndOn
The codes above contains 3 sections. The
PowerOn
part is to turn on the switch,PowerOff
part is to turn of the switch.Button#State
is the part to handle the physical button on Sonoff, so you can toogle the button to turn on/off the switch. -
Finally, the Sonoff basic switch is fully customized. Connect it to a live socket.
-
Install required packages.
npm install -g https://github.com/pbksol/homebridge-sonoff-basic-espeasy-pbk request
-
Add following lines to
config.json
."accessories": [ { "accessory": "SonoffBasicESPEasyPBK", "name": "Living Room Switch", "ip": "IP_ADDRESS_OF_THE_SONOFF_BASIC" } ]
There is in optional setting "switchType" to show the Sonoff as an outlet or lightbulb.
"accessories": [
{
"accessory": "SonoffBasicESPEasyPBK",
"name": "Living Room Switch",
"ip": "IP_ADDRESS_OF_THE_SONOFF_BASIC",
"switchType": "outlet|lightbulb"
}
]
-
Restart Homebridge, and your Sonoff basic a will be added to Home app.
See the LICENSE file for license rights and limitations (MIT).