Cheap Smart Garage Door Opener

by RobJonHol in Circuits > Remote Control

5695 Views, 19 Favorites, 0 Comments

Cheap Smart Garage Door Opener

I Made a Smart Garage Door Opener - Home Assistant

Credit

I pretty much copied Savjee's implementation but instead of using a Shelly I used a Sonoff Basic. Check out his web site and YouTube Channel!

https://www.savjee.be/2020/06/make-garage-door-ope...

https://www.youtube.com/c/Savjee/

Assumptions

  • You have a Home Assistant instance running and you know how to use it
  • You have a ESPHome instance running and you know how to use it

Supplies

Modifying the Sonoff RF R2 Power

2020-09-10 15_22_36-Clipboard.png
2020-09-10 15_31_30-back.png
2020-09-10 15_31_30-back2.png
2020-09-10 15_53_13-backcut.png

DISCLAIMER

I am not an electrical engineer and do not pretend to play one on the internet. If you decide to modify a Sonoff Basic you are doing it at your own risk. This is how I have modified my Sonoff Basic but do not recommend that you do the same. I am also not implying that I am doing it correctly or safely.

Getting started

Csongor Varga makes a good point in his video about it not being safe to modify this version of the Sonoff like the previous version by cutting the trace. See more here. The solder connection for the relay and the solder connection for the fuse that supplies power to the circuitry are too close to do the cutting trace method. I got around this by removing most of the trace and relocating the fuse.

  1. Locate the fuse that supplies power to the circuitry
  2. Location where the neutral wire in soldered onto the inlet
  3. Desolder the fuse, remove, and set aside
  4. Desolder the neutral wire from the inlet and remove
  5. Cut out the trace as seen in the photo on step five
  6. Cut out a notch as seen in the photo on step 6
  7. Solder the fuse the opposite way you took it out and solder the long end to the line inlet
  8. Strip the neutral wire and solder it to the board as seen in photo on step 8

ESPHome - Creating the Software

A switch to configure the relay. This will be internal so that it isn't directly exposed to Home Assistant.
switch:
  - platform: gpio
    pin: 12
    id: relay_1
    name: "sonoff_basic_4_switch"
    internal: true
We will need a binary sensor for the contact sensor that will tell us if the garage door is closed or open.
binary_sensor:
  - platform: gpio
    pin: 
      number: 3
      mode: INPUT_PULLUP
    name: "Garage Door Contact Sensor"
    id: contact_sensor
    internal: true
    filters:
      delayed_on_off: 500ms
We can configure the button on the Sonoff to toggle the relay.
- platform: gpio
    id: button_0
    pin:
      number: 0
      inverted: True
      mode: INPUT_PULLUP
    on_click:
      then:
        - switch.turn_on: relay_1
        - delay: 500ms
        - switch.turn_off: relay_1
Finally, a cover with the attribute garage.
cover:
  - platform: template
    device_class: garage
    name: "Garage Door"
    id: template_cov
    lambda: |-
      if (id(contact_sensor).state) {
        return COVER_OPEN;
      } else {
        return COVER_CLOSED;
      }
    open_action:
      - switch.turn_on: relay_1
      - delay: 0.5s
      - switch.turn_off: relay_1
    close_action:
      - switch.turn_on: relay_1
      - delay: 0.5s
      - switch.turn_off: relay_1
Here is the full YAML.
wifi:
  ssid: 
  password: 
  manual_ip:
    static_ip: 
    gateway: 
    subnet: 
    dns1: 
    dns2: 
    
    
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: 
    password: 

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

substitutions:
  # Modify variables based on your settings
  hostname: 'sonoff_basic_4'

esphome:
  name: $hostname
  platform: ESP8266
  board: esp01_1m
  board_flash_mode: dout


status_led:
  pin:
    number: 13
    inverted: True
    
binary_sensor:
  - platform: gpio
    pin: 
      number: 3
      mode: INPUT_PULLUP
    name: "Garage Door Contact Sensor"
    id: contact_sensor
    internal: true
    filters:
      delayed_on_off: 500ms
  - platform: gpio
    id: button_0
    pin:
      number: 0
      inverted: True
      mode: INPUT_PULLUP
    on_click:
      then:
        - switch.turn_on: relay_1
        - delay: 500ms
        - switch.turn_off: relay_1
switch:
  - platform: gpio
    pin: 12
    id: relay_1
    name: "sonoff_basic_4_switch"
    internal: true

cover:
  - platform: template
    device_class: garage
    name: "Garage Door"
    id: template_cov
    lambda: |-
      if (id(contact_sensor).state) {
        return COVER_OPEN;
      } else {
        return COVER_CLOSED;
      }
    open_action:
      - switch.turn_on: relay_1
      - delay: 0.5s
      - switch.turn_off: relay_1
    close_action:
      - switch.turn_on: relay_1
      - delay: 0.5s
      - switch.turn_off: relay_1



