Sonoff iFan03 with Tasmota Configuration (using MQTT)

I haven’t been able to figure those out yet either.

The gpio is different for the ifan03 and also another issue is that the way the remote works is different too.

@Peter_West

I’ll jump back on here later to try to help you more with your issue but I’ve got to go to work now. IRL sucks…:smile:

Thanks @finity. I really appreciate the help you’ve given me over the last few days.

I’m finding some strange behaviours when configuring my MQTT devices. The three Sonoff units I have hooked up to lamps all worked fine using configuration like this.

  - platform: mqtt
    name: "White Room Lamp 3"
    state_topic: "stat/whiteroomlamp3/POWER1"  
    command_topic: "cmnd/whiteroomlamp3/POWER1"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: false

However, when I tried using the same code for a Sonoff Basic connected to a fan then it wouldn’t work. The switch in Lovelace would trigger the fan to come on but the state wasn’t reflected and after a second or two the switch would move back to the off position, thus meaning you couldn’t turn the fan off remotely.

I got it working in the end using this YAML fragment. The main difference was dropping the 1 off the end of the command, although based on what I read it should still work with that because the number simply represents the index of the relay you wish to operate. I don’t know if the case of the command makes a difference, but the sample I found specifically had the state topic in capitals and the command in lower case. Using the config below worked for me.

  - platform: mqtt
    name: "Big Fan"
    state_topic: "stat/bigfan1/POWER"  
    command_topic: "cmnd/bigfan1/power"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: false

When I was looking at the fan control last night I was curious as to why I had no text on the buttons showing which was for LOW, MED and HIGH. Then just now it dawned on me - I was using a dark purple theme which meant the text in the boxes wasn’t readable. I’m not sure if it’s something you can address through your code, but for now i’ve just switched back to the default theme.

It means the only real issues I have now are:

  1. I need to get it so the fan control will actually turn the fan off.
  2. I somehow need to expose the lamp control on the fan so I can use another switch to turn the light on and off. I’m guessing I can just define another light: entry to take care of this?

Thanks again.

For the Sonoff Basic’s the problem could be that the Tasmota firmware has evolved over time so a config that worked a while back might not work the same now.

Here is a config for the only Tasmota Sonoff Basic I still have left. All the rest of my Sonoff’s berside that one Basic and now the iFan03 have all been switched to ESPHome firmware:

  - platform: mqtt
    name: "Tree"
    state_topic: "stat/tree/POWER"
    command_topic: "cmnd/tree/POWER"
    availability_topic: "tele/tree/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

I think the 1 on the end of the topic is used or not depending on which module configuration you set the device to use. Some devices have more than one relay and will require 1, 2, 3, etc added. Some only have one relay. Some are fans that run more than one relay at a time for fan speed control so they don’t use “power” they use “FanSpeed” with the desired fanspeed in the topic payload.

The first thing I recommend if you don’t already have it is to install a mqtt sniffer program. I use MQTTFx and MQTTExplorer. Both are really useful and can be used for different functions.

Generally I use MQTTFx for watching general MQTT topic traffic. If you watch that traffic you can see what messages are traveling around in your MQTT network. And that can help you figure out what the exact topics are that you need to use in your configs.

But on to the problems…

