the recent issues with MyQ got me to finally pull the trigger and setup an ESP8266 with ESPHome for the garage opener.
However one thing i found with the common code available online that is the cover code just executes the relay actions, so when sending it a cover close command it would actually open the garage door if the door was already closed.
I could set up a check in automations for the cover but thought it would be simpler to set it up at source in the ESPHome code.
Here is the common code i found online (this is one of the many variations)
switch:
- platform: gpio
id: relay1
pin:
number: GPIO03
inverted: true
restore_mode: ALWAYS_OFF
binary_sensor:
# This is the magnetic reed switch, used to determine if the door is closed.
- platform: gpio
pin:
number: GPIO05
mode: INPUT_PULLUP
filters:
# During testing- the reed switch was pretty noisy. This cleans up the output.
- delayed_on: 100ms
- delayed_off: 100ms
id: reed_switch
internal: true
cover:
# This template hides both the functionality to open/close the door, as well as its current state
# behind a single "cover"
- platform: template
device_class: garage
name: "$friendly_name"
id: template_cov
# my reed switch is in the on position when the door is closed i.e. magnet is away from the sensor
lambda: |-
if (id(reed_switch).state) {
return COVER_CLOSED;
} else {
return COVER_OPEN;
}
open_action:
- switch.turn_on: relay1
- delay: 0.5s
- switch.turn_off: relay1
close_action:
- switch.turn_on: relay1
- delay: 0.5s
- switch.turn_off: relay1
to address that i added a check for the reed switch status as below
open_action:
if:
condition:
binary_sensor.is_on: reed_switch
then:
- switch.turn_on: relay1
- delay: 0.5s
- switch.turn_off: relay1
else:
- switch.turn_off: relay1
close_action:
if:
condition:
binary_sensor.is_off: reed_switch
then:
- switch.turn_on: relay1
- delay: 0.5s
- switch.turn_off: relay1
else:
- switch.turn_off: relay1
probably does not need the action on the else and there might be a more elegant solution but that what i came up with.