Automation for IR fan speed (beoadlink rm mini 3)

I try to make automation for IR fan on/off + 5xspeed trough broadlink rm mini 3.

I have working switches:
on/off button - switch.kitchen_hood_fan_on_off

  • button - switch.kitchen_hood_fan_up
  • button - switch.kitchen_hood_fan_down

and input_number.kitchen_hood_fanspeed:

  kitchen_hood_fanspeed:
    name: "fanspeed"
    initial: 0
    min: 0
    max: 5

When I turn on fan with “switch.kitchen_hood_fan_on_off” fan always start on speed 2.

Automation must first start fan and decrise speed to 1 when I move slider from 0 to 1. Then must increse/decrese speed when I move slider 1-5. When I put it back to 0 must turn off fan.

I try like this but not working:

  - alias: Set fan speed
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
    action:
      service: switch.turn_on
      data_template:
        entity_id: >
          {% if is_state('input_number.kitchen_hood_fanspeed', '0.0') %}
            switch.kitchen_hood_fan_on_off
          {% elif is_state('input_number.kitchen_hood_fanspeed','1.0') %}
            switch.kitchen_hood_fan_up
          {% elif is_state('input_number.kitchen_hood_fanspeed','2.0') %}
            switch.kitchen_hood_fan_up
          {% elif is_state('input_number.kitchen_hood_fanspeed', '3.0') %}
            switch.kitchen_hood_fan_up
          {% elif is_state('input_number.kitchen_hood_fanspeed', '4.0') %}
            switch.kitchen_hood_fan_up
          {% elif is_state('input_number.kitchen_hood_fanspeed', '5.0') %}
            switch.kitchen_hood_fan_up
          {% endif %}
I try like this:
  - alias: Set fan speed
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
    action:
      service: switch.toggle
      data_template:
        entity_id: >
          {% if is_state('input_number.kitchen_hood_fanspeed', '0.0') %}
            switch.kitchen_hood_fan_on_off
          {% elif is_state('input_number.kitchen_hood_fanspeed','1.0') %}
            switch.kitchen_hood_fan_on_off, switch.kitchen_hood_fan_down
          {% elif is_state('input_number.kitchen_hood_fanspeed','2.0') %}
            switch.kitchen_hood_fan_up
          {% elif is_state('input_number.kitchen_hood_fanspeed', '3.0') %}
            switch.kitchen_hood_fan_up
          {% elif is_state('input_number.kitchen_hood_fanspeed', '4.0') %}
            switch.kitchen_hood_fan_up
          {% elif is_state('input_number.kitchen_hood_fanspeed', '5.0') %}
            switch.kitchen_hood_fan_up
          {% endif %}

Now when I go up is ok. but when I go down not working. How to check separate state for example if I move slider from 0-1 or 1-0?

Why this data_template not working:

  data_template:
    entity_id: >
      {% if is_state('input_number.kitchen_hood_fanspeed', '0.0') and is_state('trigger.from_state.state', '0.0') and is_state('trigger.to_state.state', '1.0') %}
        switch.kitchen_hood_fan_on_off, switch.kitchen_hood_fan_down

This is only the part if I have slider on 0.0 and move it from 0.0 to 1.0. Why not working? When I move slider from 0.0 to 1.0 nothing happens?

I also try like this:

  - alias: Set fan speed
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
    action:
      service: switch.toggle
      data_template:
        entity_id: >
          {% if is_state('trigger.from_state.state', '0.0') %}
            switch.kitchen_hood_fan_on_off, switch.kitchen_hood_fan_down
          {% elif is_state('trigger.to_state.state', '0.0') %}
            switch.kitchen_hood_fan_on_off
          {% endif %}

Not working. Is is_state(‘trigger.from_state.state’, ‘0.0’) and is_state(‘trigger.to_state.state’, ‘0.0’) correct?

There is working automation for IR FAN SPEED CHANGE:

  - alias: Set fan speed 0.0 to 1.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
      # Optional
      from: '0.0'
      # Optional
      to: '1.0'

    action:
      - service: switch.turn_on
        entity_id: switch.kitchen_hood_fan_on_off
      - service: switch.turn_on
        entity_id: switch.kitchen_hood_fan_down


  - alias: Set fan speed 1.0 to 0.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
      # Optional
      from: '1.0'
      # Optional
      to: '0.0'

    action:
      service: switch.turn_on
      entity_id: switch.kitchen_hood_fan_on_off

  - alias: Set fan speed 1.0 to 2.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed

      from: '1.0'
      to: '2.0'

    action:
      - service: switch.turn_on
        entity_id: switch.kitchen_hood_fan_up

  - alias: Set fan speed 2.0 to 1.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
      from: '2.0'
      to: '1.0'

    action:
      service: switch.turn_on
      entity_id: switch.kitchen_hood_fan_down

  - alias: Set fan speed 2.0 to 3.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
      from: '2.0'
      to: '3.0'

    action:
      - service: switch.turn_on
        entity_id: switch.kitchen_hood_fan_up

  - alias: Set fan speed 3.0 to 2.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
      from: '3.0'
      to: '2.0'

    action:
      service: switch.turn_on
      entity_id: switch.kitchen_hood_fan_down

  - alias: Set fan speed 3.0 to 4.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
      from: '3.0'
      to: '4.0'

    action:
      - service: switch.turn_on
        entity_id: switch.kitchen_hood_fan_up

  - alias: Set fan speed 4.0 to 3.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
      from: '4.0'
      to: '3.0'

    action:
      service: switch.turn_on
      entity_id: switch.kitchen_hood_fan_down

  - alias: Set fan speed 4.0 to 5.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
      from: '4.0'
      to: '5.0'

    action:
      - service: switch.turn_on
        entity_id: switch.kitchen_hood_fan_up

  - alias: Set fan speed 5.0 to 4.0
    trigger:
      platform: state
      entity_id: input_number.kitchen_hood_fanspeed
      from: '5.0'
      to: '4.0'

    action:
      service: switch.turn_on
      entity_id: switch.kitchen_hood_fan_down

But I have two problems. If I move slider up and down for one step at the time automation working. If I move fast from 1 to 5 nothing hepend. And I fan is manualy turned on and left on eg. speed 3 automation can’t check if fan is on or off and what speed is (this problem can’t be solved because of fan is ir I cen live with that or I can put some power meter before fan). But first problem probably can be solved somehow? Can automation like this be shorter?