Configuring fan template using climate component

So first of all, what I’m trying to do is ‘extracting’ the fan functionality from a climate component, into a separate component, so that I can control the fan speed from homekit, since homekit isn’t able to control the fan speed from it’s thermostat thing.

In order to do this i’m trying to use the Fan Template component but I’m having issues configuring it properly. Also, if you have another idea of how can i achieve the main goal, i’m open to suggestions.

(also note that i’m relatively new to home assistant configuring anything more than basic stuff)

What i did so far is a configuration that looks like this:

fan:
 - platform: template
   fans:
     livingroom_fan:
       friendly_name: "Livingroom Fan"
       value_template: >
         {% if is_state('climate.living_room', 'Off') %}
           off
         {% else %}
           on
         {% endif %}
       speed_template: "{{state_attr('climate.living_room', 'fan_mode')}}"
       oscillating_template: >
         {% if is_state_attr('climate.living_room', 'swing_mode', 'Off') %}
           False
         {% else %}
           True
         {% endif %}
       speeds:
        - '1'
        - '2'
        - '3'
        - '4'
        - '5'
        - 'Auto'
        - 'Silence'
       set_speed:
         service: climate.set_fan_mode
         data:
           entity_id: climate.living_room
           fan_mode: speed -> this is wrong

So a few questions and observations regarding this config:

  • for value_template i saw i needed to output on or off, so i’m reading from the climate component and outputting off for Off and on for anything else
  • for speed_template i’m reading from climate’s fan_mode directly
  • i’m listing the speeds manually but i saw that climate has a fan_list array which contains exactly what i’m enumerating manually, but I didn’t quite get how to actually use that array in this speeds config
  • on set_speed i’m trying to call set_fan_mode but I don’t get how i can output the speed variable that was selected from the input to that fan_mode setting

Any help with these is appreciated, thanks!

Personally, I would do the opposite because of states like ‘unkown’ or None. So make a list of items that mean that the device is on and use the following code:

       value_template: >
         # change the list after the word in to contain the 'on' values.
         {% if states('climate.living_room') in ['On','Auto','Heat','Cold'] %} 
           on
         {% else %}
           off
         {% endif %}

Should be fine as long as those states correlate with the speeds set in the speeds dropdown.

There may be a way to pull this directly but templates suffer a flaw. That flaw is that they only return strings, they do not return lists. If you want to spend the time, I believe you can pull the list using json syntax instead of yaml. I’ve never got it to work, but I haven’t really tried hard. Personally, i’d just write the list out (like you did) and call it a day.

The variable ‘speed’ is pulling from your dropdown list. So, if your climate can take the following settings for speeds (1,2,3,4,5, Auto, Silence’), then the following template should work:

       set_speed:
         service: climate.set_fan_mode
         data_template: #<--- needs to be a template to pass variables
           entity_id: climate.living_room
           # needs to use template syntax
           fan_mode: "{{ speed }}"
1 Like

Thanks! got it working. Now I just hit another wall with the homekit component not supporting fan speed… damn

I got the same issue. The fans created this way does not support speed adjustments in homekit. The same holds for google assistant exposed fans too. They only support on and off unfortunately.

It seems home assistant exposes fans to Google assistant as a switch, not a fan. I have a couple of zigbee fan controls that the cloud assistant sends to Alexa as fans, but to Google Assistant as a switch. Setting fan speeds works in Alexa, but not in Google. I think an update needs to be made to the Home Assistant.

https://developers.google.com/actions/smarthome/guides/fan

I use fan template, to get the speed slider in HomeKit I use homebridge and the home assistant plugin to expose the fan entities.
No idea why the HomeKit component does not have fan speed incorporated.

Could you share youre config? Trying to extract fan from sensibo so I can add it to homekit but nonluck ;/

HA still haven’t got decent fan controls I see.