sensor:
  - platform: wifi_signal
    name: "sonoff_basic_4_wifi_signal"
    update_interval: 60s

  - platform: uptime
    name: "sonoff_basic_4_up_time"

text_sensor:
  - platform: version
    name: "sonoff_basic_4_version"

ESPEasy - Flashing the Sonoff Basic

2020-09-10 16_26_55-Window.png
2020-09-10 16_30_55-Window.png
2020-09-10 16_32_17-Window.png
2020-09-10 16_40_19-vlcsnap-2020-09-10-16h37m22s289.png
2020-09-10 16_38_06-vlcsnap-2020-09-10-16h35m49s389.png
2020-09-10 16_46_20-Window.png

You will need a USB to serial adapter for this.

  • The RX on the serial adapter goes to the TX on the Sonoff
  • The TX on the serial adapter goes to the RX on the Sonoff

  1. In ESPHome compile the code
  2. Download the binary
  3. Copy the .bin file to your ESPEasy directory
  4. Attach your serial wires to the Sonoff
  5. Hold down the button on the Sonoff and plug in the Serial to USB adapter to your computer
  6. In the ESPEasy directory Open FlashESP8266.exe
  7. Select your COM port
  8. Select the .bin
  9. Click Flash

Wiring Everything Up

2020-09-10 17_03_25-Window.png
2020-09-10 17_01_37-Window.png
2020-09-10 17_10_59-Window.png
2020-09-10 17_14_59-Window.png
I used dupont cables and a computer power cable for this but you can use what you like.
  1. Solder a wire to the RX terminal on the Sonoff
  2. Solder a wire to the GND terminal on the Sonoff
  3. Attach wires to the outgoing neutral and line terminals
  4. Put the Sonoff case on
  5. Cut the inlet side of an extension cord, strip the wires, and attach it the the Sonoff's line and neutral inlet
  6. Screw the Sonoff's caps on ensuring that the inlet wire is secure
  7. Test to make sure your contact sensor and relay are working correctly

Attach to the Garage Door

2020-09-10 17_47_32-cablewrap.png
2020-09-10 17_49_18-contactsensor.png
2020-09-10 17_51_03-garagedooropener.png
  1. Attach the contact sensor (I attached mine to the pulley)
    1. I didn't have any wire electronics wire so I used some speaker wire and cable wrap to attach the contact sensor.

  2. Attach the Sonoff to something (I used the bracket holding up the garage door opener)
  3. Connect the cables

Home Assistant Automation - Notification If Garage Is Open for 2 Hours

Trigger: If the garage door is open for 2 hours

Action: Send notifications to my phone, my girlfriends phone, and to my home discord channel

automations.yaml

- id: notification_if_garage_is_open_for_2_hours
  alias: "notification if garage is open for 2 hours"
  trigger:
    platform: state
    entity_id: cover.garage_door
    to: open
    for:
      hours: 2
  action:
  - service: notify.mobile_app_courtney_s_iphone
    data:
      title: "[📣][🚙]Garage left open!"
      message: "The garage door has been open for 2 hours. Close it?"
      data:
        push:
          category: ios_close_garage
  - service: notify.mobile_app_pixel_3a
    data:
      title: "[📣][🚙]Garage left open!"
      message: "The garage door has been open for 2 hours. Close it?"
      data:
        actions: 
        - action: android_close_garage
          title: Close Garage
  - service: notify.discord
    data:
      message: "[📣][🚙]The garage door has been open for 2 hours. Close it?"
      target: ["YOUR DISCORD CHANNEL ID"]

To get a notification on IOS that has a button to close the garage door you need to add the following to the configuration.yaml file.

configuration.yaml

ios:
  push:
    categories:
      - name: Close Garage
        identifier: 'ios_close_garage'
        actions:
          - identifier: 'IOS_CLOSE_GARAGE'
            title: 'Close Garage'
            activationMode: 'background'
            authenticationRequired: true # Require FaceID / TouchID
            destructive: false
            behavior: 'default'

Now you can add the automation that is called when you pressed the close garage door button on the IOS push notification.

automations.yaml

- id: 'ios_mobile_app_notification_close_garage_door'
  alias: ios mobile app notification close garage door
  trigger:
    platform: event
    event_type: ios.notification_action_fired
    event_data:
      actionName: IOS_CLOSE_GARAGE
  action:
  - delay: 00:00:15
  - service: cover.close_cover
    data:
      entity_id: cover.garage_door

The automation that is called when you pressed the close garage door button on the Android push notification.

automations.yaml

- id: 'android_mobile_app_notification_close_garage_door'
  alias: android mobile app notification close garage door
  trigger:
  - event_data:
      action: android_close_garage
    event_type: mobile_app_notification_action
    platform: event
  action:
  - delay: 00:00:15
  - service: cover.close_cover
    data:
      entity_id: cover.garage_door