Need help with fan template with the new options

There’s a couple fan changes coming in 2021.3.3, not sure if they’ll make a difference

Change your template to:

percentage_template: "{{ (state_attr('light.inovelli_lzw36_fan_dimmer','brightness') | int /255*100) | int}}"

that should take care of it.

Also would you mind posting up your entire fan template code, please?

1 Like

@finity That’s great, thank you so much!
Here’s the full template with your change

      living_room_fan:
        friendly_name: "Living room fan"
        value_template: "{{ states('light.inovelli_lzw36_fan_dimmer') }}"
        speed_count: 3
        percentage_template: "{{ (state_attr('light.inovelli_lzw36_fan_dimmer','brightness') | int /255*100) | int}}"
        turn_on:
          service: light.turn_on
          entity_id: light.inovelli_lzw36_fan_dimmer
        turn_off:
          service: light.turn_off
          entity_id: light.inovelli_lzw36_fan_dimmer
        set_percentage:
          service: light.turn_on
          entity_id: light.inovelli_lzw36_fan_dimmer
          data_template:
            brightness_pct: "{{ percentage }}"
3 Likes

Thank you, that coding works perfectly! I really wish there was some explanation as to why/how things like this are needed. As someone who is not a coder by trade these things make it really hard to be an “enthusiast”. I’m not an idiot either, I’m a systems engineer by trade.

The biggest thing to remember is that all states are strings. And some attributes are strings. Even tho they could look like something else.

So it’s always a safe bet to explicitly do the conversion to what you expect it to be.

but also the error gave you a hint of what the problem was:

unsupported operand type(s) for /: ‘NoneType’ and ‘int’

that means that you are trying to do a math operation (division) on two operands that don’t support it because one is an ‘int’ and the other one has no data type.

I just opened a PR to update the docs to clarify a few things

When converting a fan with 3 speeds from the old fan entity model, the following percentages can be used, the following percentages can be used:

0 - off
33 - low
66 - medium
100 - high

Would someone way more experienced than me assist with adding a 1% = breeze mode as a 4th speed (off, breeze, low, medium, high)?

I can make an attempt at it but am still learning templating.

You’re seeing 66? Mine is converting to 0, 33, 67 and 100

If you don’t get an answer here maybe ask on the templates channel of Home Assistant Discord

Why not?

So are you saying that going forward there will be no way to get the old functionality of using “set the speed to low/medium/high” using voice assistants and we have to use only percentages or other “non-speed-name” modes?

Alright,

Here is my setup that ive been using which, was provided a way back by (finity) for use with his fan entity row integration. It still does work but gives the nagging please remove speed from template message.

My fans are all ifan03’s.

- platform: template
  fans:
    groupfan:
      friendly_name: "Group Fan"
      value_template: >
        {% set s = states('input_boolean.group_fan_state') %}
        {{ s if s in ['on', 'off'] else 'off' }}
      speed_template: "{{ states('input_select.group_fan_set_speed') }}"
      turn_on:
        service: script.group_fan_on
      turn_off:
        service: script.group_fan_off
      set_speed:
        service: script.group_fan_set_speed
        data_template:
          speed: "{{ speed }}"
      speeds:
        - "low"
        - "medium"
        - "high"

input_boolean:

group_fan_state:
  name: All Fans

input_select:

group_fan_set_speed:
  options:
    - "low"
    - "medium"
    - "high"

scripts:

group_fan_off:
  sequence:
    - service: fan.turn_off
      entity_id:
        - fan.kitchen
        - fan.living
    - service: input_boolean.turn_off
      entity_id: input_boolean.group_fan_state
group_fan_on:
  sequence:
    - service: fan.turn_on
      entity_id:
        - fan.kitchen
        - fan.living
    - service: input_boolean.turn_on
      entity_id: input_boolean.group_fan_state
group_fan_set_speed:
  sequence:
    - service: fan.turn_on
      entity_id:
        - fan.kitchen
        - fan.living
    - service: input_boolean.turn_on
      entity_id: input_boolean.group_fan_state
    - service: fan.set_speed
      data_template:
        entity_id:
          - fan.kitchen
          - fan.living
        speed: "{{speed}}"
    - service: input_select.select_option
      data_template:
        entity_id: input_select.group_fan_set_speed
        option: "{{speed}}"

Okay. Now here is what I use for the fans. This is separate from above which just makes them all work as a group.

scripts:

kitchen_fan_off:
  sequence:
    - service: fan.turn_off
      data:
        entity_id: fan.kitchen
kitchen_fan_on:
  sequence:
    - service: fan.turn_on
      data:
        entity_id: fan.kitchen
    - delay:
        seconds: 1
    - service:
        '{% if is_state("input_select.kitchen_fan_speed", "low") %} script.kitchen_fan_low
        {% elif is_state("input_select.kitchen_fan_speed", "medium") %} script.kitchen_fan_medium
        {% else %} script.kitchen_fan_high {% endif %}'
