MQTT switch iFan03 Tasmota - multiple states

Hi
I have the following switch configured:

switch:
  - platform: mqtt
    name: "Bedroom fan - low"
    command_topic: "cmnd/tasmota_2C252A/FanSpeed"
    state_topic: "stat/tasmota_2C252A/RESULT"
    payload_on: "1"
    payload_off: "0"
    state_on : '{"FanSpeed":1}'
    state_off: '{"FanSpeed":0}'
    qos: 1
    optimistic: false
    retain: true

All this switch does is turns my Tasmota/Sonoff iFan03 on to its lowest setting, the reason for this is so that I can control the fan from a thermostat entity.
However, I also manually use the remote control to set the fan to its different speeds. ‘{“FanSpeed”:1}’ is the payload for the lowest speed and ‘{“FanSpeed”:3}’ is the highest.
What I’d like is for this switch to show ‘on’ regardless of the speed setting. Is there a way to have the state_on setting do a bit of simple logic like:

if FanSpeed != 0

or

if FanSpeed == 1 OR FanSpeed == 2 OR FanSpeed == 3

If that’s not feasible then any other suggestions would be appreciated.
Thanks

You need a value_template. Something like:

    Value_template: >
      {% if value_json.Fanspeed == 0 %}
        Off
      {% else %}
        On
      {% endif %}

And delete the state_on and state_off lines.

Hey, thanks for the suggestion, however this just stopped the button from being able to do anything other than turn the fan on.

switch:
  - platform: mqtt
    name: "Bedroom fan - low"
    command_topic: "cmnd/tasmota_2C252A/FanSpeed"
    state_topic: "stat/tasmota_2C252A/RESULT"
    payload_on: "1"
    payload_off: "0"
    #state_on: '{"FanSpeed":1}'
    #state_off: '{"FanSpeed":0}'
    qos: 1
    optimistic: false
    retain: true
    value_template: >
      {% if value_json.FanSpeed == 0 %}
        Off
      {% else %}
        On
      {% endif %}

How does the value_template key tie up with the state_on and state_off keys?

According to the documentation the payload_on and _off are used for the command topic and if no state topics are defined are also used to compare with the result of the state topic. So in this case is would be better to use

state_on: On
state_off: Off

If you also want to control the fanspeed by HA, you will need an additional control, e.g an Input_Select to send the FanSpeed 1, 2 or 3 commands. Switch on to default speed and switch off by the switch and select speed by the Input_Select.