(New to Lovelace coding, so please pardon my lack of knowledge.)
Like so many HA users, I have a garage door using the momentary closure of a switch contact to trigger the door opening or closing. In ESPHome, this is coded with a series of actions: on, wait 500 milliseconds, off. The ESPHome device emulates a button being pressed half a second and then released.
Unfortunately, the switch as exposed to Home Assistant only provides for two states:
on
off
What I’d like to see is an option other than toggle that provides a momentary action. Touch the button, it fires the switch, and then releases/resets itself. Should a cover be used instead? Anyone else customize a button card for their garage doors? (I know you’re out there…)
Okay, that’s definitely better.
Let me go see how/what I can do with that in ESPHome on my Tilt Sensor device.
It’s a completely separate ESPHome node from the garage door relay device.
If you already have a tilt sensor and a switch in HA to operate the garage door then you are 90% there.
Here is how I have mine set up and no need for ESPHome.
cover:
- platform: template
covers:
north_garage_door:
friendly_name: 'North Garage Door'
value_template: "{{ is_state('binary_sensor.garage_door_north_position_sensor', 'on') }}"
open_cover:
service: script.turn_on
entity_id: script.open_gdn
close_cover:
service: script.turn_on
entity_id: script.close_gdn
stop_cover:
service: switch.turn_on
entity_id: switch.garage_door_north_operator_switch
icon_template: "{% if not is_state('binary_sensor.garage_door_north_position_sensor', 'off') %}mdi:garage-open{% else %}mdi:garage{% endif %}"
automation:
- alias: Toggle Garage Door North Switch
initial_state: 'on'
trigger:
platform: state
entity_id: switch.garage_door_north_operator_switch
to: 'on'
for:
seconds: 1
action:
service: switch.turn_off
entity_id: switch.garage_door_north_operator_switch
script:
close_gdn:
alias: Close the North Garage Door
sequence:
- condition: state
entity_id: binary_sensor.garage_door_north_position_sensor
state: 'on'
- service: switch.turn_on
entity_id: switch.garage_door_north_operator_switch
open_gdn:
alias: Open the North Garage Door
sequence:
- condition: state
entity_id: binary_sensor.garage_door_north_position_sensor
state: 'off'
- service: switch.turn_on
entity_id: switch.garage_door_north_operator_switch
scripts check to make sure the door is not already in the desired state then activates the switch. (i.e. if the door is told to open but it’s already open then nothing happens)
the automation turns the switch back off after one second.
Ah right. I missed that. If there is no chance of connecting both to the one ESP then finity does have the best solution. Otherwise to define your cover in the relay ESP you would have to use the Home Assistant Sensor to bring the tilt sensor into the relay ESP. Which is a bit redundant.
Now just one problem with the cover: item in configuration.yaml.
It enables the STOP action and the CLOSE action and never enables the OPEN action.
I’m guessing it’s some stupid cut-and-paste error somewhere. Just gotta find it.
It was an example from one of the earlier referenced threads. Honestly, I don’t like using negative logic for anything unless absolutely necessary. This one, I copied and pasted, and was too lazy to edit.
Thank you for your suggestions, let me try them and get back to you shortly.
Now the whole cover is “unavailable” ?!? Well, that was certainly unexpected.
Let me look at it more closely. Home Assistant doesn’t see a problem, YAML checks in File Editor don’t see a problem, the `binary_sensor.garagedoor_open’ is working as expected. Ahhh, but the fun never ends, does it?
It was is_states instead of is_state, I think. Yup, that was it. Working PERFECTLY, now.