diff --git a/components/switch/index.rst b/components/switch/index.rst index 002570d6ca..4bbf41aab3 100644 --- a/components/switch/index.rst +++ b/components/switch/index.rst @@ -137,7 +137,7 @@ 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. If it's different from the last internal state, it's additionally published to the frontend. - + .. code-block:: yaml // Within lambda, make the switch report a specific state @@ -149,11 +149,11 @@ advanced stuff (see the full API Reference for more info). Keep in mind that this does not change the actual state of the switch. It only changes the state in the frontend and the internal state. If you want to change the actual state of the switch, you need to call ``turn_on()``, - ``turn_off()`` or ``toggle()``. + ``turn_off()``, ``toggle()``, or ``control()``. For example, if you are using a :doc:`/components/switch/gpio`, calling ``publish_state()`` will not change the GPIO pin level. To do that, you need to call ``turn_on()``, - ``turn_off()`` or ``toggle()``. The same applies to other switch platforms. + ``turn_off()``, ``toggle()``, or ``control()``. The same applies to other switch platforms. - ``state``: Retrieve the current state of the switch. @@ -177,6 +177,16 @@ advanced stuff (see the full API Reference for more info). // Toggle the switch id(my_switch).toggle(); +- ``control()``: Control the switch state using a boolean parameter. + This provides a unified interface for setting switch state dynamically. + + .. code-block:: yaml + + // Within lambda, control switch based on a condition + id(my_switch).control(true); // Turn ON + id(my_switch).control(false); // Turn OFF + id(my_switch).control(some_condition); // Set based on condition + .. _switch-on_turn_on_off_trigger: ``switch.on_turn_on`` / ``switch.on_turn_off`` Trigger