Sonoff iFan03 Configuration

Good afternoon everyone.

I recently bought an iFan03 to control a ceiling fan.
Flashed it with Tasmota v8.5 and set it up in Rpi3b HA with this code in yaml:

  - platform: mqtt
    name: "Fan Stop"
    command_topic: "cmnd/iFan03/FanSpeed"
    payload_on: "0"
    payload_off: ""
    state_topic: "stat/iFan03/RESULT"
    state_on: ""
    state_off: "0"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1
    
  - platform: mqtt
    name: "Fan Slow"
    command_topic: "cmnd/iFan03/FanSpeed"
    payload_on: "1"
    payload_off: "0"
    state_topic: "stat/iFan03/RESULT"
    value_template: '{{ value_json.FanSpeed }}'
    state_on: "1"
    state_off: "0"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1
    
  - platform: mqtt
    name: "Fan Medium"
    command_topic: "cmnd/iFan03/FanSpeed"
    payload_on: "2"
    payload_off: "0"
    state_topic: "stat/iFan03/RESULT"
    value_template: '{{ value_json.FanSpeed }}'
    state_on: "2"
    state_off: "0"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1
    
  - platform: mqtt
    name: "Fan Fast"
    command_topic: "cmnd/iFan03/FanSpeed"
    payload_on: "3"
    payload_off: "0"
    state_topic: "stat/iFan03/RESULT"
    value_template: '{{ value_json.FanSpeed }}'
    state_on: "3"
    state_off: "0"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1
    
  - platform: mqtt
    name: "Ventilation Fan"
    command_topic: "cmnd/iFan03/POWER1"
    payload_on: "ON"
    payload_off: "OFF"
    state_topic: "stat/iFan03/POWER1"
    state_on: "ON"
    state_off: "OFF"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1

This created 4 independent switches on HA the way I like them that turn on and off fine and states are reporting correctly for each one.

So I turn on Fan Slow and state changes to on just fine.
What I would like to happen, is when I turn on Fan Medium the state of Fan Slow changes to off and when Fan Fast turns on the states of Fan Slow and Fast Medium changes to off respectively.
So I would like only one state to be highlighted at each time, the one that the fan is turning.

On iFan03 Tasmota 8.5 console I use the following 2 rules:
rule1 on Mqtt#Connected do publish cmnd/iFan03/POWER1 endon
rule2 on Mqtt#Connected do publish cmnd/iFan03/FanSpeed endon

and status is:
stat/iFan03/STATUS = {“Status”:{“Module”:71,“DeviceName”:“iFan03”,“FriendlyName”:[“iFan03”],“Topic”:“iFan03”,“ButtonTopic”:"",“Power”:2,“PowerOnState”:3,“LedState”:8,“LedMask”:“FFFF”,“SaveData”:1,“SaveState”:1,“SwitchTopic”:"",“SwitchMode”:[0,0,0,0,0,0,0,0],“ButtonRetain”:0,“SwitchRetain”:0,“SensorRetain”:0,“PowerRetain”:1}}

The problem is that if HA is restarted the status of iFan03 switches is not synchronised.
Same settings in a number of Sonoff basics with fw 6.x synchronise correctly.

Thank you
George

Sorry, I meant to get back to this a long time ago (and even bookmarked it for that purpose) but it got really lost in the shuffle.

Are you still having issues with this or did you get it working?

Still the same, working, but no status sync after HA restart.

So if the status of iFan is on (in any FanSpeed),
if I restart HA everything will show as off, even though its on.

try adding this to your automations:

  - alias: 'Check MBR Ceiling Fan State on HA Start'
    initial_state: 'on'
    trigger:
      platform: homeassistant
      event: start
    action:
      - service: mqtt.publish
        data:
          topic: "cmnd/iFan03-2/FanSpeed"
          payload: ""

Make sure you update the topic to your command topic.

it should automatically report the last command received on HA restart.

Thanks but does not work.
Tried it today it, gives errors on log:

Invalid config for [automation]: required key not provided @ data[‘action’]. Got None

Can you post what you have now for that automation (properly formatted)?

In switches.yaml I have this code that behaves exactly like I want it.
It creates separate switches where if you switch on i.e. “Fan Slow” all others switch to off.
Ventilation Fan (the switch for lamp in iFan03) gives correct state when I restart HA.
Fan Slow/Medium/High gives correct state no matter what I press but does not give correct state if I restart HA. So If I switch on [Fan Slow] and restart HA the state of the switch is off, although the actual fan in on. I would like that also to be in sync.

  - platform: mqtt
    name: "Fan Stop"
    command_topic: "cmnd/iFan03/FanSpeed"
    payload_on: "0"
    payload_off: ""
    state_topic: "stat/iFan03/RESULT"
    state_on: ""
    state_off: "0"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1
    
  - platform: mqtt
    name: "Fan Slow"
    command_topic: "cmnd/iFan03/FanSpeed"
    payload_on: "1"
    payload_off: "0"
    state_topic: "stat/iFan03/RESULT"
    value_template: >
      {% if value_json.FanSpeed == 1 -%}1
      {%- elif value_json.FanSpeed == 2 -%}0
      {%- elif value_json.FanSpeed == 3 -%}0
      {%- elif value_json.FanSpeed == 0 -%}0
      {%- endif %}
    state_on: "1"
    state_off: "0"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1
    
  - platform: mqtt
    name: "Fan Medium"
    command_topic: "cmnd/iFan03/FanSpeed"
    payload_on: "2"
    payload_off: "0"
    state_topic: "stat/iFan03/RESULT"
    value_template: >
      {% if value_json.FanSpeed == 2 -%}2
      {%- elif value_json.FanSpeed == 1 -%}0
      {%- elif value_json.FanSpeed == 3 -%}0
      {%- elif value_json.FanSpeed == 0 -%}0
      {%- endif %}
    state_on: "2"
    state_off: "0"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1
    
  - platform: mqtt
    name: "Fan Fast"
    command_topic: "cmnd/iFan03/FanSpeed"
    payload_on: "3"
    payload_off: "0"
    state_topic: "stat/iFan03/RESULT"
    value_template: >
      {% if value_json.FanSpeed == 3 -%}3
      {%- elif value_json.FanSpeed == 1 -%}0
      {%- elif value_json.FanSpeed == 2 -%}0
      {%- elif value_json.FanSpeed == 0 -%}0
      {%- endif %}
    state_on: "3"
    state_off: "0"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1
    
  - platform: mqtt
    name: "Ventilation Fan"
    command_topic: "cmnd/iFan03/POWER1"
    payload_on: "ON"
    payload_off: "OFF"
    state_topic: "stat/iFan03/POWER1"
    state_on: "ON"
    state_off: "OFF"
    availability_topic: "tele/iFan03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    retain: false
    qos: 1

fan

In automation.yaml I just pasted the code above that you gave me, with only correcting the topic to “cmnd/iFan03/FanSpeed” to match my own topic.
In HA=>Configuration=>Server Controls if I press the [Check Configuration] I do get the “Configuration Valid” message but in the notifications/logs I get the “Invalid config for [automation]: required key not provided @ data[‘action’]. Got None”

Thank you

please humor me and post what you have for that automation.

And you are sure it’s that automation? If you remove that automation the error goes away?

You are correct. It works as you said.
Used this:

- alias: 'Check iFan03 State on HA Start'
  initial_state: 'on'
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "cmnd/iFan03/FanSpeed"
        payload: ""

I must have messed the formatting on my end last night .
Now the whole concept works flawlessly!
Thank you very much. I wanted this!

1 Like