Template Fan


The template platform creates fans that combine integrations and provides the ability to run scripts or invoke services for each of the turn_on, turn_off, set_speed, set_oscillating, and set_direction commands of a fan.

To enable Template Fans in your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
fan:
  - platform: template
    fans:
      bedroom_fan:
        friendly_name: "Bedroom fan"
        value_template: "{{ states('input_boolean.state') }}"
        speed_template: "{{ states('input_select.speed') }}"
        oscillating_template: "{{ states('input_select.osc') }}"
        direction_template: "{{ states('input_select.direction') }}"
        turn_on:
          service: script.fan_on
        turn_off:
          service: script.fan_off
        set_speed:
          service: script.fan_speed
          data:
            speed: "{{ speed }}"
        set_oscillating:
          service: script.fan_oscillating
          data:
            oscillating: "{{ oscillating }}"
        set_direction:
          service: script.fan_direction
          data:
            direction: "{{ direction }}"
        speeds:
          - '1'
          - '2'
          - '3'

Configuration Variables

fans map Required

List of your fans.

friendly_name string (Optional)

Name to use in the frontend.

unique_id string (Optional)

An ID that uniquely identifies this fan. Set this to a unique value to allow customization through the UI.

value_template template Required

Defines a template to get the state of the fan. Valid value: ‘on’/‘off’

speed_template template (Optional)

Defines a template to get the speed of the fan.

oscillating_template template (Optional)

Defines a template to get the osc state of the fan. Valid value: true/false

direction_template template (Optional)

Defines a template to get the direction of the fan. Valid value: ‘forward’/‘reverse’

availability_template template (Optional, default: true)

Defines a template to get the available state of the component. If the template returns true, the device is available. If the template returns any other value, the device will be unavailable. If availability_template is not configured, the component will always be available.

turn_on action Required

Defines an action to run when the fan is turned on.

turn_off action Required

Defines an action to run when the fan is turned off.

set_speed action (Optional)

Defines an action to run when the fan is given a speed command.

set_oscillating action (Optional)

Defines an action to run when the fan is given an osc state command.

set_direction action (Optional)

Defines an action to run when the fan is given a direction command.

speeds string | list (Optional)

List of speeds the fan is capable of running at.

Default:

[“low”, “medium”, “high”]

Working without entities

If you use a template that depends on the current time or some other non-deterministic result not sourced from entities, the template won’t repeatedly update but will only update when the state of a referenced entity updates. For ways to deal with this issue, see Working without entities in the Template Binary Sensor integration.