Can iFan02 be 'translated' for another fan speed controller?

I recently purchased some Deta light & fan speed controllers (in Australia). I have another that I’ve had for a while, and just set up a glance card to change the fan speed as well as turn it on or off (Fan control - Album on Imgur)

We also recently added a smart fan to Home Assistant which uses the Tuya MCU. This fan uses a custom fan card (Fan Card - Album on Imgur)

What I would like to do is ‘convert’ the iFan02 output and YAML seen at Sonoff iFan02 — ESPHome so that I can use the custom fan card instead of the glance card for my new light & fan speed controllers. It seems like this is possible but I’m not aware of any possible caveats so just looking for a bit of a nudge in the right direction.

Here is the YAML for the wall switch I’m using:

esphome:
  name: garageswitch
  platform: ESP8266
  board: esp01_1m
  esp8266_restore_from_flash: true

wifi:

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

switch:
  - platform: gpio
    id: relay_3
    pin: GPIO3
    name: 'Garage Switch Power Indicator'
    inverted: true

  - platform: gpio
    id: relay_1
    pin: GPIO14
    name: 'Garage Light Switch'
    
  - platform: gpio
    id: relay_2
    pin: GPIO4
    name: "High Fan"
    
  - platform: gpio
    id: relay_4
    pin: GPIO13
    name: "Low Fan"
    
  - platform: gpio
    id: relay_5
    pin: GPIO15
    restore_mode: restore_default_off
    name: "Medium Fan"
    
    
binary_sensor:
  - platform: gpio
    internal: true
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
    id: gpio0
    name: Fan Power
    on_release:
      - if:
          condition:
            - switch.is_on: relay_4
          then:
            - switch.turn_off: relay_2
            - switch.turn_off: relay_5
            - switch.turn_off: relay_4
          else:
            - switch.turn_on: relay_2
            - switch.turn_on: relay_5
            - switch.turn_on: relay_4
          

  - platform: gpio
    internal: true
    pin:
      number: GPIO16
      mode: INPUT_PULLUP
    id: gpio16
    name: Light Switch
    on_release:
      - if:
          condition:
            - switch.is_on: relay_1
          then:
            - switch.turn_off: relay_1
          else:
            - switch.turn_on: relay_1
            
  - platform: gpio
    internal: true
    pin:
      number: GPIO5
      mode: INPUT_PULLUP
    id: gpio5
    name: Fan Speed
    on_release:
      - if:
          condition:
            - switch.is_on: relay_2
          then:
            - switch.turn_off: relay_2
          else:
            - if:
                condition:
                  - switch.is_on: relay_5
                then:
                  - switch.turn_off: relay_5
                else:    
                  - if:
                      condition:
                        - switch.is_on: relay_4
                      then:
                        - switch.turn_on: relay_5
                        - switch.turn_on: relay_2

How do the Deta fan controllers get added to HA? Is there an integration fort them or do you use some other method to create the fan entity in HA?

I doubt you could use the iFan02 ESPHome code for that fan since the iFan02 uses a strange remote control functionality that needs that iFan02.h file to do some conversions.

If the Deta fan already exists in HA as a fan entity then you should be able to use one of my fan plugins to control it already like you already use for the Tuya fan.

So, the fan controllers are discovered via the ESPHome Integration, and the fan speed and on/off entities are all added as switches (so a switch each for low/med/high, light, and fan on/off). Here’s how it looks at the moment: Switches - Album on Imgur

you can create a template fan out of those switches and then you can use one of my plugins just like the one you already use.

there are examples of converting a broadlink fan to a fan entity at my github. They likely won’t be exactly what you need (although they might be) but you might be able to use it for inspiration.

1 Like

Thanks finity. I think I’m close to having this set up, here’s what I have done, using your fan_package_preset_modes_broadlink.yaml example:

  • Added the ‘script’ section (lines 36 to 106) to scripts.yaml
  • Added the ‘automation’ section (lines 133 to 184) to automations.yaml
  • Ignored the switch section as I’ve already got the switches configured in the ESPHome config file
  • Added the ‘fan’ section (lines 1 to 21) to configuration.yaml

Where I’m stuck is where to put the input_select and input_boolean sections - It has been a couple of weeks since I last looked at this but from memory I tried putting those in the configurations.yaml and HA didn’t like it.

Thanks again!

Sorry since you didn’t tag me or reply to my post I didn’t see this until just now. (Unless you did and I missed it somehow…)

you can put them in a package or you can put them in configuration.yaml.

I’m not sure what you mean by “HA didn’t like it”.

Errors?

what is the code you used to put it in the config yaml file?

Ok so I dove back into this @finity - Code appears to all be OK unless I am missing something, but the fan control card does nothing when I click on the low/med/high buttons.

Taking a look at the HA logs I see this:
Screenshot from 2021-08-21 07-55-43

But the entity does exist:

I’m going to go back over what I have put in but if you have any other ideas would be happy to hear it.

Edit: When I manually run the script for Audrey Fan Low, it does turn on for around a second but then turns back off again.

I’m really not sure why you got that error since the entity does exist.

usually that means that there is something wrong with the state feedback in the fan template.

If the state doesn’t update then the displayed state goes back to what it was previously.

@finity thanks again for all your help here, I did a little more research and ended up using the below. It will probably need a little more tweaking, only issue I have now is that because fan_speed is deprecated I need to work out how I can modify this to use the percentage.

I’ve voted to bring the fan_speed back in as well, but based on the below are you able to help me “convert” this at all? I can’t seem to get the ol’ noggin around it.

fan:
  - platform: template
    fans:
      audrey_fan:
        value_template: "{{ states('input_boolean.audrey_fan') }}"
        preset_mode_template: "{{ states('input_text.audrey_fan') }}"
        turn_on:
          - service: input_text.set_value
            data:
              entity_id: switch.bed_1_low_fan_2
              value: 'low'
          - service: homeassistant.turn_on
            entity_id: switch.bed_1_low_fan_2, input_boolean.audrey_fan
        turn_off:
          - service: homeassistant.turn_off
            entity_id: switch.bed_1_low_fan_2, switch.bed_1_high_fan_2, input_boolean.audrey_fan
        set_speed:
          - service_template: "switch.turn_{{'on' if speed in ['low', 'medium'] else 'off'}}"
            entity_id: switch.bed_1_low_fan_2
          - service_template: "switch.turn_{{'on' if speed in ['high', 'medium'] else 'off'}}"
            entity_id: switch.bed_1_high_fan_2
          - service: input_text.set_value
            data_template:
              entity_id: input_text.audrey_fan
              value: '{{speed}}'


input_text:
  audrey_fan:
    name: Audrey Fan Speed

input_boolean:
  audrey_fan:
    name: Audrey Fan Power