MQTT fan configuration when controlled via percentage

Good afternoon!

I have an MQTT fan, the only control topic for is a percentage slider (0-100).
So it is assumed that when it is set to 0 - it is off, otherwise it’s on.

Im trying to configure, but encounter the following problem: Whilist the percentage slider operates correctly, I cannot make it to display on/off state correctly in HA, as well as control it with the On/Off switch (it should set percentage to 0 when switch turns off and to some preselected value - lets say 50, when switch turns on)

This is what I got so far:

- platform: mqtt
  name: "convector.kid.fan"
  command_topic: "/devices/varmannQ_5/controls/Fan Speed/on"
  command_template: "{{ value }}"
  percentage_command_topic: "/devices/varmannQ_5/controls/Fan Speed/on"
  percentage_command_template: "{{ value }}"
  state_topic: /devices/varmannQ_5/controls/Fan Speed/
  state_value_template: >
    {% if value | int(0) == 0 %}
      off
    {% else %}
      on
    {% endif %}

What is wrong here. Please, help me with modifying it to work correctly

Thank you!

Hello! Could anyone help me please?