Fan template for DC fan controlled by RF via Broadlink

Hi all, trying to get to know the fan template and use it to control 6-speed DC ceiling fans via RF with a Broadlink RM4 Pro. Using the learn command has been successful and I can get HA to send commands to the fan.

I have a helper toggle (for on/off) and slider (speeds) setup. The first issue I had was that after turning it on the switch would go back to the off state, hence the set value command, however I get the following error when it is switched - “Living Room Fan: Error executing script. Invalid data for call_service at pos 2: expected float for dictionary value @ data[‘value’]” - but if I check the state of the helper it is in the format on or off. So leaves me confused.

Next issue after that is that I’m not entirely sure how to implement the speed control for six speeds of a DC fan using the learned commands. Any pointers or examples would be great to help me.

  - platform: template
    fans:
      living_room_fan:
        friendly_name: "Living Room Fan"
        unique_id: living_room_fan
        value_template: "{{ states('input_boolean.fan_living_room_state') }}"
        turn_on:
          -  service: remote.send_command
             data:
               device: remote.fan_livingroom
               command: "wind speed 1"
               delay_secs: 0.5
             target:
               entity_id: remote.rf_remote_remote
          -  service: input_number.set_value
             target:
               entity_id: input_boolean.fan_living_room_state
             data:
               value: "on"
        turn_off:
          -  service: remote.send_command
             data:
               device: remote.fan_livingroom
               command: "turn off"
               delay_secs: 0.5
             target:
               entity_id: remote.rf_remote_remote
          -  service: input_number.set_value
             target:
               entity_id: input_boolean.fan_living_room_state
             data:
               value: "off"

I’ve solved my first issue

replaced

          -  service: input_number.set_value
             target:
               entity_id: input_boolean.fan_living_room_state
             data:
               value: "on"

with

          -  service: input_boolean.turn_on
             target:
               entity_id: input_boolean.fan_living_room_state

This is the state of the script now - still trying to work out how to do the speed, not having much luck :frowning:

  - platform: template
    fans:
      living_room_fan:
        friendly_name: "Living Room Fan"
        unique_id: living_room_fan
        value_template: "{{ states('input_boolean.fan_living_room_state') }}"
        preset_mode_template: "{{ states('input_number.fan_living_room_speed') |round(0) }}"
        turn_on:
          -  service: input_boolean.turn_on
             target:
               entity_id: input_boolean.fan_living_room_state
          -  service: input_number.set_value
             target:
               entity_id: input_number.fan_living_room_speed
             data:
               value: 1
          -  service: remote.send_command
             data:
               device: remote.fan_livingroom
               command: "wind speed 1"
               delay_secs: 0.5
             target:
               entity_id: remote.rf_remote_remote
        turn_off:
          -  service: input_boolean.turn_off
             target:
               entity_id: input_boolean.fan_living_room_state
          -  service: input_number.set_value
             target:
               entity_id: input_number.fan_living_room_speed
             data:
               value: 0
          -  service: remote.send_command
             data:
               device: remote.fan_livingroom
               command: "turn off"
               delay_secs: 0.5
             target:
               entity_id: remote.rf_remote_remote
        set_preset_mode:
          service: remote.send_command
          data:
            device: remote.fan_livingroom
            command: "wind speed {{ states('input_number.fan_living_room_speed') |round(0) }}"
            delay_secs: 0.5
          target:
            entity_id: remote.rf_remote_remote
        preset_modes:
          - '1'
          - '2'
          - '3'
          - '4'
          - '5'
          - '6'

Any update on this?
I’m also looking to control a dc fan that is made smart using the Broadlink rm 4 Pro.

Did you manage to solve this as I am just about to embark on the same journey