Garage door: view state

Hi
I think basically, I just want to display the state of a pin on an esp32.

the esp32 opens and closes the gate in my driveway. as these gate motors simply open when closed and close when open, i have added a momentary switch as a sort of limit switch, so i can see if the gate is shut.
i have some code that opens and closes the gate:

substitutions:
  name: esphome-web-475594
  friendly_name: driveway gate

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: dev

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:
- platform: esphome

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  ssid: iot
  password: sh6d0wh6t
  ap: {}

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
  import_full_config: true

# Sets up Bluetooth LE (Only on ESP32) to allow the user
# to provision wifi credentials to the device.
esp32_improv:
  authorizer: none

# To have a "next url" for improv serial
web_server:

switch:
  - platform: gpio
    pin: 5
    name: "Garage Door Button"
    id: garage_door_button

# if you DON'T have a door sensor, use the below code
cover:
  - platform: template
    name: "Garage Door"
    device_class: garage
    open_action:
      - switch.turn_off: garage_door_button
      - switch.turn_on: garage_door_button
      - delay: 0.1s
      - switch.turn_off: garage_door_button
    close_action:
      - switch.turn_off: garage_door_button
      - switch.turn_on: garage_door_button
      - delay: 0.1s
      - switch.turn_off: garage_door_button
    optimistic: true

this code somehow changes the colour of the switch in an attempt to show you if the door is open or closed, however as we still use remotes in the cars this state doesnt change when using them and makes this useless.

do i add the changes i need to this code, or do i make another thing to do this?

apologies if this has been covered. i did spend quite some time looking for a previous post covering this, but either i couldnt find it or did and i didnt understand enough to know i was looking at the solution.

thank you

So what is your question or what are you trying to do?

Also, it should be pretty easy (and cheap) to add a magnetic reed switch to your setup so the ESP could know if the gate is open or closed.

i have a switch on the gate already, it is a momentary switch that gets pushed when the gate is shut all the way. i had this all working under another software called remotexy.

All i want is to be able to see the state of the pin that the momentary switch is plugged into.
ideally next to the switch that opens the gate it would say closed if the switch is pressed and open if the switch is not presssed.

Use a binary sensor:

You can do better than that, you can have the cover dynamically show the state. Here’s the relevant part of my garage door YAML:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO21
      mode:
        input: true
        pullup: true
    name: "Garage Door Contact Sensor"
    id: contact_sensor
    internal: true
    filters:
    # Debounce the contact sensor to prevent rapid on/off/on events
      - delayed_on_off: 500ms



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
      - delay: 0.5s
      - switch.turn_off: relay
    close_action:
      - switch.turn_on: relay
      - delay: 0.5s
      - switch.turn_off: relay

Additionally, you can use the device_class of ‘gate’ instead of garage and it will show an icon for a gate (and as open or closed depending on the state).

wow thank you Brooksben11
there is some great info here, fantastic.

so this extra code does it go with the existing code for the gate door? (or gate door button?)
or does it need its own file? if so would it go under devices, entities or helpers? or am I completely in the wrong place.

It all goes in the YAML file for your ESPHome device. The cover part would replace your existing cover and the binary sensor would get added to the file. Obviously some stuff will need to be tweaked to match your file/setup.

excellent, i will have a crack at this now.

thanks brooksben11 for taking the time to walk me through this. :smiley:

1 Like