Fan lambda documentation updates (#1439)
* Remove duplicate on/off conditions in the core switch component Replace covers with switches in the core switch component lambda calls section Add a lambda calls section in the core fan component * Update components/fan/index.rst Co-authored-by: Chris Nussbaum <chris.nussbaum@protolabs.com> Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
This commit is contained in:
parent
8a26a30a7f
commit
231e49f439
|
@ -123,6 +123,77 @@ if a command to turn the fan on or off already matches the current state.
|
|||
on_turn_off:
|
||||
- logger.log: "Fan Turned Off!"
|
||||
|
||||
Lambda calls
|
||||
************
|
||||
|
||||
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
|
||||
if (id(my_fan).direction == FanDirection::FAN_DIRECTION_FORWARD) {
|
||||
// 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);
|
||||
call.set_direction(FanDirection::FAN_DIRECTION_REVERSE);
|
||||
call.perform();
|
||||
|
||||
// Toggle the fan on/off
|
||||
auto call = id(my_fan).toggle();
|
||||
call.perform();
|
||||
|
||||
Full Fan Index
|
||||
--------------
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ This :ref:`Condition <config-condition>` checks if the given switch is ON (or OF
|
|||
lambda calls
|
||||
************
|
||||
|
||||
From :ref:`lambdas <config-lambda>`, you can call several methods on all covers to do some
|
||||
From :ref:`lambdas <config-lambda>`, you can call several methods on all switches to do some
|
||||
advanced stuff (see the full API Reference for more info).
|
||||
|
||||
- ``publish_state()``: Manually cause the switch to publish a new state and store it internally.
|
||||
|
@ -135,24 +135,6 @@ advanced stuff (see the full API Reference for more info).
|
|||
// Toggle the switch
|
||||
id(my_switch).toggle();
|
||||
|
||||
.. _switch-is_on_off_condition:
|
||||
|
||||
``switch.is_on`` / ``switch.is_off`` Condition
|
||||
**********************************************
|
||||
|
||||
This :ref:`condition <config-condition>` passes if the given switch is on/off.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
# in a trigger:
|
||||
on_...:
|
||||
if:
|
||||
condition:
|
||||
switch.is_on: my_switch
|
||||
# same goes for is_off
|
||||
then:
|
||||
- script.execute: my_script
|
||||
|
||||
.. _switch-on_turn_on_off_trigger:
|
||||
|
||||
``switch.on_turn_on`` / ``switch.on_turn_off`` Trigger
|
||||
|
|
Loading…
Reference in New Issue