Lovelace Button Card - garage door

(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…)

Yeah you should put the momentary action in the open/close action of this:

Okay, that’s definitely better. :slight_smile:
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.

Then I use my cover control button row to control it.

1 Like

Another example I FINALLY found:

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.

1 Like

Thanks for commenting, @tom_l :slight_smile: I’m finally getting it figured out and configured.

The key to using this momentary tap in Lovelace was to create it as a service: within the ESPhome device that controls the garage door relay.

  - service: tap
    then:
      - switch.turn_on:  garage_door_relay
      - delay:           300ms
      - switch.turn_off: garage_door_relay

This can then be called as a service in a configuration.yaml ‘cover’:

        open_cover:
          service: ESPHome.garagescan_tap
        close_cover:
          service: ESPHome.garagescan_tap
        stop_cover:
          service: ESPHome.garagescan_tap

I’m still working it all out, will publish the full details here when I’ve got it working as desired.

1 Like

Yeah custom services are great. I use them to write commands to an ESP connected to the serial port of my cinema projector.

1 Like

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. :confounded:

Paste it here. A second set of eyes could help. Not going to be me right now though. I’m off to bed.

1 Like

Sleep well!

1 Like

This is the current YAML within configuration.yaml for this garage door cover:

cover:
  - platform: template
    covers:
      garage_door_controller:
        friendly_name: "Garage Door Controller"
        value_template: "{{ states('binary_sensor.garagedoor_open') }}"
        icon_template:  "{% if not is_state('binary_sensor.garagedoor_open', 'off') %}mdi:garage-open-variant{% else %}mdi:garage-variant{% endif %}"
        open_cover:
          - condition: state
            entity_id: binary_sensor.garagedoor_open
            state:     "off"
          - service: ESPHome.garagescan_tap
        close_cover:
          - condition: state
            entity_id: binary_sensor.garagedoor_open
            state:     "on"
          - service: ESPHome.garagescan_tap
        stop_cover:
          service: ESPHome.garagescan_tap

The current status is:

  • the icon template: functions correctly, changing icons upon state
  • the stop_cover: button is always enabled (correct, no state condition applied)
  • the close_cover: down arrow is ALWAYS enabled (not correct, state condition ignored)
  • the open_cover: up arrow is NEVER enabled (not correct, state condition ignored)

Even if I had the state values wrong or reversed, I’d expect the conditions to change with the value of the binary_sensor but they do not.

Your value template returns 'on', or 'off' but:

Screenshot 2021-09-27 at 09-52-37 Template Cover

Try this:

value_template: "{{ is_state('binary_sensor.garagedoor_open', 'on') }}"

(read the next sentence after the one I underlined).

Also is there any reason you are using this:

icon_template:  "{% if not is_state('binary_sensor.garagedoor_open', 'off') %}mdi:garage-open-variant{% else %}mdi:garage-variant{% endif %}"

Instead of:

icon_template:  "{% if is_state('binary_sensor.garagedoor_open', 'on') %}mdi:garage-open-variant{% else %}mdi:garage-variant{% endif %}"
1 Like

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? :wink:

It was is_states instead of is_state, I think. Yup, that was it. Working PERFECTLY, now. :smiley:

1 Like

Sorry I do that all the time when editing from states() to is_state().

I’ll fix the post up in case someone else uses it.