Opengarage, anyone has flashed ESPhome?

Hi, I did a DIY opengarage Garage opener (a nodemCU plus HC-SR04 ultrasonic sensor)

and flashed this firmware:

It works great, but wish to bring everything ESP related flashed with ESPhome, has anyone a working yaml code for it?

Thanks

Thank you, very useful.

In case anyone is interested and finds this older post via search I thought I would show my take on converting the same parts used for the OpenGarage DIY to be used for ESPHome. It doesn’t provide a web page frontend but it does pretty much the same job.

esphome:
  name: garageopener
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "yourwifissid"
  password: "yourwifipassword"

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:


sensor:
  - platform: ultrasonic
    trigger_pin: D6
    echo_pin: D5
    update_interval: 5s
    unit_of_measurement: cm
    accuracy_decimals: 0
    name: "Door Position Sensor"
    # apply a filter to change the distance to cm from metre #
    filters:  
      - multiply: 100
    id: door_sensor
    
  - platform: wifi_signal
    name: "Garage Opener Wifi"
    update_interval: 60s      
    
switch:
  - platform: gpio
    pin: D8
    name: "Garage Door Switch"
    id: open_switch
  # restart gives a switch in HA that can be used to reboot the NodeMCU #  
  - platform: restart
    name: garage opener restart
    id: restart_garage
    
# is the output used to create a buzzer # 
output:
  - platform: esp8266_pwm
    pin: D7
    id: 'buzzer'
  
cover:
  - platform: template
    name: "Garage Door"
    # set the value so that it is higher than value when door is in open state. In my case it reads 5cm so set it at 10cm #
    lambda: !lambda |-
      if (id(door_sensor).state < 10) {
        return COVER_OPEN;
      } else {
        return COVER_CLOSED;
      }
    open_action:
      # Cancel any previous action
      - switch.turn_off: open_switch
      # sound buzzer before door opens
      - output.esp8266_pwm.set_frequency:
          id: buzzer
          frequency: 800Hz
      - output.set_level:
          id: buzzer
          level: 50%
      - delay: 5s
      - output.turn_off: buzzer
      # Turn the OPEN/CLOSE switch/relay on briefly
      - switch.turn_on: open_switch
      - delay: 0.2s
      - switch.turn_off: open_switch
    close_action:
      # Cancel any previous action
      - switch.turn_off: open_switch
      # sound buzzer before door closes
      - output.esp8266_pwm.set_frequency:
          id: buzzer
          frequency: 800Hz
      - output.set_level:
          id: buzzer
          level: 50%
      - delay: 5s
      - output.turn_off: buzzer
      # Turn the OPEN/CLOSE switch/relay on briefly
      - switch.turn_on: open_switch
      - delay: 0.2s
      - switch.turn_off: open_switch
    stop_action:
      - switch.turn_on: open_switch
      - delay: 0.1s
      - switch.turn_off: open_switch
    # don't really need these here since they are set to default values anyway. was using before I got the ultrasonic sensor working #
    optimistic: false
    assumed_state: false
3 Likes

Hey I was curious if you’ve made any modifications to this since its been a while, I’m about to follow suit myself.

Still the same code being used for my setup.

Hi There. If i have to add MQTT to this and publish all this by MQTT, how will i do?

substitute the mqtt setup from esphome.io for the api line.

I went with something similar but with a few differences:

  1. I enabled the beeper when closing
  2. I enabled an auto-close feature (this only enables if the door was opened by the module as I didn’t want it to enable if I manually opened the door, you could change this)
  3. I found the distance sensor to have moments when it reported wrong values so I used ESPhome to smooth out the values. I also throttled how often it reports by setting a threshold
  4. I check the distance before invoking open/close to ensure it isn’t already in that state and therefore ends up doing the opposite to what I want

I’m new to ESPhome so there may be better ways to do what I did below.

substitutions:
  devicename: garagedoor
  description: OpenGarage.io Device
  friendly_name: Garage Overhead Door
  auto_close_delay: "600s" # 10 minutes
  buzzer_delay: "0.5s"
  open_distance: "15" # less than or equal in cm
  open_close_time: "20s" # allow 20s for motion to complete
  reporting_delta: "25" # minimum 25cm change

# Device informations
esphome:
  name: $devicename
  comment: ${description}
  platform: ESP8266
  board: nodemcuv2
  esp8266_restore_from_flash: false

# Configure WiFi
wifi:
  ssid: "(your SSID)"
  password: "(your password)"
  ap: # Enable fallback hotspot in case wifi connection fails
    ssid: "ESPHome"

# Enable captive portal in case wifi connection fails
captive_portal:

# Provides basic web interface and firmware upload capability
web_server:
  port: 80

# Enable logging
logger:
  level: INFO
  baud_rate: 0 # Disable logging to serial

# Enable Home Assistant API
api:

# Enable OTA updates
ota:

# Enable status LED
status_led:
  pin:
    number: D0
    inverted: yes

# Define switches/relays
switch:
  # The door opener contact (internal)
  - platform: gpio
    id: garage_button
    pin: D8
    restore_mode: ALWAYS_OFF
    internal: true
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: garage_button

# is the output used to create a buzzer # 
output:
  - platform: esp8266_pwm
    id: buzzer
    frequency: 750Hz
    pin: D7

# Define sensors
binary_sensor:
  - platform: status
    name: "${friendly_name} State"
    id: ${devicename}_state

