Skip to content

Commit 6211537

Browse files
authored
[switch] Add control() method to API (#5506)
This is a copy of #5214, but in the new format. That one should have been merged when esphome/esphome#10118 was merged, but for some reason it was missed.
1 parent 6ed85f2 commit 6211537

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

content/components/switch/_index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ advanced stuff (see the full API Reference for more info).
182182
>
183183
> For example, if you are using a {{< docref "/components/switch/gpio" >}}, calling `publish_state()` will
184184
> not change the GPIO pin level. To do that, you need to call `turn_on()`,
185-
> `turn_off()` or `toggle()`. The same applies to other switch platforms.
185+
> `turn_off()`, `toggle()` or `control()`. The same applies to other switch platforms.
186186

187187
- `state` : Retrieve the current state of the switch.
188188

@@ -206,6 +206,16 @@ advanced stuff (see the full API Reference for more info).
206206
id(my_switch).toggle();
207207
```
208208

209+
- `control()` : Control the switch state using a boolean parameter.
210+
This provides a unified interface for setting switch state dynamically.
211+
212+
```yaml
213+
// Within lambda, control switch based on a condition
214+
id(my_switch).control(true); // Turn ON
215+
id(my_switch).control(false); // Turn OFF
216+
id(my_switch).control(some_condition); // Set based on condition
217+
```
218+
209219
{{< anchor "switch-on_turn_on_off_trigger" >}}
210220

211221
### `switch.on_turn_on` / `switch.on_turn_off` Trigger

0 commit comments

Comments
 (0)