Using iFan03 with Home Assistant and Homekit

Greetings!

I have been able to successfully add an iFan03 to Home assistant, using the following settings:

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

However, when Homekit starts, it gives the following complaint, and wont start:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/homekit/type_fans.py", line 157, in update_state
    hk_speed_value = self.speed_mapping.speed_to_homekit(speed)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/homekit/util.py", line 201, in speed_to_homekit
    speed_range = self.speed_ranges[speed]
KeyError: 'off'

Any ideas how I need to modify the ifan03 stuff in configuration.yaml?

Regards!

try removing the “- off” in the speed listing. I’m not really sure if that’s necessary or not.

I don’t use homekit so I can’t help any further than that.

try adding " quotes around the off

I think ha is see the off as 0 not a word off

so i would try

    speeds:
      - "off"
      - "low"
      - "medium"
      - "high"

hope this make cents

Thank you!
The quotes around the speed names fixed the issue with homekit.

Regards!

As an FYI, HA doesn’t need the quotes around the “off” or any the others in the speed list. I have several fans set up and they all work fine without quotes. But apparently homekit needs them.

The more we use various parts of HA, the more we learn!

Thanks to both @finity for the configuration.yaml code, and also @myle for the quotes needed for the homekit integration for the ifan03 controllers!

As a side note, how would I change the structure above to add additional ifan03s for other ceiling fans. Would i just need a fans: clause above the individual fan definitions??

Thanks both of you!

the entries under the “fans:” section are in a list format which is denoted by the very first “-” in front of “platform:”.

so to add another fan then you just use another “-” and put in the fan config.

Like:

fan:
  - platform: mqtt
    name: "SW BDRM"
    command_topic: "cmnd/swbdroom/FanSpeed"
    speed_command_topic: "cmnd/swbdroom/FanSpeed"
    state_topic: "stat/swbdroom/RESULT"
    speed_state_topic: "stat/swbdroom/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.sw_bdrm.state == 'off' -%}0
        {%- elif states.fan.sw_bdrm.state == 'on' -%}4
        {%- endif %}
      {% endif %}
    speed_value_template: "{{ value_json.FanSpeed }}"
    availability_topic: tele/swbdroom/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
    **other fan config code
  - platform: ** some other platform
    ** some other fan config code

Thanks @finity!

Regards!

with Quotes around the “off”
image

with no Quotes on the Off

Im running the current version

I’ve seen that too but it doesn’t effect the operation of the fan in HA. selecting false still turns off the fan.

But thanks for pointing it out. I’ll update the tasmota wiki and my fan control row docs to eliminate confusion.

Can someone help me with the IFan02 Automation. i have a Sonoff Power Switch to control the IFan02, so if i switch off by using the switch, Ifan02 get disconnected from the WiFi ( this is due to i am cutting the power to the Ifan02) so that is normal.

Now if i switch on the power to the Ifan02 via the Sonoff wall Switch, Fan will not switch on right away it need time to connect to the WiFi Access Point and then have to use the Hassio App to switch on.

This is where i need the Automation to run- until Ifan02 find the WiFi Access-point and then get connected to the Hassio i need a script to look for the ifan02 status and if it is available then switch on the fan, if it is not available keep trying.

I have done this Manually by adding Automation Via the Hassio UI- and it works. but i think there is a short way i can achieve this with a simple code. ( I have 5 x Ifan02 and 3 x Ifan03) further more ifan03 has no issue i can always use the Remote on the wall even after tasmota installed.

Triggers

device_id: 644c7d0a14a845a89a1b03425fec0d17
domain: light
entity_id: light.dining_room_wall_3
for:
  hours: 0
  minutes: 0
  seconds: 30
platform: device
type: turned_on

Actions

data: {}
entity_id: fan.dining_fan
service: fan.turn_on

delay: ‘00:00:30’

data: {}
entity_id: fan.dining_fan
service: fan.turn_on

```

You have to set the speed for the fan. you need to change the service to

service: fan.set_speed

and also add in the data: section right above the service: line

speed: medium. ## or low or high, depending what you want.

If that doesn’t fix it, post your relevant section of the configuration.yaml .

action:

  • data:
    entity_id: fan.test_fan
    speed: medium
    service: fan.set_speed

Regards.