I created it through chatGPT
fan:
- platform: template
fans:
template_fan:
friendly_name: "範本風扇"
value_template: >
{% if is_state('binary_sensor.led_state', 'on') or
is_state('binary_sensor.led_state2', 'on') or
is_state('binary_sensor.led_state3', 'on') or
is_state('binary_sensor.led_state4', 'on') or
is_state('binary_sensor.led_state5', 'on') or
is_state('binary_sensor.led_state6', 'on') %}
on
{% else %}
off
{% endif %}
percentage_template: >
{% if is_state('binary_sensor.led_state6', 'on') %}
100
{% elif is_state('binary_sensor.led_state5', 'on') %}
83
{% elif is_state('binary_sensor.led_state4', 'on') %}
66
{% elif is_state('binary_sensor.led_state3', 'on') %}
50
{% elif is_state('binary_sensor.led_state2', 'on') %}
33
{% elif is_state('binary_sensor.led_state', 'on') %}
16
{% else %}
0
{% endif %}
turn_on:
service: switch.turn_on
target:
entity_id: switch.switch1_2
turn_off:
service: switch.turn_on
target:
entity_id: switch.switch1_2
set_percentage:
service: script.set_fan_speed
data:
percentage: "{{ percentage }}"
speed_count: 6
script:
set_fan_speed:
sequence:
- repeat:
count: "{{ ((percentage - state_attr('fan.template_fan', 'percentage')) // 17) | abs }}"
sequence:
- choose:
- conditions:
# 減少風速
- condition: template
value_template: "{{ percentage < state_attr('fan.template_fan', 'percentage') }}"
sequence:
- service: switch.turn_on
target:
entity_id: switch.switch2_2
- conditions:
# 增加風速
- condition: template
value_template: "{{ percentage > state_attr('fan.template_fan', 'percentage') }}"
sequence:
- service: switch.turn_on
target:
entity_id: switch.switch3_2
There is a bug in the use of this yaml. When the wind speed is 83 or 100, the fan will be turned off. It must be adjusted to 66 to display the status normally. Can you help me improve the problem?