Introduction: Sonoff Garage Door Opener
I have been playing around with the nodemcu devices for some time now but found these Sonoff devices about 6 months ago and have made a number of projects with them now. This project involved a modification so i thought it different than normal and thought i would share it.
My need was for a simple to add device that would integrate with my home automation system and would allow control of my garage door with out having to run additional wires to or from the ceiling unit or wall button.
After tracing the Sonoff circuit board I found this wouldn't be that hard with one of these cheap devices with a simple modification.
The Sonoff units take mains power at one end and delivers switched mains power at the other, internally they have a small transformer to run the ESP8266 device and a 10amp relay to switch the power.
My garage door like most has a low voltage pair of connectors that run to a button on the wall and when connected with a button press opens or closes the door, this is what i needed to make the Sonoff do.
Parts Needed:
Step 1: Starting With the Sonoff Device
These devices can be purchased from Aliexpress for a few dollars, looking at the circuit inside you can see the circuit that carries the mains power down from the input through the relay down to the output.
Step 2: Modification
A small cut using a dremel or hack saw is cut down the side of the relay disconnecting the relay from the mains power for both phase and neutral.
Step 3: Circuit Completion
Then a small run of solder is completed across the two points making the relay just close the end contracts.
At this point you should be sure to test this and confirm there is no connection between the mains and the non mains ends. If you don't test this or check this you could still be passing mains down to device which could cause damage or worse give you a big shock.
Step 4: Flashing the Sonoff With the EasyESP Image
There is plenty of information online to do this image replacement and it can be found in detail here:
https://www.letscontrolit.com/wiki/index.php/ESPEa...
https://rutg3r.com/sonoff-firmware-tutorial-to-esp...
Basically you need to connect a USB header device to the Sonoff header pins and reflash the ESP8266 with the new EasyESP image replacing the factory image. This turns the device into a device that will talk to your home automation system not just the phone app that comes with the Sonoff devices. There is a lot of information on line on doing this and dont worry if you flash it and it doesn't seem to work the first time as its very hard to break the device here as you can always reflash the device again and again to get it working. I have found the process to be very easy and reliable.
EasyESP is a great image to deploy, i use to write code for these nodemcu devices and spent hours doing this where i found using this image needed no coding skills at all and was all just configured in the web interface.
Step 5: Connecting the Contact Sensor
Next I purchase a small case and gland for the power cable plus a magnetic contact to detect when the door is open or closed. A 8mm hole was drilled in the end of the case which was a perfect size for the contacts metal cable end to fit snugly. I then soldered the two wires on the end two connections on the header holes. These are ground and GPIO14 pins which is where the unit was flashed earlier.
At this point i have also drilled a second hole for the relay contact wire to connect to the relay terminals and also installed a gland for the incoming power supply.
Step 6: Configuring the EasyESP Image
This step is where you power up the Sonoff device and it will appear as a ESP_0 access point which you connect to on a phone or tablet etc and configure it to connect to your home network. Once you have completed this you can configure it.
There are only a few places you need to configure the unit to enable this. Setup the devices the same as the images show and setup the rules as below as this is the part that presses the button for 1 second and also sends the MQTT so my home automation knows when the door is open or closed. You can remove the two on sensor#switch do rules if you dont want to publish to an MQTT server for OPENHAB.
RULES:
on System#Boot do
gpio,12,0 // Prevent relay turning on during boot endon
on relay1#switch do
if [relay1#switch]=1
timerSet,1,1 // 1 second timer
endon
on Rules#Timer=1 do
gpio,12,0 // Turn off relay
endon
on sensor#switch do
if [sensor#switch]=1
publish /house/garage/garagecontact,CLOSED
endon
on sensor#switch do
if [sensor#switch]=0
publish /house/garage/garagecontact,OPEN
endon
Step 7: OPENHAB Integration
I have integrated mine into my openhab setup but you can simply send the command:
HTTP://YOUR_SONOFF_IP/control?cmd=GPIO,12,1
My OPENHAB settings are as follows which work well, you will need to change this for your MQTT server etc.
Default Items:
Switch Garage_Button "Garage Door Button" (All) { autoupdate="false",http=">[ON:GET:http://YOUR_SONOFF_IP/control?cmd=GPIO,12,1:GO]" }
Contact GarageDoor2 "Garage Door Status3 [MAP(en.map):%s]" { mqtt="<[openpowermqtt:/house/garage/garagecontact:state:default]"}
Default SiteMAP:
Text item=GarageDoor2
Switch item=Garage_Button mappings=[ON="Go"]}
en.map file
CLOSED=Closed
OPEN=Open
Step 8: Mounting the Unit
My unit attaches to the top of my door opener, there is a power socket there already and i connect the terminals for the button and fit the sensor to the ceiling. The Magnet was hotglued to the top of the door opening unit. The magnetic switch has a large range (about 5cms) so it does not need to be real close to the sensor to active it.
If your door is different you can modify yours to suite and lengthening the cable etc to get a point that changes with the door opening or closing.

Participated in the
Wireless Contest
74 Comments
1 year ago
Not sure which version of the switch this is but the trick still works if you are careful. Two cuts (orange arrows) with my dremel and an extra wire soldered on. You have to cut all the way through the board making the second cut quite tricky (in the end I used a knife to complete it). I checked there was no connection using a multimeter then soldered in the blue wire. It works perfectly. Thanks so much for this instructable which was fun and rewarding.
Reply 4 weeks ago
Hi Omdaddi, are you able to share more photos of your solution?
Reply 4 weeks ago
That's the only one I have I am afraid, just the two cuts and the soldered wire.
Reply 24 days ago
Ok no stress, and just to confirm this is working on your garage motor all fine? Seems there are two different versions of the SONoFF R2 Basic, one with two wires (I have a fix for this), but the one with one wire seems to be the newer batch that I just ordered
Reply 24 days ago
My solution is just adding a second way to toggle the switch that opens my gate. I can imagine that a garage might be the same? Especially if it's a sprung toggle switch.
Question 2 years ago on Step 7
Can you show your openHAB rules file?
Answer 2 years ago
There is no openhab rule file needed. The sonoff turns off after a second so this updates openhab that its off
Reply 2 years ago
Thanks. I didn't realise that a post below showing console commands included PulseTime. That's the command that causes the relay in inching mode.
Tip 3 years ago
I have a newer Sonoff Basic (says on the PCB "Sonoff RF R2 Power v1.0"). The trick to cut the board won't work anymore. Not because they used wires instead of traces, the board design is done to make it really hard to isolate the input from the relay. In more detail, the fuse F1 which provide power to the ESP SoC is placed in a tricky location (it's tied to the relay). If there is enough interest, I could post my solution later.
Reply 3 years ago
I would be interested. only a new kind of sonoff basic can be taken
Reply 3 years ago
sorry for the late reply. Attached top and bottom photos of my modified version. It would be nice if someone can post a unmodified board to see the differences. It's fully working with my garage door. I plan to add open/close sensor later.
Reply 3 years ago
Sharing is caring so I figured I'd give something back to the community for this interesting read. Attached are the pictures of the latest, unmodified Sonoff Basic module (PCB "Sonoff RF R2 Power v1.0") which I bought on Banggood earlier this month. The module indeed has wires instead traces.
@wildwildwilliam: what did you modify exactly?
Reply 3 years ago
Now it's 2020, time to reply :)
You have probably figured out by now. I cut the board, replaced one of the wire, relocated the fuse F1. Basically, the relay is only switching the low voltage side instead of the hot line.
Reply 3 years ago
Thank you! works perfect!! I'm looking forward to installing the sensor, physically built in, but I can't adjust it in my tasmota.
3 years ago
I have the newer RF R2 POWER V1.0 with the wires instead of the traces and followed the instruction of arossetti1976 using a polarized plug. Worked perfectly without any modification to the board. The only thing I have not done yet is add the sensor since it looks like GPIO14 is no longer an option. I am seeing posts that suggest using GPIO3 instead so will be investigating that option.
Reply 3 years ago
I think doing that trick may not work / safe depending on the electrical panel design, just for the record.
Reply 3 years ago
GPIO3 does work as expected. Obviously, the trade-off is serial programming since you won't be able to plugin directly to the board once GPIO3 is used for the sensor, but once the device if fully setup, you should not need to plug directly in any longer.
3 years ago
Hi, is it possible to make an instructable with a sonoff r3 rf to make a dry contact? I can not find any tutorial on internet about a r3
Reply 3 years ago
I dont have one if if this link is correct then its the same process you just need to cut the mains links and join them on the non live side.
https://forum.creationx.de/forum/index.php?thread/1940-info-sonoff-basic-r3-und-basic-rfr3/
3 years ago on Step 6
I do have the new rev board with AC wires instead of the traces modified and working fine in my garage. How do I add GPIO14 to that board?
Also, does eWeLik have the option to read sensor status? if not, which app would you recommend.
Thanks