Template Button - how to make button disabled/unavail. after pressing and before press sequence ends?

Hello, I want to create an intelligent “template button” for manual restarting of fast.com measurement service which run for cca 20 seconds.
Would like a button which gets disabled after pressing and gets enabled again after press sequence ends (like ESPhome and HA system buttons).
My first version below was trying to set icon and availability properties according to the button state, but it was wrong (later found out that state of template button = timestamp of the last press, not sure why).

I can’t figure out where/how to find the button press real state.
Could anyone help me how to configure the template button which behaves exactly like the standard HA/ESPhome buttons (is unavailable/disabled during press sequence running)?
Thanks in advance

template:
  - button:
    - unique_id: 'restart_fastdotcom'
      name: Restart Fast.com
      icon: >-
        {% if is_state('button.restart_fastdotcom', 'on') %}
          mdi:restart-off
        {% else %}
          mdi:restart
        {% endif %}
      press:
        - service: fastdotcom.speedtest
      availability: >-
        {% if is_state('button.restart_fastdotcom', 'on') %}
          off
        {% else %}
          on
        {% endif %}

make a script with a delay so that it gets an on/off state.

speed_test:
  sequence:
  - service: fastdotcom.speedtest
  - delay:
      seconds: 20

Then map the button to the script.

template:
  - button:
    - unique_id: 'restart_fastdotcom'
      name: Restart Fast.com
      icon: >
        mdi:restart{{ '-off' if is_state('script.speed_test', 'on') else '' }}
      press:
        - service: script.speed_test
      availability: >
        {{ is_state('script.speed_test', 'off') }}
1 Like

Thanks a lot man, I would never think of the script workaround…
Got it working.
The icon switching is not working (unimportant) and delay is not needed (script is waiting for fastdotcom.speedtest service end).

well, when the availability is ‘unavailable’ the other templates don’t render, so it makes sense that the icon stops working.