I was using a Sonoff 4 Channel Pro relay in my “Smart Garage Door” project however it was big time overkill. I only need one relay to pull this off. In addition to this I was using a NodeMCU ESP8266 to act separately as the garage door sensor. So in essence I had:
- Spare Remote Control (for Security 2.0 garage door opener)
- Sonoff 4 Channel Pro Relay
- NodeMCU ESP8266 Chip for Door sensor
Now I have
- Spare Remote Control
- Sonoff SV
Much, much more compact. In addition to using the Sonoff SV to open and close the door I used the GPIO 14 pin on the board to add the door sensor to the Sonoff SV.
First and foremost I have flashed the Sonoff SV with Tasmota and configured it as follows:
- Set Module Type to Sonoff SV (03)
- Set GPIO 14 to Switch2 (10)
Now after the SV reboots go to the Console and type the following 5 commands
SwitchTopic 1 SwitchMode1 0 SwitchMode2 2 PulseTime1 10 PowerRetain 1
Now set it aside and unplug the board and lets get the hardware ready.
- Remove the two resistors to the right of the INPUT. There is one on each side of the 2 pin connector. Just take a small screwdriver and pry on them. They’ll pop off pretty easily. What this does is it isolates the relay from the wifi.
- Now solder a jumper across the input + and –
- Take a USB connector and leave the A side on and connect it to the + and – terminals labelled in the picture below. I spliced female breadboard wires onto them.
- Hook reed switch to GPIO and a Ground Terminal
- Solder the wires that go to the spare remote button to the output end.
Here is a depiction of all your relevant hook ups:
That’s it. Now lets configure HomeAssistant. This is the switch for the door.
NOTE: I renamed my sonoff MQTT name to “sonoffgarage”. If you don’t change this yours will just be “sonoff” in the MQTT commands below.
switch 15: - platform: mqtt name: "Garage Door" state_topic: "stat/sonoffgarage/POWER" command_topic: "cmnd/sonoffgarage/POWER" payload_on: "ON" payload_off: "OFF" optimistic: false qos: 0 retain: false
Now here is the garage door binary sensor for the reed switch.
NOTE: The door sensor (reed switch) is now “POWER2”. Also note that again yours could be named “sonoff” and mine is named “sonoffgarage”. If you have Eagle Eyes you might note that my payload_on is off. The door would show open when it was closed, and vice versa. You can issue a command in the Sonoff SV Console to change this however this was just the simplest way as far as I was concerned. No right or wrong way IF IT WORKS.
- platform: mqtt name: Garage Door state_topic: cmnd/sonoffgarage/POWER2 payload_on: 'OFF' payload_off: 'ON' sensor_class: 'opening' optimistic: false qos: 0 retain: true
I made an automation to send me a notification to my phone when the door is opened.
automation 24: alias: Notify when garage door opens trigger: - platform: state entity_id: binary_sensor.garage_door to: 'on' action: - service: notify.mypushbullet data_template: title: "Garage Door Open" message: >- Doors Open Dude
Now for safety’s sake I set an automation to automatically close the door if it is open for 20 minutes. At least if it accidentally goes up, it will come back down.
automation 25: alias: Close Garage After 20 Minutes trigger: - platform: state entity_id: binary_sensor.garage_door to: 'on' for: minutes: 20 action: - service: switch.turn_on entity_id: switch.garage_door
Lastly I set a customization for the garage door. This makes it change color and stuff.
binary_sensor.garage_door: friendly_name: Garage Door device_class: garage_door switch.garage_door: friendly_name: Garage Door icon: mdi:garage
Bad Assed. The only way to describe it. I printed a 3D case for the SV from here. Here’s what it looks like installed.