Sonoff ifan02

sure here is the mqtt message after changing speed to 2

here is the tele/state lines

{"Time":"2019-09-20T20:13:38","Uptime":"0T08:39:50","UptimeSec":31190,"Heap":26,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER1":"ON","FanSpeed":2,"Wifi":{"AP":1,"SSId":"HA","BSSId":"E4:F4:C6:02:01:BA","Channel":6,"RSSI":100,"LinkCount":1,"Downtime":"0T00:00:04"}}

I had an improvement I got it to register the fan speed changes but it puts everything as med or off here is the yaml turns out it was the quoted mqtt topics i had in it

fan:
  - platform: mqtt  
    name: "Kitchen Ceiling Fan 2"
    command_topic: KCF2/cmnd/FanSpeed
    speed_command_topic: KCF2/cmnd/FanSpeed
    state_topic: KCF2/stat/RESULT
    speed_state_topic: KCF2/tele/STATE
    state_value_template: >
      {% if value_json.FanSpeed is defined %}
        {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
      {% else %}
        {% if states.fan.Kitchen_Ceiling_Fan_2 == 'off' -%}0{%- elif states.fan.Kitchen_Ceiling_Fan_2.state == 'on' -%}4{%- endif %}
      {% endif %}
    speed_value_template: "{{ value_json.FanSpeed }}"
    availability_topic: KCF2/tele/LWT
    payload_off: "0"
    payload_on: "4"
    payload_low_speed: "1"
    payload_medium_speed: "2"
    payload_high_speed: "3"
    payload_available: Online
    payload_not_available: Offline
    speeds:
      - off
      - low
      - medium
      - high

The quotation marks shouldn’t make any difference. My config has the quotation marks and it works fine.

However I did find a couple of mistakes in your code.

Where did you get the code above? Did you copy it from somwhere other than the Tasmota website or any of the threads/posts I’ve made?

Here are the incorrect lines:

    speed_state_topic: KCF2/tele/STATE
    state_value_template: >
      {% if value_json.FanSpeed is defined %}
        {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
      {% else %}
        {% if states.fan.Kitchen_Ceiling_Fan_2 == 'off' -%}0{%- elif states.fan.Kitchen_Ceiling_Fan_2.state == 'on' -%}4{%- endif %}
      {% endif %}

they should be:

    speed_state_topic: KCF2/stat/RESULT 
    state_value_template: >
      {% if value_json.FanSpeed is defined %}
        {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
      {% else %}
        {% if states.fan.kitchen_ceiling_fan_2.state == 'off' -%}0{%- elif states.fan.kitchen_ceiling_fan_2.state == 'on' -%}4{%- endif %}
      {% endif %}

the state topic is wrong and the {% else %} {% if %}… portion is wrong.

Entity_id’s are never going to contain uppercase characters. and you missed “…state” at the end of the line.

I think I got it directly from one of your posts but i would have to go fine to tell you for sure

I don’t think so.

but if you find it please let me know where it is so I can correct it.

Is it working now?

Yes that did the trick thank you