ESPHome’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/esphome/esphome.io/llms.txt
Use this file to discover all available pages before exploring further.
switch domain represents any output that has exactly two states — on or off — and exposes it as a Home Assistant switch entity. The most common use is controlling relay modules, but switches also power template logic, UART sequences, and output-pin abstractions. Every switch platform inherits a common set of configuration variables for naming, state restoration, and automation triggers.
Base Switch Configuration
Manually specify the ID for code generation. At least one of
id and name must be specified.The name for the switch in Home Assistant. Set to
None to inherit the device’s friendly_name.Manually override the MDI icon shown in the frontend.
If
true, the reported state is inverted (ON becomes OFF and vice versa). Defaults to false.Controls the initial switch state on boot:
ALWAYS_OFF(default) — always start off.ALWAYS_ON— always start on.RESTORE_DEFAULT_OFF— restore previous state, default to off.RESTORE_DEFAULT_ON— restore previous state, default to on.RESTORE_INVERTED_DEFAULT_OFF— restore inverted state, default to off.RESTORE_INVERTED_DEFAULT_ON— restore inverted state, default to on.DISABLED— leave initial state to the underlying platform.
The Home Assistant device class for the switch. Controls icon behavior in the frontend.
If
true, the switch is not exposed to the frontend. Defaults to false.If
true, the entity is hidden in Home Assistant until manually enabled. Defaults to false.The entity category (
config, diagnostic). Set to "" to remove the default.Switch Actions
switch.turn_on
switch.turn_off
switch.toggle
switch.control
Useful when the desired state is computed dynamically.
The switch to control.
true to turn on, false to turn off. Accepts lambda expressions.switch.is_on / switch.is_off Condition
Switch Triggers
on_turn_on / on_turn_off
Fire after the switch acknowledges the new state.
on_state
Fires on any state change. The new state is available as boolean x.
Lambda Calls
Popular Switch Platforms
GPIO Switch
Control a digital GPIO pin directly. Ideal for relay modules, LEDs, and other digital loads.
Template Switch
Synthesize a switch from C++ lambdas. Useful for virtual switches and complex logic.
Output Switch
Wrap any
output component as a switch entity. Bridges low-level outputs to the switch domain.Restart Switch
Trigger a device restart from Home Assistant. Always useful for remote management.
Shutdown Switch
Gracefully shut down the device. Useful for battery-powered devices.
Safe Mode Switch
Boot into safe mode. Allows recovery when a bad config prevents normal operation.
UART Switch
Send a configured UART byte sequence when the switch is toggled.
Modbus Switch
Control Modbus coil registers over RS-485, exposing them as Home Assistant switches.