kitchen_fan_low:
  sequence:
    - service: fan.turn_on
      data:
        entity_id: fan.kitchen
    - service: fan.set_speed
      data_template:
        entity_id: fan.kitchen
        speed: low
kitchen_fan_medium:
  sequence:
    - service: fan.turn_on
      data:
        entity_id: fan.kitchen
    - service: fan.set_speed
      data_template:
        entity_id: fan.kitchen
        speed: medium
kitchen_fan_high:
  sequence:
    - service: fan.turn_on
      data:
        entity_id: fan.kitchen
    - service: fan.set_speed
      data_template:
        entity_id: fan.kitchen
        speed: high
kitchen_fan_set_speed:
  sequence:
    - service: input_select.select_option
      data_template:
        entity_id: input_select.kitchen_fan_speed
        option: "{{ speed }}"
    - service: script.turn_on
      data_template:
        entity_id: script.kitchen_fan_{{ speed }}

Now my question is will the fan scripts still be okay with the current method? They dont seem to be causing any errors as is.

And is it as easy as just changing the set speed to set_percentage and changing the off, low. medium, high to 0, 33, 66, 100 in the template group fan?

interestingly, the mqtt fans (which is what In use for my iFan03’s) still use the old speed settings according to the docs.

But they also still throw the nag error every time I change the speed.

It would be nice to get answers on how to update the fans to use a possible speed setting (using preset modes per the question above?) instead of needing to use percentages.

And any updated examples to update the mqtt fans to the new settings.

EDIT:

Oh, and as an FYI I just created a new fan entity row that uses percents to control the fans using the new method. It should be available in HACS soon but you can go to my github now to install it manunally.

Maybe that will work with your existing template fans using percents? I tested on my template fans and it works fine.

And once I fully figure out how the modes are supposed to work IOW, get some questions answered) I’ll create one for controlling fans using preset modes.

1 Like

Nice. I’ll check it out here maybe tonight. Thanks for your work. Without it, my setup would be trash. lol

As a side note, I recently moved and left my lyric thermostat at that house, but while I was there I had a pretty nice setup with node-red reading the thermostat, and motion sensors. So walking into a room would trigger the fans to turn on at a speed determined by the temperature.

I’ll have that again as soon as I figure out which motion sensors im gonna run this time (stupid wyze sensor mac address problem) screwed me there.

1 Like

So apparently I picked a bad time to get a fan switch (LZW36)… I added this to Alexa using the Alexa Smart Home Skill and can only set the fan using specific percentages just like you mention. Am I missing something or is that the only solution at the moment? I would like to be able to use, Low, Medium, and High also but she doesn’t seem to do anything. I am using the template from above:

  - platform: template
    fans:      
      bedroom_fan:
        friendly_name: "Bedroom Fan"
        value_template: "{{ states('light.bedroom_fan') }}"
        speed_count: 3
        percentage_template: "{{ (state_attr('light.bedroom_fan','brightness') | int /255*100) | int}}"
        turn_on:
          service: light.turn_on
          entity_id: light.bedroom_fan
        turn_off:
          service: light.turn_off
          entity_id: light.bedroom_fan
        set_percentage:
          service: light.turn_on
          entity_id: light.bedroom_fan
          data_template:
            brightness_pct: "{{ percentage }}"

Maybe you will get a response if you ask the dev yourself above.

I seem to be on the naughty list right now so I’m only getting coal in my stocking… :wink:

Okay, I’ll poke around for an open issue first before I make a new one, but wanted to make sure I wasn’t just missing something in my setup. Has anyone happened to debug yet to see if Alexa is sending anything to HA for the “low, medium, and high” commands?

As far as I could glean any info from the threads I think that speeds should all still work as they did before but it will throw an warning in the logs that the set_speed service is being deprecated.

However, eventually, you will be required to only use percentages to control the speeds using voice controls.

I would really like to see us be able to use either going forward tho. I think using “set speed to 33%” instead of “set speed to low” is un-natural and not normal human language.

If you have a fan that supports (requires) percentages that’s fine and I’m glad that those fans are supported but I don’t see why the speeds are being thrown away and we have to completely change to that way when speeds have been supported for years.

So I have found a few post’s regarding this (sorry didn’t realize you already dealt with this so much already)… I’m debating if I should open it as an issue with the Alexa Smart Home Skill as the docs for fans there specifically mentions using low medium high… also all these mentions of using “preset_modes” and ASHS mentions “speed_list” but I cannot figure out if Alexa is supposed to pick up on those automatically or what… this is my first fan in HA so not super familiar with any of it. I guess worse case scenario I’ll make routines for the speeds… but definitely not ideal

That’s kind of what I was thinking of doing too if I couldn’t persuade anyone to have all the options.

It’s sad to think that I’ve spent so much time and effort to get everything in HA to have to go outside of it to get this seemingly basic functionality.

@Bartem

were you able to get your fan working yet?

if not then you might want to look at this thread to see if can help you out.

if not then post back here where you’re stuck and I’ll see if I can help.

1 Like