This blueprint automates speed control of your fans in relation to your chosen temperature range and fan speed range. A large part of this has been copied from another blueprint made by @MickW69. However it was missing some key elements I thought worthy to add. And I have changed how the mapping is done between the temp_range
and the fan_speed_range
. The original blueprint can be found here. All credit for the idea and original code should go to Mick. Thanks mate!
The new set_fan_speed equation is caculated as follows:
Currently tested on an EspHome fan with percentage step control.
Features:
- The speed is calcualted and set each time the the fan is turned on.
- A customizable delay is used to avoid changing the fan too frequently.
- A minimum percent change can be set to avoid continuously adjusting.
- A blocking entity can be used (with an
input_boolean
) to block the automation from running.
blueprint:
name: Auto fan speed
description: "Temperature based Auto fan control.\n\n Fan Speed will be set when
initially turned on by relating the ambient temperature to an equivalant speed
setting. \nA time delay and a minimum percentage change is used to eliminate
frequent speed changes.\n At the minimum temperature setting the fan will turn
off. \n When the temperature rises above this minimum temperature setting, the
fan will automatically turn back on."
domain: automation
input:
temp_sensor:
name: Temperature Sensor
description: Enter your temperature sensor.
default: []
selector:
entity:
domain:
- sensor
device_class:
- temperature
multiple: false
fan_switch:
name: Fan
description: The fan you wish to speed control.
selector:
entity:
domain:
- fan
multiple: false
min_fan_speed:
name: Minimum Fan Speed
description: Set the minimum percentage speed when your fan is still on.
default: 16
selector:
number:
min: 1.0
max: 100.0
mode: slider
step: 1.0
unit_of_measurement: '%'
max_fan_speed:
name: Maximum Fan Speed
description: Set the maximum percentage speed for your fan.
default: 100
selector:
number:
min: 1.0
max: 100.0
mode: slider
step: 1.0
unit_of_measurement: '%'
max_temp:
name: What temperature would you like the fan to run at max fan speed.
description: Set the high temperture sensor value.
default: 31
selector:
number:
min: 15.0
max: 50.0
step: 1.0
mode: slider
min_temp:
name: What temperature would you like the fan to run at minimum speed.
description: Set the low temperture sensor value.
default: 23
selector:
number:
min: 15.0
max: 45.0
step: 1.0
mode: slider
off_temp:
name: What temperature would you like the fan to turn off.
description: When the temperature falls below this value, the fan turns off. When the temperature rises above this value, the fan will automatically turn back on (unless the blocking entity is turned on).
default: 21.5
selector:
number:
min: 15.0
max: 50.0
step: 1.0
mode: slider
change_time:
name: Change frequency delay
description: How long to delay bewteen potential speed adjustments.
default: 30
selector:
number:
min: 1.0
max: 120.0
unit_of_measurement: minutes
step: 1.0
mode: slider
change_threshold:
name: Minimum percentage change
description: The minimum percentage change (between current fan speed and set
fan speed)
default: 1
selector:
number:
min: 1.0
max: 100.0
mode: slider
step: 1.0
unit_of_measurement: '%'
blocker_entity:
name: (OPTIONAL) Blocking entity
description: If this entity's state is on, it will prevent the automation from
running. E.g. sleepmode or away mode.
default:
selector:
entity:
multiple: false
source_url: https://community.home-assistant.io/t/adaptive-fan-speed-control-based-on-temperature-and-speed-range/678152
variables:
change_time: !input change_time
min_temp: !input min_temp
off_temp: !input off_temp
max_temp: !input max_temp
min_fan_speed: !input min_fan_speed
max_fan_speed: !input max_fan_speed
temp_sensor: !input temp_sensor
fan_switch: !input fan_switch
change_threshold: !input change_threshold
blocker_entity: !input blocker_entity
current_temp: "{{ states(temp_sensor) | float(0)}}"
fan_speed: '{{ state_attr(fan_switch,''percentage'') | float(0)}}'
temp_range: '{{max_temp | float(0)-min_temp | float(0)}}'
fan_range: '{{max_fan_speed | float(0) - min_fan_speed | float(0)}}'
slope: '{{fan_range | float(0)/temp_range | float(0)}}'
set_fan_speed: '{{ [[slope|float(0) * (current_temp|float(0) - min_temp|float(0)) + min_fan_speed|float(0), min_fan_speed] | max, max_fan_speed] | min}}'
speed_diff: '{{(fan_speed - set_fan_speed)|abs}}'
trigger:
- platform: state
entity_id:
- !input fan_switch
id: fanon
from: 'off'
to: 'on'
- platform: state
id: temp_state_change
entity_id:
- !input temp_sensor
condition:
- condition: template
alias: Check for blocker entity
value_template: '{{ (blocker_entity == none) or (states(blocker_entity) == ''off'')}}'
action:
- choose:
- conditions:
- condition: trigger
alias: Only run if fan switched on
id: fanon
- condition: template
alias: Is the percentage change great enough?
value_template: '{{ speed_diff | float(0) > change_threshold | float(0) }}'
sequence:
- service: homeassistant.turn_on
data:
percentage: '{{set_fan_speed}}'
target:
entity_id: '{{fan_switch}}'
- delay:
minutes: !input change_time
- conditions:
- condition: template
alias: Is the percentage change great enough?
value_template: '{{ speed_diff | float(0) > change_threshold | float(0) }}'
- condition: template
alias: Is the temperature above the off temp?
value_template: '{{ current_temp | float(0) > off_temp | float(0) }}'
sequence:
- service: homeassistant.turn_on
target:
entity_id: '{{fan_switch}}'
data:
percentage: '{{set_fan_speed}}'
- delay:
minutes: !input change_time
- conditions:
- condition: not
alias: Make sure the fan hasn't just been turned on
conditions:
- condition: trigger
id: fanon
- condition: numeric_state
entity_id: !input temp_sensor
below: !input off_temp
sequence:
- service: homeassistant.turn_off
target:
entity_id: '{{fan_switch}}'
- conditions:
- condition: not
alias: Make sure the fan hasn't just been turned on
conditions:
- condition: trigger
id: fanon
- condition: numeric_state
entity_id: !input temp_sensor
above: !input off_temp
sequence:
- service: homeassistant.turn_on
data:
percentage: '{{set_fan_speed}}'
target:
entity_id: '{{fan_switch}}'
- delay:
minutes: !input change_time
mode: single