Template Fan value resets to 1% when turned on

I’ve got an extremely simple fan template setup right now. For some reason, whenever I turn this template fan off and on again, the fan speed percentage becomes 1%, even though the input_number helper still has its old value. For example, I would set the fan speed to 33% (my fan has 9 speeds), then turn the fan off. When I turn the fan back on, the fan speed for the fan would show up as 1% instead of 33%. When I check the input_number entity, it still shows as 33%.

Does anyone know why that might be?

Here’s my really simple template:

  - platform: template
    fans:
      living_room_fan:
        friendly_name: "Living Room Fan"
        unique_id: "living_room_fan"
        value_template: "{{ states('input_boolean.ceiling_fan_state') }}"
        speed_template: "{{ states('input_number.ceiling_fan_speed') }}"
        speed_count: 9
        turn_on: 
          service: input_boolean.turn_on
          target: 
            entity_id: input_boolean.ceiling_fan_state
        turn_off:
          service: input_boolean.turn_off
          target: 
            entity_id: input_boolean.ceiling_fan_state
        set_percentage:
          service: input_number.set_value
          target:
            entity_id: input_number.ceiling_fan_speed
          data:
            value: "{{ percentage }}"

My input_number is set to have a minimum of 0 and a maximum of 100, with a step size of 1. I’m currently detecting the change in the input_number and input_boolean to control the fan, which is why you don’t see me calling any services in the template.

That’s likely important to include as well

I resolved the problem! It turns out I was using speed_template instead of percentage_template in the config! Once the config was updated, the percentage no longer resets. Perhaps the reason why it always “resets” was that speed_template expected a much smaller value than the percentage value in my input_number.

Only noticed this as I was re-reading my post. I guess this was a case of rubber ducky debugging haha.

Hi. I do have percentage_template and the same erratic behavior occurs. When turned off and back to on, percentage slider goes to 0. Input number keeps the correct states.

Fan toggle missing percentage has been fixed: