Cheap Smart Garage Door Opener
by RobJonHol in Circuits > Remote Control
5668 Views, 19 Favorites, 0 Comments
Cheap Smart Garage Door Opener
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
Sonoff Basic - https://www.amazon.com/Sonoff-Remote-Control-Comp...
Contact Sensor - https://www.amazon.com/gp/product/B07F314V3Z/ref=...
USB To Serial - https://www.amazon.com/gp/product/B00IJXZQ7C/ref=...
Heat Gun - https://www.amazon.com/gp/product/B00IJXZQ7C/ref=...
Soldering Iron - https://www.amazon.com/gp/product/B00IJXZQ7C/ref=...
Heat Shrink Tubing - https://www.amazon.com/gp/product/B00IJXZQ7C/ref=...
Wire - https://www.amazon.com/gp/product/B00IJXZQ7C/ref=...
Wire Sleeve - https://www.amazon.com/gp/product/B00IJXZQ7C/ref=...
Dupont Cables - https://www.amazon.com/gp/product/B00IJXZQ7C/ref=...
Software:
Home Assistant - https://www.home-assistant.io/
ESPhome - https://www.home-assistant.io/
ESP Easy - https://www.home-assistant.io/
Modifying the Sonoff RF R2 Power
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.
- Locate the fuse that supplies power to the circuitry
- Location where the neutral wire in soldered onto the inlet
- Desolder the fuse, remove, and set aside
- Desolder the neutral wire from the inlet and remove
- Cut out the trace as seen in the photo on step five
- Cut out a notch as seen in the photo on step 6
- Solder the fuse the opposite way you took it out and solder the long end to the line inlet
- Strip the neutral wire and solder it to the board as seen in photo on step 8
ESPHome - Creating the Software
switch: - platform: gpio pin: 12 id: relay_1 name: "sonoff_basic_4_switch" internal: trueWe 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: 500msWe 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_1Finally, 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_1Here 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
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
- In ESPHome compile the code
- Download the binary
- Copy the .bin file to your ESPEasy directory
- Attach your serial wires to the Sonoff
- Hold down the button on the Sonoff and plug in the Serial to USB adapter to your computer
- In the ESPEasy directory Open FlashESP8266.exe
- Select your COM port
- Select the .bin
- Click Flash
Wiring Everything Up
- Solder a wire to the RX terminal on the Sonoff
- Solder a wire to the GND terminal on the Sonoff
- Attach wires to the outgoing neutral and line terminals
- Put the Sonoff case on
- Cut the inlet side of an extension cord, strip the wires, and attach it the the Sonoff's line and neutral inlet
- Screw the Sonoff's caps on ensuring that the inlet wire is secure
- Test to make sure your contact sensor and relay are working correctly
Attach to the Garage Door
- Attach the contact sensor (I attached mine to the pulley)
I didn't have any wire electronics wire so I used some speaker wire and cable wrap to attach the contact sensor.
- Attach the Sonoff to something (I used the bracket holding up the garage door opener)
- 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