Beginners question, Fan Template

So, when searching for the answers everyone sounds like they know what they are talking about, but I just don’t get it.

What is the purpose of the Fan Template?

Since I don’t have a “smart fan” but a standard fan operated by a dual smart switch that allows me to control two speed settings, I thought the Fan Template would give me a generic fan so that HA believes it drives a real smart fan and I could then use the fan integration documented, or some card that is set up for fans, or whatever else.

To test this idea I put a basic version of the fan template into my configuration.yaml file to see what happens. But there is no additional integration available and no “fan card”, nothing that I can see that would make the fan template usable in any way.

What am I missing? Am I approaching this the wrong way?

Yes that is what it is for.

No idea. As you did not share your attempted config.

Thank you for your replies @tom_l , I did not think sharing the actual code was relevant as this about understanding the concept rather than problem solving. Anyway I pasted it below if it makes any difference.

I guess my questions boils down to this.

  1. What is the purpose of this generic fan?
  2. What am I supposed to be able to do with it?
  3. More specific, shouldn’t I be able to add this Fan integration after I added a fan template into the configuration file?

Here is the initial code. I am not saying it is correct yet, but I was expecting to gain some insight to above questions by giving it a go that way.

# https://www.home-assistant.io/integrations/fan.template
fan:
  - platform: template
    fans:
      bedroom_fan:
        friendly_name: "Bedroom Fan"
        value_template: "{{ states('switch.bedroom_fan') }}"
        preset_mode_template: "{{ states('input_select.fan_speed_select') }}"
        turn_on:
          service: switch.turn_on
          entity_id: switch.bedroom_fan
        turn_off:
          service: switch.turn_off
          entity_id: switch.bedroom_fan
        set_preset_mode:
          action: script.set_fan_speed
          data:
            preset_mode: "{{ preset_mode }}"
        speed_count: 2
        preset_modes:
          - "fast"
          - "slow"

To create a fan entity from other individual entities (switches, sensors, etc…)

Turn your fan on/off, adjust the speed (if configured).

No. That documentation applies to all fans, including your template fan entity. No need to add anything else.

I can adjust that for you if you tell me how the two switches relate to fan speed:

e.g. do they operate like this?

Sw2 Sw1 Speed
off off off
off on low
on off mid
on on high

Also tell me the entity ids of the two switches.

Thanks @tom_l, makes a bit more sense now.
Appreciate your offer. Here is my logic table, there are only two speed settings, fast and slow.

switch.bedroom_fan switch.bedroom_fan_slow Speed
on on slow
on off fast
off on off
off off off

And here is what I have already created and used so far, before looking into the Fan Template topic. Hope it makes sense.

sensor.fan_speed

{% if is_state("switch.bedroom_fan", "on") -%}
  {% if is_state("switch.bedroom_fan_slow", "on") -%}
    slow
  {%- else -%}
    fast
  {%- endif %} 
{%- else -%}
  off
{%- endif %} 

Script

alias: Set Fan Speed
fields:
  speed:
    selector:
      text: null
    name: Speed
    required: true
    default: "Off"
description: ""
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ speed | lower == \"fast\" }}"
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.bedroom_fan
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - switch.bedroom_fan_slow
        alias: fast
      - conditions:
          - condition: template
            value_template: "{{ speed | lower == \"slow\" }}"
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id:
                - switch.bedroom_fan
                - switch.bedroom_fan_slow
        alias: slow
      - conditions:
          - condition: template
            value_template: "{{ speed | lower == \"off\" }}"
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - switch.bedroom_fan
                - switch.bedroom_fan_slow
        alias: "off"
    default:
      - action: switch.turn_off
        metadata: {}
        data: {}
        target:
          entity_id:
            - switch.bedroom_fan
            - switch.bedroom_fan_slow
icon: mdi:fan-alert

I have also created input_select.fan_speed_select which I have used for tinkering with speed control user interfaces:

Ok that all looks good (though I’d use single quotes rather than escaping double quotes, but your way should work). Your template fan should generate an entity called fan.bedroom_fan which you can add to your dashboard. Do you not see it in Developer Tools → States or Settings → Devices & Services → Entities ?

Yes, the fan entity is there and when I add it to the dashboard I am asked to use a simple tile or entity card, depending on the Layout. There is nothing “fan-specific” about it, it’s just an on-off switch. I was expecting to be able to change the speed on the card somehow. The only thing that’s different is the Preset Mode drop-down in details (which by the way doesn’t work correctly at the moment yet)

Maybe I was expecting too much. I thought there must be a specific fan card or something else that provides me with a ready to go user interface.

This now begs the question, why go through all the effort of coding a fan template, when all I am getting is a standard tile or entity card? This is the point where I feel that something is amiss. :thinking:

There are fancier third party fan cards. e.g.

So, what you are saying is that the fan template is there in order to pave the way for further developments (either official HA or third party). This, to me, explains why it is worth while to set up a fan template.

Thank you so much for your help @tom_l , I appreciated your time and patience with me.

1 Like

Do you want to fix this?

If so, change your template fan from:

        set_preset_mode:
          action: script.set_fan_speed
          data:
            preset_mode: "{{ preset_mode }}"

to:

        set_preset_mode:
          action: script.set_fan_speed
          data:
            speed: "{{ preset_mode }}"
1 Like

Spot on, I was going to look into that tomorrow. I think you saved me from a bit of a headache ! :+1:

1 Like

Just another quick addition to this topic. Below is a screenshot of what the standard Tile Card with Fan connection looks like. It is simple and works well as a result of above discussion. Of course there are other options and I am tinkering with them right now. Thanks again @tom_l for your guidance.
Screenshot 2024-11-24 at 11.42.35 am

1 Like