Block close command if "closed"

I use a fibaro smart implant on my garage door in combination to send an open/close/stop signal (the garage door controller itself opens/closes/stops using the same signal) and use a window/door sensor to determine if the door is closed.

Here is the code for this

# Garage door
cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: >-
          {% if is_state('sensor.garage_access_control_door_state','22') %}
            Open
          {% else %}
            Closed
          {% endif %}
        open_cover:
          service: switch.turn_on
          data:
            entity_id: switch.garage_door_5
        close_cover:
          service: switch.turn_on
          data:
            entity_id: switch.garage_door_5
        stop_cover:
          service: switch.turn_on
          data:
            entity_id: switch.garage_door_5
        icon_template: >-
          {% if is_state('sensor.garage_access_control_door_state','22') %}
            mdi:garage-open-variant
          {% else %}
            mdi:garage-variant
          {% endif %}

My Google Assistant can see the device but I want to close the security flaw by being able to open the door by telling google to “close garage door” since it only requires the code for the command “open garage door”. Is there a way in HA to block the close command if the door is currently in the closed state? How could I accomplish this?

You can use a script as the close action for the cover (look at the docs for the template cover).

then in the script set a condition that the door is open before calling the switch turn on service for the close switch.

Thanks @finity
I read up on scripting and was able to write my first script and changed the template cover to run it when I say “close garage door”.

Now my Template looks like this:

# Garage door
cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        value_template: >-
          {% if is_state('sensor.garage_access_control_door_state','22') %}
            Open
          {% else %}
            Closed
          {% endif %}
        open_cover:
          service: switch.turn_on
          data:
            entity_id: switch.garage_door_5
        close_cover:
          service: script.close_garage_door
        stop_cover:
          service: switch.turn_on
          data:
            entity_id: switch.garage_door_5
        icon_template: >-
          {% if is_state('sensor.garage_access_control_door_state','22') %}
            mdi:garage-open-variant
          {% else %}
            mdi:garage-variant
          {% endif %}

With the script.close_garage_door being:

alias: Close Garage Door
sequence:
  - condition: state
    entity_id: sensor.garage_access_control_door_state
    state: "22"
  - repeat:
      until:
        - condition: state
          entity_id: sensor.garage_access_control_door_state
          state: Window/door is closed
      sequence:
        - service: switch.turn_on
          data: {}
          target:
            entity_id: switch.garage_door_5
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
mode: single
icon: mdi:garage-variant

I timed the length of the garage door opening/closing and put the script on repeat until the door is closed which ensures the reattempts closing if something accidentally stops it from closing all the way.

I have to think about this repeat though because it prevents me from stopping the garage door midway (I haven’t been successful in triggering stop_cover) if I need to vent the garage without opening the door all the way and also could pose a problem if something is legitimately preventing the door from closing.