Sonoff iFan03 with Tasmota Configuration (using MQTT)

Hi,

Can anyone please give me an idiots guide on configuring a Sonoff iFan03 with Tasmota firmware so that it will work with MQTT?

I’ve put a fan: entry into my configuration.yaml file but the entity it defines is still shown as ‘unavailable’ in the device view.

Is anyone able to walk me through the entire process please? I’m wondering if i’ve missed something in the MQTT config in Tasmota.

Grateful for any help received.

Thanks

Pete

I found I had a duplicate MQTT broker. Fixed that and this now looks ok?

And specifically the iFan03 shows up?

But i’m not sure if my YAML is right:

Based on this MQTT configuration:

It generally looks right to me.

The only question is are you going to be running it with the plain toggle for on/off and the drop down for changing speeds or are you planning on using my fan control row?

Depending on which way you will use it there might be a couple of changes you need to make to the yaml.

Hi,

I wanted to use your fan control row, and since I posted this i’ve made a few changes to make it clearer what is happening.

Right now the main issue I see is when I look in the state view it shows ‘fan.conservatoryfan’ as being unavailable (note, that one of the changes I made was to rename the device in configuration.yaml as the name previously was similar to another fan and it was causing confusion).

I also noticed in the configuration.yaml that the state_value_template section makes reference to the name of the entity and i’d failed to update that. My YAML entry for the fan now looks like this:

fan:
  - platform: mqtt  
    name: "ConservatoryFan"
    command_topic: "cmnd/iFan03-1/FanSpeed"
    speed_command_topic: "cmnd/iFan03-1/FanSpeed"    
    state_topic: "stat/iFan03-1/status"
    speed_state_topic: "stat/iFan03-1/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/iFan03-1/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

If you have any idea as to why it might still show as unavailable in Home Assistant then i’d be really grateful to hear your thoughts.

It looks like you might be using discovery for your MQTT devices. At least that’s what it looks like from the second picture in your first post above.

It’s possible that may be interfering with the yaml configured fan.

you could try deleting the fan from the mqtt integration and then see if that fixes the “unavailable” issue.

Or try to restart the iFan03 first and see if that re-sends the LWT message.

1 Like

I’m limited what I can do because i’m not actually at home right now.

However, what I did try was going into the Terminal in Hassio and running this command:

mosquitto_sub -h localhost -u mosquitto -P redacted -v -t ‘#’

If I then connect to the web interface for Tasmota on the iFan03 and toggle some of the states there then I see this in the console in Hassio:

I’m pretty sure the iFan will have been restarted in the last day because my wife still has a habit of shutting it off at the main switch and I only turned it back on last night. If you think it might be worth deleting the item in the Integrations section then please let me know and I can give that a try.

Are you sure she didn’t turn it back off again? :wink:

But yeah, if it’s still showing as unavailable after cycling power to it then I would try to remove the one from the integration and restart HA to see if it fixes it.

I don’t ever use discovery so I can’t really help you much there.

Are you sure she didn’t turn it back off again? :wink:

She was out this morning when I was working on it remotely; plus if the Tasmota Web UI is up and running then device must be powered right?

Out of interest how can I remove a single device from the integration please?

When I go into the MQTT Broker integration there is a trashcan icon at the top right but that appears to delete the entire integration and not just the single entity?

There is a gear icon against each entity but clicking that only allows me to change the name and the area where the item is placed.

You know…I have no idea.

You may have to delete each entity from the entity registry?

Or you might have to manually edit the device registry in the .storage folder. That’s not recommended but I really don’t know of another way.

There definitely should be a way to just delete an entire device from the GUI just like you can delete entities. But if there isn’t that should definitely be created.

Thanks for your help.

I did a bit of digging around and apparently it is possible to remove the entity using an MQTT command. In my case I took the more drastic route of entirely removing the integration and then configuring it again.

I’m currently having a play around with the config and will report back what I find.

I presume if you don’t turn on discovery then you must manually define the entities in the YAML in a similar manner to how we are doing for the iFan?

that’s correct.

Ok, so I feel like i’m slowly losing the plot here. I have removed the integration and then re-added it again.

When adding I used this configuration.

mqtt3