As far as the theme colors my fan controls can be themed individually for different backgrounds. You can look at the repository for config options and examples (https://github.com/finity69x2/fan-control-entity-row).

For the light you would just create another mqtt light and use that to control the light. Here is my config for the light:

light:
  - platform: mqtt
    name: "iFan03-1 Light"
    command_topic: "cmnd/iFan03-1/power1"
    state_topic: "stat/iFan03-1/POWER1"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: false

Then just put the resulting switch on your frontend for the toggle to control the light.

Can you please post the most recent config for your iFan03 again? I just want to make sure that I’m looking at the most recent config.

Also as suggestred above, install MQTTFx , connect it to your broker and subcribe to all the topics (use # in the subcribe section). Then watch for the topics and payloads that pop up in the right hand window when you operate the iFan03 from the Tasmota web console.

You won’t see any of the command topics pop up because all of that is done outside of your broker but you will see all of the status messages.

Then after that try to operate the ifan03 from the HA frontend using my fan control row. you should see the same status messages as before in response to the commands but this time you should also see the commands sent from HA to your broker to try to control the ifan03. Pay particular attention to the “off” button command since that is the one you said isn’t working.

Once you’ve done that if it doesn’t lead you to a solution then please post back with the requested information.

We’ll get this figured out. :slightly_smiling_face:

Hi @finity.

Here is my current fan config.

fan:
  - platform: mqtt  
    name: "ConservatoryFan"
    command_topic: "cmnd/conservatoryfan/FanSpeed"
    speed_command_topic: "cmnd/conservatoryfan/FanSpeed"    
    state_topic: "stat/conservatoryfan/status"
    speed_state_topic: "stat/conservatoryfan/status"
    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.conservatoryfan.state == 'off' -%}0{%- elif states.fan.conservatoryfan.state == 'on' -%}4{%- endif %}
      {% endif %}
    speed_value_template: "{{ value_json.FanSpeed }}"
    availability_topic: tele/conservatoryfan/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’ll try to have a look at some of what you speak about above this evening, but unfortunately time is a little short tonight. I got home from work and took the chance to go out for a ride on the new motorbike my wife bought me for my birthday - then I had some bunkbeds to build. As you say, real life gets in the way some times.

I’ll report back with what I find. :slight_smile:

The YAML you posted for the lamp connected to the iFan worked flawlessly for me.

Right now the only issue I seem to have is that the ‘OFF’ button doesn’t seem to work and the selected fan speed doesn’t seem to change colour like the YAML suggests it should.

I installed and tried MQTTFx - very impressive - but the status messages all look to check out so i’m not sure what it is. Maybe something in my YAML definition for the Fan?

Thanks for your help - it’s really appreciated.

I found the problem with your fan…(I hope…)

you need to change the following lines in your conrig from:

  state_topic: "stat/conservatoryfan/status"
  speed_state_topic: "stat/conservatoryfan/status"

to this;

  state_topic: "stat/conservatoryfan/RESULT"
  speed_state_topic: "stat/conservatoryfan/RESULT"

I copied your config to mine and it wouldn’t work until I noticed those two lines were wrong.

1 Like

You nailed it @finity. Thanks SO much for all of your help.

And, I have just a single final question if that’s ok.

Is there any way to change the button text on the fan control to a different colour? I can set the button backgrounds to a light colour but as the text is white it makes it unreadable.

Otherwise, it’s all working. I now have a working multi-speed fan controller with a seperate light switch running in HA. It’s great that the iFan03 comes with a seperate RF remote because it means I don’t have to worry what happens if we ever move house as we can simply leave the remote behind for the new owners.

I’ll look into it to see how complicated that could be. I’m a weekend programmer so I’ll have to likely slog my way through to see if I can figure it out. :wink:

But right now the font color is the same color as the rest of the default page fonts. What I do is just pick a pleasinb color that has enough contrast to show up in both a dark theme (light font color) and a light theme (dark font color). As an example of the colors I use you can look at my github examples and it shows how it looks with a dark & light theme.

I’m sure I could set a fixed font of a different color fairly easily but then it wouldn’t change to follow the default theme color which I like better.

I’ll let you know if I get the custom font theme worked out tho.

Thanks @finity.

For now i’ve just set the inactive button colour to black and it looks pretty sweet. But best of all it all works flawlessly.

Huge thanks for all your help - i’ve learnt a fair bit about MQTT which was a protocol i’d not worked with until I developed an interest in HA. :slight_smile:

1 Like

hi,
anyone can guide me to set up the ifan3 tasmota 7 for alexa? the hue emulation is giving me 4 switches. i cant change the speed . its only switches.
thanks,

@gnasser76

You are going to have to create a “fan” entity from the tasmota configuration.

See a few posts up to see an example of how that will look. (post #24 I think has the code)

1 Like

Have you got it to work the Ifan03
I have the same issue, I can’t get the fan to work on Hassio but only the fan light.

1 Like

It might actually be better to ask someone who already has it working…

And what exactly is that issue?

Did you try to reconfigure the fan into a “fan entity” as in the code posted above?

This is what I have been using and it works fine I use it with a custom entity row with fan speeds. You have to write it a bit different without the custom entity row.
Then the light comes in as a seperate entity switch.
Capture

fan:
  - platform: mqtt  
    name: "Fan"
    command_topic: "cmnd/bedroom_fan/FanSpeed"
    speed_command_topic: "cmnd/bedroom_fan/FanSpeed"    
    state_topic: "stat/bedroom_fan/RESULT"
    speed_state_topic: "stat/bedroom_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.bedroom_fan.state == 'off' -%}0{%- elif states.fan.bedroo_fan.state == 'on' -%}4{%- endif %}
      {% endif %}
    speed_value_template: "{{ value_json.FanSpeed }}"
    availability_topic: tele/bedroom_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
  - platform: mqtt
    name: "Fan Light"
    command_topic: "cmnd/bedroom_fan/power1"
    state_topic: "stat/bedroom_fan/POWER1"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

1 Like

i know its a stupid question . but where i can edit the config file. how can i access the device through putty or winscp ?

I’m not sure what you don’t know how to do…

Are you asking how to install and set up winscp and/or how to access your configuration files with it after you have it installed?

which method of accessing your config files is easiest to use depends on if you are using hassio or not?

yes thats it i want to access my configuration files after flashing the device.

You didn’t answer this question.

But if you are using hassio then install the samba add on and then use any text editor to edit the files. I use notepad++. There is a vscode add on you can use as well.

You guys are awesome! I just added my Tasmota Ifan03 to Hassio and working perfectly

now to make it even better you can install my fan control row via HACS or manually (I recommend HACS)