Ifan Mqtt Configuration

Hi guys.
I am a newbie on Hass. I have been using openhab for 10 years. and decided to make the move. I ran into a bit of a battel.

I have a Ifan 2 flashed with tasmota . got it to work with openhab. now i need to get it to work with Hass. tried a some of the suggestions i found on the forum. but end up hitting some more walls. please note that i am still in the learning stages. .

so in openhab i used the following code to get it to work using mqtt.


- id: GuestRoomFanSpd
    channelTypeUID: mqtt:number
    label: Guest Room Fan Spd
    description: ""
    configuration:
      commandTopic: cmnd/GeustBedroom_IFAN/FanSpeed
      postCommand: false
      transformationPatternOut: JSONPATH:$.FanSpeed:(*)
      stateTopic: stat/GeustBedroom_IFAN/FanSpeed
      transformationPattern: JSONPATH:$.FanSpeed:(*)

and it works. but how do I do this now. as I tried using the number in yaml file and it does not for. also copied this

- platform: mqtt  
    name: "Master Bedroom Fan"
    command_topic: "cmnd/sonoff_MBR_fan/FanSpeed"
    speed_command_topic: "cmnd/sonoff_MBR_fan/FanSpeed"    
    state_topic: "stat/sonoff_MBR_fan/RESULT"
    speed_state_topic: "stat/sonoff_MBR_fan/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.master_bedroom_fan.state == 'off' -%}0{%- elif states.fan.master_bedroom_fan.state == 'on' -%}4{%- endif %}
      {% endif %}
    speed_value_template: "{{ value_json.FanSpeed }}"
    availability_topic: tele/sonoff_MBR_fan/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

i did modify it to suit. but keeps giving me errors. tells me to remove the platform: MQTT part. but then it says my config is incorrect.

Please help

That’s an outdated example and is not how an MQTT Fan is currently defined.

In the past, you defined an MQTT Fan entity directly under the top-level fan: key and specified its platform: to be mqtt.

Today, you define an MQTT Fan under the top-level mqtt: key. Under that key is the fan: key and then you define the actual MQTT Fan entity.

Refer to the examples in the documentation.

That looks like my way old original config I’ve posted before.

as noted the way mqtt fans are configured has changed. follow the link above to get the base config setup (from “fan->mqtt platform” to “mqtt->fan”)

additionally the basic fan configuration has changed since then as well because HA doesn’t do “speeds” any more. So unfortunately none of that will work the way it is.

I posted an updated version a while back that at least takes the base fan coinfig into account. if you use that as starting point and update the mqtt->fan portion hopefully it gets you there.

Unfortunately I don’t use MQTT/Tasmota for my iFan’s anymore (I now use ESPHome flashed onto the iFan) so I don’t know what else may have changed since then but here is a post made about the config change:

hopefully it helps you out.

Hi i am working on a way around this. by using Node red.
can some one point me in the right direction.

My idea:
I want to use the MQTT number to be able to select (OFF, Slow, Med, Fast) and send 0, 1, 2, 3 to node red via MQTT. and have mqtt do the messages to the Ifan.

have it subscribed to the CMND topic. but how do I do the command template.

Hi Guys so i got this working little crude but it works.

used Node Red as a type of decoder/ encoder. .

now just to get it nicely on my dashboard.

This is how i did it. .

MQTT Settings :

 - select:
     name: "Guest Fan Speed "
     command_topic: "cmnd/GuestBedroom_Fan/SPD"
     state_topic: "stat/GuestBedroom_IFAN/RESULT"
     value_template:  |-
      {% if value_json.FanSpeed == '0' %}
        "Off"
      {% elif value_json.FanSpeed == '1' %}
        "Slow"
      {% elif value_json.FanSpeed == '2' %}
        "Med"
      {% elif value_json.svalue1 == '3' %}
        "Fast"
      {% endif %}"
     options:
      - "Off"
      - "Slow"
      - "Med"
      - "Fast"

Node Red :

[
    {
        "id": "56c25f2c856fee96",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "fa25c4e8831b4fbb",
        "type": "mqtt in",
        "z": "56c25f2c856fee96",
        "name": "",
        "topic": "stat/GuestBedroom_IFAN/RESULT",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "650485ee55fca41f",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 300,
        "y": 100,
        "wires": [
            [
                "bd5a04a8ca08fe69"
            ]
        ]
    },
    {
        "id": "564c4926b686c919",
        "type": "debug",
        "z": "56c25f2c856fee96",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 320,
        "wires": []
    },
    {
        "id": "9d307dfe6799d527",
        "type": "mqtt out",
        "z": "56c25f2c856fee96",
        "name": "",
        "topic": "cmnd/GuestBedroom_IFAN/FanSpeed",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "650485ee55fca41f",
        "x": 930,
        "y": 220,
        "wires": []
    },
    {
        "id": "bd5a04a8ca08fe69",
        "type": "debug",
        "z": "56c25f2c856fee96",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 720,
        "y": 140,
        "wires": []
    },
    {
        "id": "b7fa2011a72fdddd",
        "type": "mqtt in",
        "z": "56c25f2c856fee96",
        "name": "",
        "topic": "cmnd/GuestBedroom_Fan/SPD",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "650485ee55fca41f",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 290,
        "y": 220,
        "wires": [
            [
                "5945345d2e313079"
            ]
        ]
    },
    {
        "id": "5945345d2e313079",
        "type": "change",
        "z": "56c25f2c856fee96",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "Off",
                "fromt": "str",
                "to": "0",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "Slow",
                "fromt": "str",
                "to": "1",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "Med",
                "fromt": "str",
                "to": "2",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "Fast",
                "fromt": "str",
                "to": "3",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 560,
        "y": 220,
        "wires": [
            [
                "9d307dfe6799d527",
                "564c4926b686c919"
            ]
        ]
    },
    {
        "id": "650485ee55fca41f",
        "type": "mqtt-broker",
        "name": "MQTT Server",
        "broker": "192.168.20.114",
        "port": "1883",
        "clientid": "Node_Red",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

It is a work in progress.