Template fan little question

Hi,

I’m trying to use the template fan to control my home ventilation.

It works almost but changing speed doesn’t work. The scripts won’t be called. The on works, and the fan runs high ad of the fan runs low. But selecting med or low won’t work.

I have this


fan:
  - platform: template
    fans:
      my_fan:
        value_template: "{{ states('sensor.ventilatie') }}"
        speed_template: "{{ states('sensor.ventilatie') }}"
        turn_on:
          service: script.fan_high
        turn_off:
          service: script.fan_low
        set_speed:
          service: fan.set_speed
          data_template:
            speed: >
              {% if speed == 'high' %}
                script.fan_high
              {% elif speed == 'medium' %}
                script.fan_medium
              {% elif speed == 'low' %}
                script.fan_low
              {% endif %}
        speeds:
          - 'high'
          - 'medium'
          - 'low'


  fan_low:
    alias: fanlow
    sequence:
      - service: shell_command.fan_low

  fan_medium:
    alias: fanmedium
    sequence:
      - service: shell_command.fan_medium

  fan_high:
    alias: fanhigh
    sequence:
      - service: shell_command.fan_high

shell_command:
  fan_high: "/usr/bin/curl -X GET http://192.168.180.72/control?cmd=event,stand3"
  fan_medium: "/usr/bin/curl -X GET http://192.168.180.72/control?cmd=event,stand2"
  fan_low: "/usr/bin/curl -X GET http://192.168.180.72/control?cmd=event,stand1"

can you format your code please?

Edit your post and use three ``` symbols before and after your code blocks.

EDIT, the ` symbol is the button below escape on your keyboard (on most keyboards)

Hi I formatted, hopefully someone can help me

I think the set speed needs to be a service template

fan:
  - platform: template
    fans:
      my_fan:
        value_template: "{{ states('sensor.ventilatie') }}"
        speed_template: "{{ states('sensor.ventilatie') }}"
        turn_on:
          service: script.fan_high
        turn_off:
          service: script.fan_low
        set_speed:
          service_template: >
            {% if speed == 'high' %}
              script.fan_high
            {% elif speed == 'medium' %}
              script.fan_medium
            {% elif speed == 'low' %}
              script.fan_low
            {% endif %}
        speeds:
          - 'high'
          - 'medium'
          - 'low'
1 Like

Thnx that works!!