Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions components/switch/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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
Expand Down