Optimising Garage Door Button for Voice Assistant

For my Garage Door, I have a simple ESPHome ESP32 controlling a single relay to simulate the Garage Door Controller button. The pressing of the button toggles the garage door to open or close.

switch:
  - platform: gpio
    id: relay
    pin: GPIO17
    restore_mode: RESTORE_DEFAULT_OFF

button:
  - platform: template
    name: "Garage Door Control"
    on_press:
      - switch.turn_on: relay
      - delay: 650ms
      - switch.turn_off: relay

binary_sensor:
  - platform: gpio
    device_class: garage_door
    icon: mdi:garage-variant
    pin: 
      number: GPIO16
      mode: INPUT_PULLUP
      inverted: true
    name: "Door Status"

For voice control via my voice satellites, I have a voice-sentence - triggered automation. When the sentence is said, the automation presses the button to open or close the garage door. I have taken this approach as the Garage Door ESP Home device is currently not a “Cover” and hence, I cannot directly issue a “Open or close Garage Door” voice command. But this approach works well.

I would like to make my Garage Door device or the button a “Cover” device/entity, so that I can then expose the button to the Voice Assistant directly and use the standard cover commands directly, avoiding the need for an automation.

I explored the ESPHome Cover component, the Simple Garage Door example and various Garage Door posts which are mostly around getting more precise status of the door. I also can’t assign the device_class for the button as “Cover” either as that is not valid for buttons.

Wondering if anyone has a simple ESPHome garage door toggle example that makes the ESP device and/or the button a device_class = cover, that I can use as a base to change my code.

Is there a more efficient/simpler approach to getting the voice assistant to push a ESPHome button? Or is my current approach via an automation already optimal?

Hope this makes sense … any help would be much appreciated

I don’t use voice assistant, but as I understood button is not supported there.
You already have switch though, you don’t need button at all.

switch:
  - platform: gpio
    id: relay
    pin: GPIO17
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:
      - delay: 650ms
      - switch.turn_off: relay

Obviously you need to call “turn on garage door” and that doesn’t sound elegant for most of people. I’m exception because i like minimalistic setups.

Otherwise, convert it to cover.
Simple template cover added to your actual setup:

cover:
  - platform: template
    name: "Garage Door"
    device_class: garage
    open_action:
      - button.press: garage_button
    close_action:
      - button.press: garage_button
    stop_action:
      - button.press: garage_button
    lambda: |-
      if (id(door_status).state) {
        return COVER_CLOSED;
      } else {
        return COVER_OPEN;
      }

You need to give id: door_status for your binary sensor
and id: garage_button for your button.

Many thanks for this - it works and it was extremely helpful!

I used the Cover approach, but had to flip the lambda results around as I had inverted the binary_sensor. The cover entity created by the Cover code now works perfectly with the voice assistant.

I kept the button exposed as I had other automations operate on a single press of the button.

You’re welcome.