Template Fan Speed Script and Remove Oscillation Option

I have a DC ceiling fan.
It has 5 speeds.
I have set it up in Home Assistant using a Template Fan to configure it.
The template uses scripts which instruct a Broadlink RM4 Pro to fire the RF commands to control the fan.
It’s almost perfect but I have a couple of things I’m stuck on.

  • I can control the speed of the fan using the slider BUT when I set it to Zero% no command is fired off from my RM4 Pro
  • I would like to be able to remove the Oscillation option from my fan’s config so the oscillation switch/option doesn’t show up in the controls
  • When I turn the fan on, the switch toggles on for a moment and then toggles back off, though it does actually send the power command (single command for an/off), so I can’t see the current status reflected in HA, I’m guessing this requires optimistic mode or something but can’t quite figure it out
  • When I open the fan controls I have Two icons that reflect Two directions, my fan uses the same code to switch directions rather than Two separate codes where One is for each direction. I’d like to replace these 2 icons with a single icon that reflects the current direction.

I hope I have made everything clear.
Following is the code I used to configure this fan.

The fan:

- platform: template
        friendly_name: "Living Room Fan"
        value_template: "{{ states('input_boolean.state') }}"
        percentage_template: "{{ states('input_number.percentage') }}"
        preset_mode_template: "{{ states('input_select.preset_mode') }}"
        oscillating_template: "{{ states('input_select.osc') }}"
        direction_template: "{{ states('input_select.direction') }}"
          service: script.lr_fan_power
          service: script.lr_fan_power
          service: script.lr_fan_direction
          service: script.lr_fan_set_speed
            percentage: "{{ percentage }}"
        speed_count: 5

The speed control script:

alias: lr_fan_set_speed
  - service: remote.send_command
      entity_id: remote.rm4_pro_remote
      device: Living Room Fan
      command: |-
        {% if percentage == 0 %}
        {% elif percentage == 20 %}
        {% elif percentage == 40 %}
        {% elif percentage == 60 %}
        {% elif percentage == 80 %}
        {% elif percentage == 100 %}
        {% endif %}
mode: single

You don’t have to include oscillation into your template (I’m relatively certain of this) so if you don’t include it then it won’t show.

As for setting things to 0 not sending a command, that is the same as OFF, so your off command should be firing.

With the initial power on also sending a power off, is it possible that your base 64 string is sending a repeat? If you trained your RM with the actual remote and the remote sends repeats that may be the problem. You should be able to test this by using the remote and holding the button down and see if it changes anything. You can also try re-training the RM by just quickly single tapping that power button.

As far as the multi-directional icon, you can achieve this using an icon template in your Lovelace, sort of like this that I use for upload/download and a Button Card from HACS:

type: 'custom:button-card'
  action: more-info
entity: sensor.qb
name: qb
show_state: true
  - value: downloading
    color: 'rgb(51, 255, 51)'
    icon: 'mdi:arrow-left-bold'
  - value: uploading
    color: 'rgb(255, 25, 25)'
    icon: 'mdi:arrow-right-bold'
  - value: up_down
    color: 'rgb(0, 68, 204)'
    icon: 'mdi:arrow-left-right-bold'