Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This HA Blueprint Automation will control a 3 speed MQTT fan such as an IFANxx running Tasmota. Fan speed is changed using Home Assistant based on a temperature sensor reading and your inputs.
name: Auto_Fan_Temperature_Control_for_3-Speed_Fan_2021-09-03
description: This sets the fan speed for a 3 speed fan (such as an IFAN03/IFAN04) based on a room temperature.
# Community link for blueprint: source_url:
domain: automation
name: Toggle to turn the fan function off for when away or seasonally
description: input_boolean - If this is off, the Automation will be disabled.
domain: input_boolean
name: Room Temperature Sensor
description: >-
This is a temperature sensor or averaged temperature sensor preferrably within
the path of the moving air from the fan. Otherwise the action will be laggy
where changes in temperature will have a lower effect on fan speed.
domain: sensor
name: Room Target Temperature
description: >-
input_number - This is the target temperature of the room.
This can be Metric or imperial, but the same as the temperature sensor.
domain: input_number
name: Temp Hysteresis
description: >-
This keeps the fan from speed cycling too often.
Set it bigger if the fan goes on and off too much.
Set it smaller if the fan doesn't change speeds fast enough.
0 is a good number if this area is not used in conjunction with a heating or
cooling unit where you want to set them both to 21C (for instance).
I use the Temperature setting input_number as an input to climate and this
at the same time, so I needed an offset.
default: 1.3
min: 0.0
max: 7.0
unit_of_measurement: Degrees
mode: slider
step: 0.1
name: Temp Gap between Low and Medium
description: >-
This is the temp swing between Low and Medium.
If the sensor reads between the base temperature and
this degrees warmer, the fan is on LOW.
Below the base temperature the fan is off.
default: 4.5
min: 1.0
max: 20.0
unit_of_measurement: Degrees
mode: slider
step: 0.1
name: Temp Gap between Medium and High
description: >-
This is the temp change between Medium and High.
If the sensor reads between the base temperature plus the
1-2 temperature and this degrees warmer, the fan is on MEDIUM.
Any warmer than this and the fan is set to HIGH.
default: 2.0
min: 1.0
max: 20.0
unit_of_measurement: Degrees
mode: slider
step: 0.1
name: Time of day fan should start
description: Set this for the time of day you want the fan function to be enabled.
name: Time of day fan should stop
description: Set this for the time of day you want the fan function to end.
name: Fan Topic
description: >-
This is the MQTT Topic needed to change the fan speed.
Tasmota flashed IFANxx devices have a topic such as:
but you need to look at YOUR device and determine the exact correct
topic to send to the broker to make yours work.
default: 'cmnd/Bedroom_Fan/FanSpeed'
variables: # Convert !inputs for use in jinja templates
temp_gap_var: !input 'temp_gap'
temp_gap_1_to_2_var: !input 'temp_gap_1_to_2'
temp_gap_2_to_3_var: !input 'temp_gap_2_to_3'
room_temp_now_var: !input 'room_temp_now'
room_set_temp_var: !input 'room_set_temp'
room_temp_now_val: '{{ expand(room_temp_now_var)[0].state | float }}'
room_set_temp_val: '{{ expand(room_set_temp_var)[0].state | float - temp_gap_var | float }}'
mode: restart
- platform: state
id: go_on_any_sensor_temp_changes
entity_id: !input 'room_temp_now'
- platform: state
id: go_on_any_set_temp_changes
entity_id: !input 'room_set_temp'
- platform: time
id: go_if_the_start_time_occurs
at: !input 'fan_on_time'
- platform: state
id: go_if_the_control_is_switched_on
entity_id: !input 'fan_control'
to: "on"
- platform: time
id: go_if_the_stop_time_occurs
at: !input 'fan_off_time'
- platform: state
id: go_if_the_control_is_switched_off
entity_id: !input 'fan_control'
to: "off"
- choose:
- alias: Fan normal turn off sequence
condition: or
- alias: Time limit has been reached
condition: trigger
id: go_if_the_stop_time_occurs
- alias: The automation has been disabled
condition: trigger
id: go_if_the_control_is_switched_off
- alias: Stop the fan
service: mqtt.publish
topic: !input 'mqtt_fan_topic'
payload: 0
qos: 1
retain: false
- alias: Normal fan run sequence
condition: and
- alias: Make sure the Fan is enabled
condition: state
entity_id: !input 'fan_control'
state: "on"
- alias: Only allow execution within selected hours
condition: time
after: !input 'fan_on_time'
before: !input 'fan_off_time'
- service: mqtt.publish
topic: !input 'mqtt_fan_topic'
payload: >
{% if room_temp_now_val < room_set_temp_val %}
{# Room is cooler than set temp so turn fan OFF. #}
{% elif room_temp_now_val < (room_set_temp_val + temp_gap_1_to_2_var) %}
{# Room is at the temp where the fan should be at LOW speed. #}
{% elif room_temp_now_val < (room_set_temp_val + temp_gap_1_to_2_var + temp_gap_2_to_3_var) %}
{# Room is at the temp where the fan should be at MEDIUM speed. #}
{% else %}
{# Room is warm enough to be on HIGH speed, #}
{% endif %}
qos: 1
retain: false

This comment has been minimized.

Copy link
Owner Author

@SirGoodenough SirGoodenough commented Aug 2, 2021

⬇️ Get Started

Option 1: My Home Assistant

Click the badge to import this Blueprint (needs Home Assistant Core 2021.7 or higher for Trigger_ID to work)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Option 2: Direct Link

Copy this link if you want to import the blueprint in your installation.

📄 Description

This functionality started as a way to help my Bedroom AC unit keep an even temperature throughout the bedroom over night. My partner wanted the fan on, but not faster than it had to be. I wanted it to change speeds following the temperature of the room. So that's what I did.

I continue to use this functionality in a slightly different way in my home system. If you want to see my use the automation form of this look at my HA Configuration GitHub repository. You will see that I have combined the control of the AC unit climate entity with this fan speed function and also have an 'on demand' version of this for when the room needs to be used during the day. My feeling was that I wanted to make this accessible to a wider audience, so I created this blueprint.

If you are looking to tweak the function here or are looking for something the same but different, hit me up on my Discord ( and we can work on that! If you see problems or have questions and don't want to use Discord, Comments here are also welcome.

First, let’s go over Blueprints and what they are. Blueprints are a way to share automations and is built into Home Assistant. Simple as that. You can import my template code and a copy of it will reside in your configuration. Once there, you can can edit it (if you need changes only) or you can call up that Blueprint to build an automation. It will collect the information needed based on your entities and your personal adjustments, and provide a working automation. You will have to have or add the required hardware and entities that the Blueprint needs to function.

How the Blueprint works:

To import this Blueprint:

• Open Home Assistant with administrator privileges and on a Lovelace screen, click anywhere in the main entity area and type the letter ‘c’. A selection box should pop up. Type blue and select the button to navigate to blueprints. You can also find blueprints by selecting configuration from the left menu and then blueprints from the center menu.
• Once there, click on the ‘Import Blueprint’ button in the lower right side of the main screen.
• In the ‘URL of the blueprint’ line type or paste in the URL of my Blueprint. I have the blueprint stored on my Public GIST on GitHub:

To make the blueprint work it will need:

• 1 input_boolean entity as the feature so you can enable or disable the automation easily
• 1 input_number used as the target temperature for the area you will be in
• 1 temperature sensor or temp average sensor or filtered temp sensor. This should be located physically within the breeze area of the fan for maximum desired affect.

Once you have the entities created or decided upon you can build the Automation. To build the automation:

  1. Click on 'Create Automation
  2. Add a Description so you can tell what this one is for
  3. Use the Drop-downs to select the Entities and values for the listed purposes. If you have questions trial and error or hit me up on Discord.
  4. Test that your fan works by changing the input number and the input boolean

FAQ for blueprint


  1. You can use either Metric or Imperial, but the sensor and the input_number have to be using the same scale.
  2. The Hysteresis offset can be '0' for the simplest operation. If you hare using the input_number to control both this and a climate integration, you may want an offset so the fan does not quick cycle. It basically move the input_number set point by the amount you pick
  3. You can have multiple automations running off of this with the same or different temp settings or times, but I suggest the times on 'ENABLED' versions do not overlap, or it will get very confused.

HOW the Blueprint / Automation works


  1. The header of the Blueprint contains the required info plus the URL from where it came from.
  2. The input: section is where it gets the information it needs to fill in the blanks. This information is stored in the actual automation referencing this Blueprint when executing the task.
  3. The Variables section has several entries. These are converting !inputs to variables that can be used in templates.
  4. The triggers section has hooks for the listed things. 2 of them are used to stop the automation at the appropriate time, and the rest are used to start the automation or to adjust the fan speed on temperature changes.
  5. In the action the first test looks to see if the automation wants to stop. If that is not the case, it will test the temperature reading against the set point and adjust the fan speed accordingly.


  • 2021-08-02: First blueprint version 🎉
    needs Home Assistant Core 2021.7 or higher for Trigger_ID to work
  • 2021-08-04: Remove Default path as it made my fan beep for no reason.
  • 2021-08-19: Remove negative Temp Gap hysteresis, logic wrong.
  • 2021-09-03: Add Description

All My Blueprints

Contact Links or see my other work:

What are we Fixing Today Homepage / Website: https://www.WhatAreWeFixing.Today/
Channel Link URL: (WhatAreWeFixingToday)
What are we Fixing Today Facebook page (Sir GoodEnough):
What are we Fixing Today Twitter Account (Sir GoodEnough):
Discord Guild: (Sir_Goodenough#9683)

If you want to support me:

Buy me Coffee:
PayPal one-off donation link:
Cash App $CASHTAG:$SirGoodenough
Venmo cash link:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment