Sure. My setup has two garage doors. Each door has a momentary button for open and a second one for close. I also have a simple wired open/close sensor at the bottom of each door. The ESP home code looks like:
esphome:
name: garage_node
platform: ESP8266
board: nodemcuv2
wifi:
ssid: ###
password: ###
# Enable logging
logger:
# Enable Home Assistant API
api:
password: ###
ota:
password: ###
switch:
- platform: gpio
pin: D1
id: left_open_switch
- platform: gpio
pin: D2
id: left_close_switch
- platform: gpio
pin: D5
id: right_open_switch
- platform: gpio
pin: D6
id: right_close_switch
- platform: template
name: "Left Garage Door Open Switch"
lambda: 'return false;'
turn_on_action:
- switch.turn_on: left_open_switch
- delay: 0.5s
- switch.turn_off: left_open_switch
- platform: template
name: "Left Garage Door Close Switch"
lambda: 'return false;'
turn_on_action:
- switch.turn_on: left_close_switch
- delay: 0.5s
- switch.turn_off: left_close_switch
- platform: template
name: "Right Garage Door Open Switch"
lambda: 'return false;'
turn_on_action:
- switch.turn_on: right_open_switch
- delay: 0.5s
- switch.turn_off: right_open_switch
- platform: template
name: "Right Garage Door Close Switch"
lambda: 'return false;'
turn_on_action:
- switch.turn_on: right_close_switch
- delay: 0.5s
- switch.turn_off: right_close_switch
binary_sensor:
- platform: gpio
pin:
number: TX
mode: INPUT_PULLUP
device_class: garage_door
name: "Left Garage Door Sensor"
id: left_sensor
- platform: gpio
pin:
number: RX
mode: INPUT_PULLUP
device_class: garage_door
name: "Right Garage Door Sensor"
id: right_sensor
The GPIO switches are for internal use in ESPHome only. The template switches create the momentary action for each of the 4 buttons (2 open, 2 closed).
Then in Home Assistant I have the following code:
# Garage door covers
cover:
- platform: template
covers:
left_garage_door:
friendly_name: "Left Garage Door Controller"
value_template: "{{ is_state('binary_sensor.left_garage_door_sensor', 'on') }}"
open_cover:
- service: switch.turn_on
data:
entity_id: switch.left_garage_door_open_switch
close_cover:
- service: switch.turn_on
data:
entity_id: switch.left_garage_door_close_switch
icon_template: >-
{% if is_state('binary_sensor.left_garage_door_sensor', 'on') %}
mdi:garage-open
{% else %}
mdi:garage
{% endif %}
right_garage_door:
friendly_name: "Right Garage Door Controller"
value_template: "{{ is_state('binary_sensor.right_garage_door_sensor', 'on') }}"
open_cover:
- service: switch.turn_on
data:
entity_id: switch.right_garage_door_open_switch
close_cover:
- service: switch.turn_on
data:
entity_id: switch.right_garage_door_close_switch
icon_template: >-
{% if is_state('binary_sensor.right_garage_door_sensor', 'on') %}
mdi:garage-open
{% else %}
mdi:garage
{% endif %}
The icon_template changes the icon between open and closed for the cover.