Hi. All my fans are using template fan integration. Below is my setup.
How do i adapt to use input_number for percentage?
Tried adding an input number and changed set_speed to preset_mode.
Deprecated speeds can be converted to preset_modes?
Got confused and didnt worked.
Rolled back to last version to keep fans working.
Documentation on https://www.home-assistant.io/integrations/fan.template/ https://www.home-assistant.io/integrations/fan/
I have the same issue. Would be interested in the reply.
I think I have it mostly sorted but donāt know whether I now need to handle ranges in the turn_onservice_template or whether that translation happens automagically.
fan:
- platform: template
fans:
vent_teto_quarto:
friendly_name: "Ventilador Quarto"
value_template: "{{ states('input_boolean.ventteto_quarto') }}"
percentage_template: "{{ float(states('input_select.ventteto_quarto_velocidades')) * 100 / 6 }}"
# Uses a fake switch from an input_boolean as the fan has no way of reporting direction back to HA
direction_template: "{{ 'forward' if is_state('input_boolean.quarto_fan_direction', 'on') else 'reverse' }}"
turn_on:
service: script.ventteto_quarto_on
turn_off:
service: script.ventteto_quarto_off
set_percentage:
- service: script.ventteto_quarto_velocidade
data_template:
percentage: "{{ percentage }}"
set_direction:
- service: remote.send_command
data:
entity_id: remote.rmpro_remote
command:
- b64:sgYwABQvFA02DTYvFC+UHyQfJB8kHyQfJB8kHyMfIy8ULxMvFA02DTYvFC8TDTYNNg02LwAAAAAAAAAA
- service: input_boolean.toggle
entity_id: input_boolean.quarto_fan_direction
speed_count: 6
For your ventteto_quarto_velocidade, check the percentage value is between 100*1/6, 100*2/6, 100*3/6, 100*4/6, etc and set the value of the input select based on where it falls similar to how you are doing in ventteto_quarto_on
The intent was to make fully backwards compatibly to give everyone time to transition as it will likely take a few months for every integration to switch over to the new model. Last time I checked we had 5 integrations still on the old model out of ~26.
If it helps I updated my old template fan package to allow for the new percentage, it is a little convoluted since it uses RFlink to pickup the status from the 433hz remote and uses broadlink to transmit from home assistant and it is glued together with a bunch of binary sensors etc.
anyhow here is my code which may be helpful for others - for the set percentage if/else check I forgot to switch to an integer as opposed to a sting (i drdnt remove the inverted commas for the percentage).
granted it could be a bit tidier, i could move the broadling calls into the scripts and try and get the speed calls into a single script using the input numner variable
Ok, so itās some kind of āmagicalā, āundocumentedā, ābackgroundā variable that we can use.
Those kinds of things would be good to put in the documentation as an example somewhere. Especially when these kinds of big/breaking changes get implemented.
The docs on this change are pretty darn sparse.
Thanks for the info.
In the meantime I did manage to bang my head against the code wall long enought that I was able to get it wotking another way.
I donāt know if it will help you or not (or somebody else later) but this is my fan package for a dumb fan controlled by a broadlnk:
fan:
- platform: template
fans:
sunroom_fan_percent_template:
friendly_name: "Sunroom Fan Percent Template"
value_template: "{{ states('input_boolean.sunroom_fan_state') }}"
percentage_template: "{{ states('input_number.sunroom_fan_speed_percent') | float }}"
turn_on:
service: script.sunroom_fan_on
turn_off:
service: script.sunroom_fan_off
set_percentage:
service: script.sunroom_fan_set_speed_percent
data:
percentage: "{{ percentage }}"
speed_count: 3
input_number:
sunroom_fan_speed_percent:
name: Sunroom Fan Speed Percent
min: 0
max: 100
step: 1
input_boolean:
sunroom_fan_state:
name: Sunroom Fan State
script:
sunroom_fan_off:
alias: Sunroom Fan Off
sequence:
- service: switch.turn_on
entity_id: switch.sunroom_fan_0
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sunroom_fan_state
sunroom_fan_on:
alias: Sunroom Fan On
sequence:
- service: input_boolean.turn_on
entity_id: input_boolean.sunroom_fan_state
- service: script.sunroom_fan_set_speed_percent
sunroom_fan_set_speed_percent:
alias: Sunroom Fan Set Percentage
sequence:
- service: input_number.set_value
entity_id: input_number.sunroom_fan_speed_percent
data:
value: "{{ percentage }}"
- delay:
milliseconds: 500
- service: >
{% if states("input_number.sunroom_fan_speed_percent") | int == 33 %}
script.sunroom_fan_low
{% elif states("input_number.sunroom_fan_speed_percent") | int == 66 %}
script.sunroom_fan_med
{% elif states("input_number.sunroom_fan_speed_percent") | int == 100 %}
script.sunroom_fan_high
{% else %}
script.sunroom_fan_off
{% endif %}
- service: >
{% if states("input_number.sunroom_fan_speed_percent") | int == 33 %}
input_boolean.turn_on
{% elif states("input_number.sunroom_fan_speed_percent") | int == 66 %}
input_boolean.turn_on
{% elif states("input_number.sunroom_fan_speed_percent") | int == 100 %}
input_boolean.turn_on
{% else %}
input_boolean.turn_off
{% endif %}
entity_id: input_boolean.sunroom_fan_state
sunroom_fan_low:
alias: Sunroom Fan Low
sequence:
- service: switch.turn_on
entity_id: switch.sunroom_fan_1
sunroom_fan_med:
alias: Sunroom Fan Medium
sequence:
- service: switch.turn_on
entity_id: switch.sunroom_fan_2
sunroom_fan_high:
alias: Sunroom Fan High
sequence:
- service: switch.turn_on
entity_id: switch.sunroom_fan_3
switch:
- platform: broadlink
mac: 34:ea:34:42:f3:be
switches:
#sunroom_fan_1:
- name: "Sunroom Fan 1"
command_on: sgA8AQ4MDgwODA8MDgwODA4MDg0ODA4MDgwOq........
command_off: sgA8AQ4MDgwODA8MDgwODA4MDg0ODA4MDgwOqhsMG......
#sunroom_fan_2:
- name: "Sunroom Fan 2"
command_on: sgDaAQ8MDgwODA8LDwsPDA4MDwsPCw8MDg........
command_off: sgDaAQ8MDgwODA8LDwsPDA4MDwsPCw8MDg.........
#sunroom_fan_3:
- name: "Sunroom Fan 3"
command_on: sgA8AQ4MDgwODA4NDgwODA4MDg0NDQ4MDgwOqhsMG.........
command_off: sgA8AQ4MDgwODA4NDgwODA4MDg0NDQ4MDgwOqhsMG...........
#sunroom_fan_0:
- name: "Sunroom Fan 0"
command_on: sgB4Ag4MDgwODQ4MDgwODA4NDQ0ODA4MDgwOqhsMG.......
command_off: sgB4Ag4MDgwODQ4MDgwODA4NDQ0ODA4MDgwOqhsMGw.........
automation:
- alias: Toggle Sunroom Fan Low Switch
initial_state: 'on'
trigger:
platform: state
entity_id: switch.sunroom_fan_1
to: 'on'
for:
seconds: 1
action:
service: homeassistant.turn_off
entity_id: switch.sunroom_fan_1
- alias: Toggle Sunroom Fan Medium Switch
initial_state: 'on'
trigger:
platform: state
entity_id: switch.sunroom_fan_2
to: 'on'
for:
seconds: 1
action:
service: homeassistant.turn_off
entity_id: switch.sunroom_fan_2
- alias: Toggle Sunroom Fan High Switch
initial_state: 'on'
trigger:
platform: state
entity_id: switch.sunroom_fan_3
to: 'on'
for:
seconds: 1
action:
service: homeassistant.turn_off
entity_id: switch.sunroom_fan_3
- alias: Toggle Sunroom Fan Off Switch
initial_state: 'on'
trigger:
platform: state
entity_id: switch.sunroom_fan_0
to: 'on'
for:
seconds: 1
action:
service: homeassistant.turn_off
entity_id: switch.sunroom_fan_0
homeassistant:
customize:
switch.sunroom_fan_0:
friendly_name: Sunroom Fan Off
switch.sunroom_fan_1:
friendly_name: Sunroom Fan Low
switch.sunroom_fan_2:
friendly_name: Sunroom Fan Medium
switch.sunroom_fan_3:
friendly_name: Sunroom Fan High
Thanks @finity for posting this code. It got me most of the way there and I would have really struggled putting it together from scratch, but I was getting an error when I tried to turn the fan on just using the on/off toggle. The error was that a float value (the percentage) was missing. I have a slightly different setup with a Tuya/Smartlife fan that is integrated with the Tuya integration. The fan doesnāt just show up and I had to create ātap to runā actions in the TUYA app, which creates separate scenes for low, medium, high, and off similar to your Broadlink controlled fan. The fan has a QIACHIP so TUYA convert doesnāt look like it will work, so this is the next best thing for control.
The error could have been caused by the slightly different application of using scenes versus switches. I added some more code to the turn on script that basically sets the fan to the previous percentage/speed, unless the prior percentage was 0 which I then have it set to turn the fan to medium using the toggle. My code in case it helps anyone with a similar setup is:
fan:
- platform: template
fans:
lroom_fan_percent_template:
friendly_name: "Living Room Fan"
value_template: "{{ states('input_boolean.lroom_fan_state') }}"
percentage_template: "{{ states('input_number.lroom_fan_speed_percent') | float }}"
turn_on:
service: script.lroom_fan_on
turn_off:
service: script.lroom_fan_off
set_percentage:
service: script.lroom_fan_set_speed_percent
data:
percentage: "{{ percentage }}"
speed_count: 3
input_number:
lroom_fan_speed_percent:
name: Living Room Fan Speed Percent
initial: 0
min: 0
max: 100
step: 33
input_boolean:
lroom_fan_state:
name: Living Room Fan State
lroom_fan_off:
alias: Living room Fan Off
sequence:
- service: scene.turn_on
entity_id: scene.lroomfanoff
- service: input_boolean.turn_off
data:
entity_id: input_boolean.lroom_fan_state
lroom_fan_on:
alias: Living room Fan On
sequence:
- service: input_boolean.turn_on
entity_id: input_boolean.lroom_fan_state
- service: >
{% if states("input_number.lroom_fan_speed_percent") | int == 33 %}
script.lroom_fan_low
{% elif states("input_number.lroom_fan_speed_percent") | int == 66 %}
script.lroom_fan_med
{% elif states("input_number.lroom_fan_speed_percent") | int == 100 %}
script.lroom_fan_high
{% else %}
script.lroom_fan_onfromzero
{% endif %}
lroom_fan_set_speed_percent:
alias: Living room Fan Set Percentage
sequence:
- service: input_number.set_value
entity_id: input_number.lroom_fan_speed_percent
data:
value: "{{ percentage }}"
- delay:
milliseconds: 500
- service: >
{% if states("input_number.lroom_fan_speed_percent") | int == 33 %}
script.lroom_fan_low
{% elif states("input_number.lroom_fan_speed_percent") | int == 66 %}
script.lroom_fan_med
{% elif states("input_number.lroom_fan_speed_percent") | int == 100 %}
script.lroom_fan_high
{% else %}
script.lroom_fan_off
{% endif %}
- service: >
{% if states("input_number.lroom_fan_speed_percent") | int == 33 %}
input_boolean.turn_on
{% elif states("input_number.lroom_fan_speed_percent") | int == 66 %}
input_boolean.turn_on
{% elif states("input_number.lroom_fan_speed_percent") | int == 100 %}
input_boolean.turn_on
{% else %}
input_boolean.turn_off
{% endif %}
entity_id: input_boolean.lroom_fan_state
lroom_fan_low:
alias: Living Room Fan Low
sequence:
- service: scene.turn_on
entity_id: scene.lowfan
lroom_fan_med:
alias: Living Room Fan Medium
sequence:
- service: scene.turn_on
entity_id: scene.mediumfan
lroom_fan_high:
alias: Living Room Fan High
sequence:
- service: scene.turn_on
entity_id: scene.highfan
lroom_fan_onfromzero:
alias: On from Zero
sequence:
- service: input_number.set_value
entity_id: input_number.lroom_fan_speed_percent
data:
value: "66"
- service: scene.turn_on
entity_id: scene.mediumfan
If youād like to see the old speed list reinstated Iāve requested that the old speed list options should be kept and Iāve had a suggestion from a dev that if a FR gets enough votes they would implement it.
why is there a percentage slider when most fans run on 3-12 speed modes? this doesnt make sense to me. a dropdown list would be way more convinient to me or am i oversseing something?
The percentage slider will work with anything between 2-12+ speeds. It will devide the steps by 100 ie 3 speeds 33, 66, 100. 4 speeds 25, 50, 75, 100 etc.
Maybe you can help me. I implemented this script, but for some reason, i canāt figure out how to add any of it to lovelace, none of the switches are showing up. Am I missing something?
If you successfully created the entity, then you should be able to just add it to Lovelace like in this clip. There are custom fan UI sliders you can get if you search the forum, but this should get you basic control
I have GE ZWave fan controls, and it seems that 33% is āMedā speed, and 32 is āLowā. It might be better if the slider used 32, 65, 99 instead of 33, 66, 100.