2018-05-13 11:37:02 +02:00
Fan Component
=============
2018-11-14 22:12:27 +01:00
.. seo ::
:description: Instructions for setting up the base fan component.
2021-11-16 03:19:33 +01:00
:image: folder-open.svg
2018-11-14 22:12:27 +01:00
2018-05-13 11:37:02 +02:00
With the `` fan `` domain you can create components that appear as fans in
2022-01-23 15:28:27 +01:00
the Home Assistant frontend. A fan can be switched on or off, optionally
has a speed between 1 and the maximum supported speed of the fan, and can have an
oscillation and direction output.
2018-05-13 11:37:02 +02:00
2018-06-01 18:10:00 +02:00
.. figure :: images/fan-ui.png
:align: center
2018-05-13 11:37:02 +02:00
2018-06-01 18:10:00 +02:00
.. _config-fan:
2018-05-13 11:37:02 +02:00
Base Fan Configuration
2018-08-24 22:44:01 +02:00
----------------------
2018-05-13 11:37:02 +02:00
2018-11-19 18:32:16 +01:00
.. code-block :: yaml
2018-05-13 11:37:02 +02:00
fan:
- platform: ...
name: ...
Configuration variables:
2018-06-01 18:10:00 +02:00
- **name** (**Required** , string): The name of the fan.
2021-10-10 10:39:50 +02:00
- **icon** (*Optional* , icon): Manually set the icon to use for the fan in the frontend.
2022-01-23 15:28:27 +01:00
- **restore_mode** (*Optional* ): Control how the fan attempts to restore state on boot.
2022-01-22 20:42:36 +01:00
2022-01-23 15:28:27 +01:00
- `` NO_RESTORE `` - Don't restore any state.
- `` RESTORE_DEFAULT_OFF `` - Attempt to restore state and default to OFF if not possible to restore (default).
2022-01-22 20:42:36 +01:00
- `` RESTORE_DEFAULT_ON `` - Attempt to restore state and default to ON.
- `` RESTORE_INVERTED_DEFAULT_OFF `` - Attempt to restore state inverted from the previous state and default to OFF.
- `` RESTORE_INVERTED_DEFAULT_ON `` - Attempt to restore state inverted from the previous state and default to ON.
- `` ALWAYS_OFF `` - Always initialize the fan as OFF on bootup.
- `` ALWAYS_ON `` - Always initialize the fan as ON on bootup.
2019-02-17 12:28:17 +01:00
- **internal** (*Optional* , boolean): Mark this component as internal. Internal components will
not be exposed to the frontend (like Home Assistant). Only specifying an `` id `` without
a `` name `` will implicitly set this to true.
2022-01-23 15:28:27 +01:00
- **disabled_by_default** (*Optional* , boolean): If true, then this entity should not be added to any client's frontend
2021-08-10 03:45:41 +02:00
(usually Home Assistant) without the user manually enabling it (via the Home Assistant UI).
Requires Home Assistant 2021.9 or newer. Defaults to `` false `` .
2021-11-07 19:24:55 +01:00
- **entity_category** (*Optional* , string): The category of the entity.
See https://developers.home-assistant.io/docs/core/entity/#generic-properties
for a list of available options. Requires Home Assistant 2021.11 or newer.
Set to `` "" `` to remove the default entity category.
2019-02-17 12:28:17 +01:00
MQTT options:
2018-06-01 18:10:00 +02:00
- **oscillation_state_topic** (*Optional* , string): The topic to
2018-10-20 15:10:26 +02:00
publish fan oscillation state changes to.
2018-06-01 18:10:00 +02:00
- **oscillation_command_topic** (*Optional* , string): The topic to
receive oscillation commands on.
2021-09-22 13:43:23 +02:00
- **speed_level_state_topic** (*Optional* , int): The topic to publish
numeric fan speed state changes to (range: 0 to speed count).
- **speed_level_command_topic** (*Optional* , int): The topic to receive
numeric speed commands on (range: 0 to speed count).
2018-06-01 18:10:00 +02:00
- **speed_state_topic** (*Optional* , string): The topic to publish fan
2021-09-22 13:43:23 +02:00
speed state changes to (options: LOW, MEDIUM, HIGH).
2018-06-01 18:10:00 +02:00
- **speed_command_topic** (*Optional* , string): The topic to receive
2021-09-22 13:43:23 +02:00
speed commands on (options: LOW, MEDIUM, HIGH).
2018-06-01 18:10:00 +02:00
- All other options from :ref: `MQTT Component <config-mqtt-component>` .
2021-05-19 06:12:59 +02:00
Automation triggers:
- **on_turn_on** (*Optional* , :ref: `Action <config-action>` ): An automation to perform
when the fan is turned on. See :ref: `fan-on_turn_on_off_trigger` .
- **on_turn_off** (*Optional* , :ref: `Action <config-action>` ): An automation to perform
when the fan is turned off. See :ref: `fan-on_turn_on_off_trigger` .
2021-09-08 05:16:03 +02:00
- **on_speed_set** (*Optional* , :ref: `Action <config-action>` ): An automation to perform
when the fan speed is set/changed. See :ref: `fan-on_speed_set_trigger` .
2021-05-19 06:12:59 +02:00
2018-06-01 18:10:00 +02:00
.. _fan-toggle_action:
`` fan.toggle `` Action
2018-08-24 22:44:01 +02:00
---------------------
2018-06-01 18:10:00 +02:00
Toggles the ON/OFF state of the fan with the given ID when executed.
2018-11-19 18:32:16 +01:00
.. code-block :: yaml
2018-06-01 18:10:00 +02:00
on_...:
then:
2018-10-20 14:53:27 +02:00
- fan.toggle: fan_1
2018-06-01 18:10:00 +02:00
.. _fan-turn_off_action:
`` fan.turn_off `` Action
2018-08-24 22:44:01 +02:00
-----------------------
2018-06-01 18:10:00 +02:00
Turns the fan with the given ID off when executed.
2018-11-19 18:32:16 +01:00
.. code-block :: yaml
2018-06-01 18:10:00 +02:00
on_...:
then:
2018-10-20 14:53:27 +02:00
- fan.turn_off: fan_1
2018-06-01 18:10:00 +02:00
.. _fan-turn_on_action:
`` fan.turn_on `` Action
2018-08-24 22:44:01 +02:00
----------------------
2018-06-01 18:10:00 +02:00
2021-05-26 00:35:11 +02:00
Turns the fan with the given ID on when executed.
2018-06-01 18:10:00 +02:00
2018-11-19 18:32:16 +01:00
.. code-block :: yaml
2018-06-01 18:10:00 +02:00
on_...:
then:
- fan.turn_on:
2018-06-02 21:54:39 +02:00
id: fan_1
2018-11-10 14:31:27 +01:00
# Shorthand:
- fan.turn_on: fan_1
2018-06-01 18:10:00 +02:00
Configuration options:
2018-06-02 21:54:39 +02:00
- **id** (**Required** , :ref: `config-id` ): The ID of the fan.
2018-06-01 18:10:00 +02:00
- **oscillating** (*Optional* , boolean, :ref: `templatable <config-templatable>` ):
Set the oscillation state of the fan. Defaults to not affecting oscillation.
2021-03-17 14:40:33 +01:00
- **speed** (*Optional* , int, :ref: `templatable <config-templatable>` ):
Set the speed level of the fan. Can be a number between 1 and the maximum speed level of the fan.
2021-08-26 00:25:30 +02:00
- **direction** (*Optional* , string, :ref: `templatable <config-templatable>` ):
2022-01-23 15:28:27 +01:00
Set the direction of the fan. Can be either `` forward `` or `` reverse `` . Defaults to not changing the direction.
2018-06-01 18:10:00 +02:00
2021-09-26 21:32:50 +02:00
.. _fan-cycle_speed_action:
`` fan.cycle_speed `` Action
--------------------------
Increments through speed levels of the fan with the given ID when executed. If the fan's speed level is set to maximum when executed, turns fan off.
.. code-block :: yaml
on_...:
then:
- fan.cycle_speed: fan_1
2021-09-02 02:16:15 +02:00
.. _fan-is_on_condition:
.. _fan-is_off_condition:
`` fan.is_on `` / `` fan.is_off `` Condition
2021-09-14 13:04:38 +02:00
----------------------------------------
2021-09-02 02:16:15 +02:00
2022-01-23 15:28:27 +01:00
This :ref: `condition <config-condition>` passes if the given fan is on or off.
2021-09-02 02:16:15 +02:00
.. code-block :: yaml
# in a trigger:
on_...:
if:
condition:
fan.is_on: my_fan
# same goes for is_off
then:
- script.execute: my_script
2021-05-19 06:12:59 +02:00
.. _fan-on_turn_on_off_trigger:
`` fan.on_turn_on `` / `` fan.on_turn_off `` Trigger
2021-09-14 13:04:38 +02:00
------------------------------------------------
2021-05-19 06:12:59 +02:00
This trigger is activated each time the fan is turned on or off. It does not fire
if a command to turn the fan on or off already matches the current state.
.. code-block :: yaml
fan:
- platform: speed # or any other platform
# ...
on_turn_on:
- logger.log: "Fan Turned On!"
on_turn_off:
- logger.log: "Fan Turned Off!"
2021-09-08 05:16:03 +02:00
.. _fan-on_speed_set_trigger:
`` fan.on_speed_set `` Trigger
2021-09-14 13:04:38 +02:00
----------------------------
2021-09-08 05:16:03 +02:00
2021-09-14 13:04:38 +02:00
This trigger is activated each time the fan speed is changed. It will fire when the speed is either set via API e.g. in Home Assistant or locally by an automation or a lambda function.
2021-09-08 05:16:03 +02:00
.. code-block :: yaml
fan:
- platform: speed # or any other platform
# ...
on_speed_set:
- logger.log: "Fan Speed was changed!"
2021-09-13 22:10:31 +02:00
Lambda calls
2021-09-14 13:04:38 +02:00
------------
2021-09-13 22:10:31 +02:00
From :ref: `lambdas <config-lambda>` , you can call several methods on all fans to do some
advanced stuff (see the full API Reference for more info).
- `` state `` : Retrieve the current state (on/off) of the fan.
.. code-block :: yaml
// Within lambda, get the fan state and conditionally do something
if (id(my_fan).state) {
// Fan is ON, do something here
} else {
// Fan is OFF, do something else here
}
- `` speed `` : Retrieve the current speed of the fan.
.. code-block :: yaml
// Within lambda, get the fan speed and conditionally do something
if (id(my_fan).speed == 2) {
// Fan speed is 2, do something here
} else {
// Fan speed is not 2, do something else here
}
- `` oscillating `` : Retrieve the current oscillating state of the fan.
.. code-block :: yaml
// Within lambda, get the fan oscillating state and conditionally do something
if (id(my_fan).oscillating) {
// Fan is oscillating, do something here
} else {
// Fan is not oscillating, do something else here
}
- `` direction `` : Retrieve the current direction of the fan.
.. code-block :: yaml
// Within lambda, get the fan direction and conditionally do something
2022-01-23 15:28:27 +01:00
if (id(my_fan).direction == FanDirection::FORWARD) {
2021-09-13 22:10:31 +02:00
// Fan direction is forward, do something here
} else {
// Fan direction is reverse, do something else here
}
- `` turn_off() `` /`` turn_on() `` /`` toggle() `` : Manually turn the fan ON/OFF from code.
Similar to the `` fan.turn_on `` , `` fan.turn_off `` , and `` fan.toggle `` actions,
but can be used in complex lambda expressions.
.. code-block :: yaml
// Turn the fan off
auto call = id(my_fan).turn_off();
call.perform();
// Turn the fan on and set the speed, oscillating, and direction
auto call = id(my_fan).turn_on();
call.set_speed(2);
call.set_oscillating(true);
2022-01-23 15:28:27 +01:00
call.set_direction(FanDirection::REVERSE);
2021-09-13 22:10:31 +02:00
call.perform();
// Toggle the fan on/off
auto call = id(my_fan).toggle();
call.perform();
2018-06-01 18:10:00 +02:00
Full Fan Index
2018-08-24 22:44:01 +02:00
--------------
2018-06-01 18:10:00 +02:00
2019-02-07 13:54:45 +01:00
- :apiref: `fan/fan_state.h`
- :ghedit: `Edit`
2018-06-01 18:10:00 +02:00
.. toctree ::
:maxdepth: 1
2018-10-20 14:53:27 +02:00
:glob:
2018-06-01 18:10:00 +02:00
2018-10-20 14:53:27 +02:00
*