Get condition from attribute value

I am seeking for help to create an automation to decrease speed on my fan. I created as below but after all, the fan still turn_off. I don’t want it to turn off

  - platform: state
    entity_id: sensor.0x54ef44117a4a2_action  # change to your button
    to: button_3_single  # change to your button state
    condition: not
      - condition: template
        value_template: "{{ is_state_attr('fan.sofa_fan', 'percentage', '10') }}"
  - service: fan.decrease_speed
      percentage_step: 10
      entity_id: fan.sofa_fan
  mode: single

Here’s the attribute of the fan:

preset_modes: null
percentage: 40
percentage_step: 10
preset_mode: null
last_on_speed: '4'
device_code: 1160
manufacturer: Atomberg
  - Efficio
supported_controller: Broadlink
commands_encoding: Base64
friendly_name: Sofa fan
supported_features: 1


Your template is checking if the percentage is exactly 10. What if it is 9?

You don’t need a template to solve this.

    - condition: numeric_state
      entity_id: fan.sofa_fan
      attribute: percentage
      above: 10

Many thanks, I’ll try.
I have no skill on coding so it’s quite dificult for some issues

Dear tom_l,
Unluckily, it still turns the fan off.
When I tried the contribute to 20, luckily it works​:grinning::grinning::grinning:
Possibly the problem is with the value of tge contribute.
Thanks for your help
It’s the solution for me

What does the trace show:

It doesn’t seem to me to be an issue with the condition.

the action runs (maybe) but it is just performing the wrong action. So the condition has to be valid.

Are you sure there is no other automation/device controlling the fan?

as a test you could just completely remove the condition and see what the result of triggering the automation (by pushing the button) is.

Dear Finity,
It works already when I replaced value to 20

which value?

the condition value or the decrease_speed value?

OK, so let me try to understand better what is happening…

if you push the button and the percentage is greater than 10 then the automation works as it should?

if the percentage = 10 then the automation still runs and turns the fan off (because the percentage goes to 0)?

Dear Finity,
Value after “above” like below

    - condition: numeric_state
      entity_id: fan.sofa_fan
      attribute: percentage
      above: 20