Sonoff Garage Door Opener

48,321

59

58

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:

SONOFF

Magnetic Contact

Case

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.

Wireless Contest

Participated in the
Wireless Contest

Share

    Recommendations

    • Indoor Lighting Contest

      Indoor Lighting Contest
    • Make It Fly Challenge

      Make It Fly Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    58 Discussions

    0
    None
    wildwildwilliam

    Tip 7 weeks 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.

    3 replies
    0
    None
    zoral566wildwildwilliam

    Reply 5 weeks ago

    I would be interested. only a new kind of sonoff basic can be taken

    0
    None
    wildwildwilliamzoral566

    Reply 27 days 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.

    Untitled.pngIMG_6600.jpg
    0
    None
    Snowmannetjewildwildwilliam

    Reply 20 days 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?

    20190729_164124.jpg20190729_164112.jpg20190729_164104.jpg20190729_164053.jpg20190729_164042.jpg20190729_164025.jpg
    1
    None
    saruc

    Question 5 months ago

    Hi, Nice tutorial and can I use a Tasmota firmware with this HW setup?

    4 answers
    0
    None
    rewensaruc

    Answer 5 months ago

    I did the physical modification from this guide and went with Tasmota + Home Assistant for firmware and control. I've pasted my settings below so that it helps you and others out. FYI the PulseTime setting does what @Kuzmanic was suggesting with a rule, without writing a custom rule. To learn about the rest of the settings just look them up on the Tasmota Wiki.

    One other tweak I did which is really important imo, is that I put the reed sensor on top of the opener, on the side of the chain that moves towards the opener when the door is closing. This allowed me to put the magnetic half of the reed sensor onto the chain, which made for a very clean setup, and more importantly, I can tell when the garage is opened even just a little bit. With the OPs placement the garage appears as closed even if it's 99% open, since the sensor isn't triggered until the door reaches 100% open. There's a short clip of mine in action in the link below.

    https://photos.app.goo.gl/pnnfsCWr9MmG7PaU8


    For Tasmota v6.4.1 setup to use my own MQTT server I did the following:

    (set the following in module configuration)
    GPIO 14: Switch2

    (run the following commands in the console)
    SwitchMode1 0
    SwitchMode2 1
    SwitchTopic2 sonoff-141E67-sensor (change to your own topic)
    PulseTime 5
    PowerOnState 0
    SwitchRetain 1

    In Home Assistant I added this to my config yml file:

    cover:
    - platform: mqtt
    name: "Garage Door"
    command_topic: "sonoff-141E67/cmnd/POWER" (change to your own topic)
    payload_open: "ON"
    payload_close: "ON"
    payload_stop: "ON"
    state_topic: "sonoff-141E67-sensor/cmnd/POWER2" (change to your own topic)
    state_open: "ON"
    state_closed: "OFF"
    optimistic: false
    retain: false

    IMG_20190303_234938.jpgIMG_20190303_190036.jpgScreenshot_20190306-131740.png
    0
    None
    Kuzmanicsaruc

    Reply 5 months ago

    Yes will work fine, i have moved to Tasmota for my other devices but i havent changed this device as its working fine. In Tasmota you would need to add a rule to the switch to make it disconnect after 1 second. The rule would look like

    rule1 on Power1#State=1 do ruletimer1 1 endon on rules#timer=1 do Power1 off endon

    0
    None
    sarucKuzmanic

    Reply 5 months ago

    Where to add the rule?

    0
    None
    Kuzmanicsaruc

    Reply 5 months ago

    in the console you just add that command, you need to adjust it so that switch1 is the right contact

    0
    None
    diy_bloke

    1 year ago

    Well done. Just a question though. It is not clear to me why you cut the relay from the mains power. Is that because your garage door opener trigger contact is Low Voltage?

    10 replies
    0
    None
    Kuzmanicdiy_bloke

    Reply 1 year ago

    yes most door openers use a low voltage loop to the wall button so I needed just a relay not mains supply

    0
    None
    arossetti1976Kuzmanic

    Reply 1 year ago

    there is no reason to cut the board or to solder the relay contacts

    you can do what you want without modding/ruining the board

    you just need to use a polarized plug and reverse the L and N on the mains input side of the sonoff and then connect a wire from the + door bell button terminal on the back of the opener to the terminal marked L on the load side of the sonoff , then connect a wire from the - door bell button terminal on the back of the opener to your main N

    make sure you test everything first and be sure to get all of the polarity right

    crude diagram below

    https://postimg.cc/image/6ze75hbi3/

    1
    None
    TYDIRTYarossetti1976

    Reply 9 months ago

    Thanks, this worked very nice for both garage door openers. Sonoff just released new firmware that allows "inching". This now allows the garage door to be used using the reverse polarity method as you mentioned. Thanks again!

    1
    None

    can you post the diagram again? I'm having trouble understanding your explanation.

    0
    None

    here is the original diagram once again and here is yours which i edited you should be able to see how it works now

    https://postimg.cc/image/6ze75hbi3/

    https://postimg.cc/image/gow8jic93/b55dbca4/

    be sure to use a meter and to test the polarity of the button wires and especially the 2 main wires just in case your house/outlet has the polarity mixed up , best way to do this is to put the black - probe in the GND prong female on the outlet then put the red + probe into both the other 2 female prong holes

    make sure you do not get it wrong ,you do not want to connect L to the opener button under any circumstance

    0
    None
    Kuzmanicarossetti1976

    Reply 1 year ago

    the button circuit is not a mains voltage loop where this will put mains to it which will not work.

    0
    None
    arossetti1976Kuzmanic

    Reply 1 year ago

    No it does not put mains voltage to the button circuit at all
    It just connects the - button wire to mains neutral which is essentially ground
    Then the + button wire is switched to or from neutral no L wire ever connects to the button circuit at all ,that would destroy the opener if it did
    This isn why you reverse the L and N on the input side of the sonoff the sonoff will still get power because polarity does not matter for powering the sonoff ,you reverse the L and N so you now only have a switched N wire
    Then you connect the + DC from the button circuit To the the switched N on the sonoff output so that switching with the sonoff is just connecting both the + and - wires from the button circuit to N which is just essentially ground