ESPhome "virtual" switch not working properly

I would like to program virutal switch, which runs lambdas instead of turning hardware gpios. I designed following yaml script, but it does not work - toggling the switch in HA (or in its own web page) does not change the state. What is wrong please?

globals:
  - id: bu_switch
    type: boolean
    restore_value: true
    initial_value: "false"

...
switch:
  - platform: template
    id: blinds_up
    name: "Blinds Up"
    lambda: return id(bu_switch);
    on_turn_on:
      - lambda: |-
          id(bu_switch) = true;
          sendMarkisolCommand(SHADE_UP_EXAMPLE);
    on_turn_off:
      - lambda: |-
          id(bu_switch) = false;
          sendMarkisolCommand(SHADE_STOP_EXAMPLE);

Same problem to which I still don’t have a solution … for now I have given up to commit a gpio to make it work but I find it absurd and useless

I’m no ESPHome expert, but I I think you have to use turn_on_action/turn_off_action with template switches that is what I have in all my configs.

globals:
  - id: bu_switch
    type: boolean
    restore_value: true
    initial_value: "false"

...
switch:
  - platform: template
    id: blinds_up
    name: "Blinds Up"
    lambda: return id(bu_switch);
    turn_on_action:
      - lambda: |-
          id(bu_switch) = true;
          sendMarkisolCommand(SHADE_UP_EXAMPLE);
    turn_off_action:
      - lambda: |-
          id(bu_switch) = false;
          sendMarkisolCommand(SHADE_STOP_EXAMPLE);

@Didgeridrew is correct, you need to use either turn_on_action/turn_off_action or set optimistic: true to have the switch reflect the current state. The new release tomorrow will enforce this.

I had set it up that way but it didn’t work properly.
Now with your help I understand
the GPIO switch from the moment it is activated immediately sends the change of state and then executes the actions

[15:40:04][D][switch:045]: 'Blocco Chiusura Vasistas': Sending state ON
[15:40:04][D][cover:072]: 'Finestre vasistas' - Setting
[15:40:04][D][cover:076]:   Command: STOP

while the switch template performs the actions and then changes the state.

[15:36:42][D][switch:025]: 'Virtual Switch' Turning OFF.
[15:36:42][D][main:715]: ----ACTION---SCRIPT---ACTION--------------------------- OFF
[15:36:42][D][switch:045]: 'Virtual Switch': Sending state OFF

This is ruinous for me because when I go to OFF he activates a script inside which he checks the status of the switch.
So with the GPIO it works, while with the template it doesn’t and I have to create yet another dedicated verification variable