sensor:
  - platform: wifi_signal
    name: "${friendly_name} WiFi Signal"
    id: ${devicename}_wifi_signal
    update_interval: 60s

  - platform: ultrasonic
    name: "${friendly_name} Distance"
    id: ${devicename}_distance
    trigger_pin: D6
    echo_pin: D5
    update_interval: 2s
    unit_of_measurement: cm
    accuracy_decimals: 0
    pulse_time: 10us
    timeout: 4.0m
    filters:
      - filter_out: nan  # filter timeouts
      - multiply: 100    # from meter to cm
      - sliding_window_moving_average:
          window_size: 10
          send_every: 5
          send_first_at: 5
      - delta: ${reporting_delta}

cover:
  - platform: template
    name: "${friendly_name} Control"
    id: ${devicename}_control
    device_class: garage
    # set the distance so it is equal or less than $open_distance when open
    lambda: !lambda |-
      if (id(${devicename}_distance).state <= ${open_distance}) {
        return COVER_OPEN;
      } else {
        return COVER_CLOSED;
      }

    open_action:
      - if:
          condition:
            lambda: "return id(${devicename}_control).position == cover::COVER_CLOSED;"
          then:
            # sound buzzer before door opens
            - output.set_level:
                id: buzzer
                level: 50%
            - delay: ${buzzer_delay}
            - output.turn_off: buzzer
            - switch.turn_on: garage_button
            - delay: ${open_close_time}
            - script.execute: auto_close

    close_action:
      - if:
          condition:
            lambda: "return id(${devicename}_control).position == cover::COVER_OPEN;"
          then:
            # sound buzzer before door closes
            - output.set_level:
                id: buzzer
                level: 50%
            - delay: ${buzzer_delay}
            - output.turn_off: buzzer
            - delay: ${buzzer_delay}
            - output.set_level:
                id: buzzer
                level: 50%
            - delay: ${buzzer_delay}
            - output.turn_off: buzzer
            - delay: ${buzzer_delay}
            - output.set_level:
                id: buzzer
                level: 50%
            - delay: ${buzzer_delay}
            - output.turn_off: buzzer
            - switch.turn_on: garage_button
            # Disable any auto close pending action
            - script.stop: auto_close
            - delay: ${open_close_time}

script:
  - id: auto_close
    then:
      - logger.log: "Automtically closing in ${auto_close_delay}"
      - delay: ${auto_close_delay}
      - logger.log: "Initiating automatic garage closing"
      - cover.close: ${devicename}_control
2 Likes

Does this work with the latest version of opengarage hardware? when i flash this, it just bricks and doesn’t boot up.

./Sooraj

Define please?

I’m not sure what version mine is, I bought it back in January of 2020 and it looks the same as the version in the photo they have in the store with the acrylic case.

What steps did you take to flash it? Was it through the OpenGarage web interface?

I compiled the yaml in esphome, downloaded it and upgraded via the web interface. it said upgrade successful, but nothing turned up in my network. The hardware that i have, the chip covering says ESP12n. seems to be a derivation of ESP8266EX. How did you loaded? via the serial interface? as the model that i have dont have the serial to usb chip and has to be reflashed using FTDI adapter.

looks like the latest version of hardware that they sell dont have the serial to usb chip. so if i have to reflash it, i have to do it via the FTDI adaptor, like how we flash old sonoff devices.

I loaded via the web interface. If the device did not show up on your wi-fi, did you ensure that it isn’t broadcasting its own AP?

Yup. tried everything.

Could you also tell me if the code above will detect if the car is in the garage or not? i didnt see any status for the same when i read through the code. Also how can i publish the whole status and control everything via mqtt rather than ha api, as the garage is in separate network.

Unfortunately, you’ll likely need to try a serial flash then.

The code above will not check for vehicle presence. You’d have to make some changes to do that, perhaps create a template sensor in ESPHome that evaluates the ultrasonic distance and sets the vehicle status to true if the distance is greater than the garage open distance but less than or equal to the distance threshhold to the top of your car. See: https://esphome.io/components/text_sensor/template.html

If you don’t want to use the native API, you can use the MQTT client component instead: https://esphome.io/components/mqtt.html

1 Like

My OpenGarage also ended up in a bootloop. I have this version, please note the wifi shield being under the ultrasonic sensor:

The bootloop comes from the wrong pinout. The correct pinout for this version is listed here:

/** GPIO pins */
#define PIN_RELAY  15 //D8 on nodemcu
#define PIN_BUTTON  0
#define PIN_TRIG   12 //D6 on nodemcu
#define PIN_ECHO   14 //D5 on nodemcu
#define PIN_LED     2
#define PIN_RESET  16
#define PIN_BUZZER 13
#define PIN_SWITCH  4 //switch sensor: D2 on nodemcu
#define PIN_TH      5 //temeprature sensor: D1 on nodemcu

Just use the numbers instead of the Dx.

PS. To add a nice ring on boot:

# Device informations
esphome:
  name: $devicename
  comment: ${description}
  platform: ESP8266
  board: nodemcuv2
  esp8266_restore_from_flash: false
  on_boot:
    priority: 800
    then:
      - output.set_level: {id: buzzer, level: 10%}
      - delay: "0.1s"
      - output.set_level: {id: buzzer, level: 20%}
      - delay: "0.1s"
      - output.set_level: {id: buzzer, level: 30%}
      - delay: "0.1s"
      - output.set_level: {id: buzzer, level: 40%}
      - delay: "0.1s"
      - output.set_level: {id: buzzer, level: 50%}
      - delay: "0.1s"
      - output.set_level: {id: buzzer, level: 60%}
      - delay: "0.1s"
      - output.set_level: {id: buzzer, level: 70%}
      - delay: "0.1s"
      - output.set_level: {id: buzzer, level: 80%}
      - delay: "0.1s"
      - output.set_level: {id: buzzer, level: 90%}
      - delay: "0.1s"
      - output.turn_off: buzzer