For now I will leave discovery turned off. I understand this means that the three Sonoff Basics i’ve got and the Sonoff S20 won’t appear in the config, but that’s fine. I can manually define those later if needed.

I have also gone into Tasmota UI and made sure that MQTT is enabled and a unqiue friendly name is set.

I also changed the topic in Tasmota UI to something a bit more concise. At the same time I re-entered the user and password to make sure that this was also correct.

Still seems no luck though :frowning:

And i’m not sure if the MQTT device should show up under here in integrations?

mqtt7

Finally, just for the sake of clarity. Here is my updated entry in the YAML file. I changed the topic name to reflect the new name defined in Tasmota.

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

If you have any more clues then i’d really appreciate the help. :slight_smile:

I got it working - and I can’t believe I hadn’t spotted the issue before.

The Full Topic value is the wrong way round. It was defined as ‘%topic%/%prefix%/’ and i’m pretty sure that was how it was set initially. But ‘default’ value shown above next to the words ‘Full Topic’ clear show it the other way round.

I wasn’t sure that was the issue but I figured it was worth a try. And sure enough…

I need to do a bit more testing but I think the issue might be solved.

Good catch! :slightly_smiling_face:

I’m not sure why it would have been that way tho. Mine is freshly flashed with the latest firmware that supports the iFan03 and mine defaulted to the way the example shows (’%prefix%/%topic%/’).

Hopefully that was the whole problem.

Thanks finity.

I’ve no idea why it was that way. I had a ‘dead’ Sonoff Basic in the front room which had dropped off the wifi when I tried to reconfigure it and i’ve just got that going again by hooking up the FTDI to it and using the Backlog command to get it back online. That also had the same configuration in the Full Topic field. The only thing I can think is that maybe I got the first one misconfigured and then copied it to the next. The strange thing is that they have all been working fine but I don’t know if that’s because how the discovery process works.

If i’m not using discovery then will the icons for the devices still show up under Integrations->MQTT? Right now i’ve tried to manually configure the fan and another Sonoff Basic.

The fan is showing up in the device state list but the Sonoff Basic isn’t for some reason. And when I go into Integrations-MQTT there is nothing listed under there.

Is that how it should be?

And can you give me an example of what the config for a Sonoff Basic would be? I’ve got a couple of those hooked up to lamps but previously used discovery; it might be nice to manually define them so i’ve got more control over the config.

Well, it looks to be a red herring because although the device is now showing some status i’ve found that using the buttons on the defined fan has no impact at all on the fan. It doesn’t come on, nor do the lights turn on and off.

I’ve found similar issues with the Sonoff Basics i’ve tried to configure.

I’ve also noticed that changing the full topic to %prefix%/%topic%/ causes the device to reboot and once it’s finished booting the UI shows it as being back to %topic%/%prefix%. I also tried using the FullTopic command to manually set the value and that also failed to work.

So, i’m back to square 1 again. Any more ideas please folks?

I figured it out I think.

The Tasmota firmware was still configured for auto-discovery and this was why the Full Topic kept getting reset.

I used SetOption19 0 on the console to turn off auto-discovery and now I can set the Full Topic and the Sonoff Basic allows the lamp to turn on and off.

Hurrah!!

Forgive me if this is slightly off topic since I am trying to make the iFan03 work with ESPHome as opposed to Tasmota. I have not been able to find documentation on the proper GPIOs in the iFAN03. For the 02 version those were GPIO0 for the lamp toggle, GPIO 9, 10 and 14 for each of the 3 speeds. Does this group know what the GPIOs are for the iFAN03 ? IN addition, is there a way to automate the fan rotation toggle (clockwise vs counter-clockwise) ? Any help would be appreciated ! Thanks

I’m pretty sure the template I loaded then configures the GPIO settings.

Alas, it’s 1AM here and I need to go to bed. If noone has replied by the morning then i’ll try to dig out the config and post it here.

@finity So, the Fan is almost working now. If I go into the developer state view I can see the entity and using the menu I can get the fan moving. However, it doesn’t seem to want to allow me to stop the fan, nor can the light be controller.

Should the YAML I originally posted support that feature?

I also tried using the fan controller in Lovelace (I think it’s the one you built) and the left three buttons seem to move through the fan speeds but the very right button doesn’t seem to have any impact.