Controller DC fans / Fan light combo - RF controlled

With lots of help on the forums, I’ve managed to get full (and mostly clean) controls set up for my DC fans (and one with a light). These are usually controlled with 433MHz RF remotes. States in HA are updated appropriately when the normal remotes are used. I’m using a Sonoff RF Bridge (flashed with Tasmota) for comms.

Looks like this:

Light switch:

#DC Fan Office Light Switch
switch:
  - platform: mqtt
    name: "Office light"
    icon: mdi:lightbulb-on-outline
    state_topic: "cmnd/sonoff_rfb_01/RESULT"
    command_topic: "cmnd/sonoff_rfb_01/RfKey7"
    optimistic: true
  - platform: mqtt
    name: "Lounge lamp"
    icon: mdi:lightbulb-on-outline
    state_topic: "stat/sonoff_s26_lounge/POWER"
    command_topic: "cmnd/sonoff_s26_lounge/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    state_on: "ON"
    state_off: "OFF"
    retain: true

Fan controls:

#DC Fan Control
input_select:
  fan_office:
    name: Office fan
    icon: mdi:fan
    options:
      - 'Off'
      - Very slow
      - Slow
      - Medium
      - Fast
      - Very fast
  fan_lounge:
    name: Lounge fan
    icon: mdi:fan
    options:
      - 'Off'
      - Very slow
      - Slow
      - Medium
      - Fast
      - Very fast  

Automations for setting fan speeds:

#DC Fan Controls
- alias: 'Office Fan Set'
  trigger:
    - platform: state
      entity_id: input_select.fan_office
  action:
    - service: mqtt.publish
      data_template:
        topic: >-
          {% set topics = {'Off':6, 'Very slow':5, 'Slow':4, 'Medium':3, 'Fast':2, 'Very fast':1} %}
          cmnd/sonoff_rfb_01/RfKey{{ topics[trigger.to_state.state] if trigger.to_state.state in topics.keys() else 'unknown' }}
        payload: ""

- alias: 'Lounge Fan Set'
  trigger:
    - platform: state
      entity_id: input_select.fan_lounge
  action:
    - service: mqtt.publish
      data_template:
        topic: >-
          {% set topics = {'Off':13, 'Very slow':12, 'Slow':11, 'Medium':10, 'Fast':9, 'Very fast':8} %}
          cmnd/sonoff_rfb_01/RfKey{{ topics[trigger.to_state.state] if trigger.to_state.state in topics.keys() else 'unknown' }}
        payload: ""

Automation for syncing HA fan speed states when changes with RF remote:

#DC Fan Sync
- alias: 'Office Fan Sync'
  trigger:
    - platform: mqtt
      topic: tele/sonoff_rfb_01/RESULT
  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.fan_office
      option: >-
        {% if '917103' in trigger.payload %}Very fast
        {% elif '91710D' in trigger.payload %}Fast
        {% elif '917105' in trigger.payload %}Medium
        {% elif '917104' in trigger.payload %}Slow
        {% elif '917101' in trigger.payload %}Very slow
        {% elif '917107' in trigger.payload %}'Off'
        {% elif '917183' in trigger.payload %}Very fast
        {% elif '91718D' in trigger.payload %}Fast
        {% elif '917185' in trigger.payload %}Medium
        {% elif '917184' in trigger.payload %}Slow
        {% elif '917181' in trigger.payload %}Very slow
        {% elif '917187' in trigger.payload %}'Off'
        {% endif %}

- alias: 'Lounge Fan Sync'
  trigger:
    - platform: mqtt
      topic: tele/sonoff_rfb_01/RESULT
  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.fan_lounge
      option: >-
        {% if 'AB3103' in trigger.payload %}Very fast
        {% elif 'AB310D' in trigger.payload %}Fast
        {% elif 'AB3105' in trigger.payload %}Medium
        {% elif 'AB3104' in trigger.payload %}Slow
        {% elif 'AB3101' in trigger.payload %}Very slow
        {% elif 'AB3107' in trigger.payload %}'Off'
        {% elif 'AB3183' in trigger.payload %}Very fast
        {% elif 'AB318D' in trigger.payload %}Fast
        {% elif 'AB3185' in trigger.payload %}Medium
        {% elif 'AB3184' in trigger.payload %}Slow
        {% elif 'AB3181' in trigger.payload %}Very slow
        {% elif 'AB3187' in trigger.payload %}'Off'
        {% endif %}
3 Likes

Are you able to provide any information on how you setup the sonoff bridge to send the correct codes out to the fan? I assume your solution was able to use the built in receiver in the fan, correct?

I flashed the Sonoff with Tasmota, then started pressing buttons on the fan controller (while watching the console feed) to get the RF codes corresponding to each button press. Those are all the codes (e.g. 917187) use in my setup above. I also used the Tasmota interface to record some of the (up to 16) programmable RF codes (i.e. where you see RFKey in the above).