Trying to convert my RF fan into an fan entity

I now have a fan template entity and a script to toggle the rf fan based on what mode it is. The script works when I send a service with a preset mode. But the fan entity it self does not trigger any of the fan speeds except for ‘off’ which is the only one that works. Was wondering if anyone can help me figure out this issue.

Fan template entity:

fan:
  - platform: template
    fans:
      office_rf_fan:
        friendly_name: "Office RF fan"
        value_template: "{{ states('switch.pcroom_wall_switch') }}"
        turn_on:
          - service: script.office_rf_fan_on
        turn_off:
          - service: script.office_rf_fan_off
        percentage_template: "{{ states('input_number.office_rf_fan') }}"
        set_percentage:
          - service: script.office_rf_fan_speed_percentage
            data:
              percentage: "{{ percentage }}"
        preset_mode_template: "{{ states('input_select.office_rf_fan') }}"
        speed_count: 6
        preset_modes:
          - "off"
          - "1"
          - "2"
          - "3"
          - "4"
          - "5"
          - "6"
        set_preset_mode:
          - service: script.office_rf_fan_speed
            data:
              preset_mode: "{{ preset_mode }}"

Script:

office_rf_fan_speed:
  alias: office_rf_fan_speed
  sequence:
    - service: input_select.select_option
      target:
        entity_id: input_select.office_rf_fan
      data:
        option: "{{ preset_mode }}"
    - service: mqtt.publish
      data_template:
        topic: cmnd/office_rf_bridge/Backlog
        payload: "{{ 'RFRAW AA B0 21 03 08 04CE 0168 30F2 28181818181818181908190908181819081819081908190819 55 RFRAW 0' if preset_mode == 'off' else 'RFRAW AA B0 21 03 08 04D8 0172 3246 28181818181818181908190908181819081819081909090819 55 RFRAW 0' if preset_mode == '1' else 'RFRAW AA B0 21 03 08 04C4 0186 30FC 28181818181818181908190908181819081819081909081819 55 RFRAW 0' if preset_mode == '2' else 'RFRAW AA B0 21 03 08 04BA 0190 31C4 28181818181818181908190908181819081819081908181909 55 RFRAW 0' if preset_mode == '3' else 'RFRAW AA B0 21 03 08 04CE 0172 312E 28181818181818181908190908181819081819081819081909 55 RFRAW 0' if preset_mode == '4' else 'RFRAW AA B0 21 03 08 04CE 0172 30CA 28181818181818181908190908181819081819081819090819 55 RFRAW 0' if preset_mode == '5' else 'RFRAW AA B0 21 03 08 04BA 017C 30DE 28181818181818181908190908181819081819081819090909 55 RFRAW 0' if preset_mode == '6' }}"
  mode: single

Now I’m trying percentage as well, but the entity does not trigger the rf, but manually using the script does.

Percentage script:

office_rf_fan_speed_percentage:
  alias: office_rf_fan_speed_percentage
  sequence:
    - service: input_number.set_value
      target:
        entity_id: input_number.office_rf_fan
      data:
        value: "{{ percentage }}"
    - service: mqtt.publish
      data_template:
        topic: cmnd/office_rf_bridge/Backlog
        payload: "{{ 'RFRAW AA B0 21 03 08 04CE 0168 30F2 28181818181818181908190908181819081819081908190819 55 RFRAW 0' if percentage == '0' else 'RFRAW AA B0 21 03 08 04D8 0172 3246 28181818181818181908190908181819081819081909090819 55 RFRAW 0' if percentage == '16' else 'RFRAW AA B0 21 03 08 04C4 0186 30FC 28181818181818181908190908181819081819081909081819 55 RFRAW 0' if percentage == '33' else 'RFRAW AA B0 21 03 08 04BA 0190 31C4 28181818181818181908190908181819081819081908181909 55 RFRAW 0' if percentage == '50' else 'RFRAW AA B0 21 03 08 04CE 0172 312E 28181818181818181908190908181819081819081819081909 55 RFRAW 0' if percentage == '66' else 'RFRAW AA B0 21 03 08 04CE 0172 30CA 28181818181818181908190908181819081819081819090819 55 RFRAW 0' if percentage == '83' else 'RFRAW AA B0 21 03 08 04BA 017C 30DE 28181818181818181908190908181819081819081819090909 55 RFRAW 0' if percentage == '100'}}"
  mode: single

Found the issue,

added a persistent notification to my script to check the output of {{ percentage }} and {{ preset_mode }} and it doesn’t have quotation in the output where as in the payload the number is in quotations, removed it and now its working

service: persistent_notification.create
data_template:
  title: Office rf% test
  message: |-
    Msg: {{ percentage }}