Script and wait_template

Is there anybody that can help me with this?
I’m trying to create a “universal” script that will toggle the addons installed on the system.
The switching on and off for the addons works perfectly but I also wanto to disable the button while the sensor that I use to determine the state of the addon has changed state. So I use mqtt and set the topic specific to the button I pressed to “running” and then to “idle” when the stat has changed.
I was able to produce this:

alias: Addon Toggle
sequence:
  - variables:
      current_state: "{{ states(sensor) }}"
      prefix: "{{ sensor.split('.')[1].split('_')[0] }}_"
      my_topic: buttons/{{ sensor.split('.')[1].split(prefix)[1] }}
  - service: mqtt.publish
    data:
      qos: "0"
      retain: false
      topic: "{{ my_topic }}"
      payload: "{  \"status\" :  \"running\" }"
  - service: |-
      {% if states(sensor) == 'up' %} 
        {{ "hassio.addon_stop" }}
      {% else %}
         {{ "hassio.addon_start" }}
      {% endif %}
    data:
      addon: |-
        {% set addon = name %}
        {{ addon }}
  - wait_template: "{{not is_state(sensor, current_state)}}"
  - service: mqtt.publish
    data:
      qos: "0"
      retain: false
      topic: "{{ my_topic }}"
      payload: "{  \"status\" :  \"idle\" }"
mode: single

What really bugs me is that this script works just fine when the state goes from up to down but not viceversa… I mean it works but the wait _template goes a 5/10 seconds longer thant the state (I can see it because the button change color when the state changes).

Why the hell it can’t work like the other way around? :wink:

thank you in advance.