Switch
The Switch integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] manages the state of the switch entities and allows you to control them.
- Maintains a state for each of your switches.
- Registers actions
switch.turn_on,switch.turn_off, andswitch.toggleto control switches.
Building block integration
This switch is a building block integration that cannot be added to your Home Assistant directly but is used and provided by other integrations.
A building block integration differs from the typical integration that connects to a device or service. Instead, other integrations that do integrate a device or service into Home Assistant use this switch building block to provide entities, services, and other functionality that you can use in your automations or dashboards.
If one of your integrations features this building block, this page documents the functionality the switch building block offers.
Switch states
A switch entity can have the following states. Each item shows the label you see in the Home Assistant interface, followed by the state as Home Assistant stores it. If you write templates or edit automations in YAML, use the stored state.
-
On (
on): The switch is turned on. -
Off (
off): The switch is turned off.
In addition, the entity can have the following states:
-
Unavailable (
unavailable): The entity is currently unavailable. -
Unknown (
unknown): The state is not yet known.
Device class
The device class tells Home Assistant whether a switch controls a power outlet. Home Assistant uses the device class to choose the icon. Google Assistant, Alexa, and Apple Home use the device class to show an outlet as an outlet or a smart plug.
The integration that provides the switch sets the device class.
Device classes in automations and templates
- Automations: The device class doesn’t change how a switch works in automations.
- Templates: The device class is the
device_classattribute of the entity. Use the stored value, such asoutlet. For example, you can find entities by device class.
List of available device classes
A switch without a device class is a generic switch and shows
Each item shows the name you see in the Home Assistant interface, followed by the device class as Home Assistant stores it.
-
Outlet ( outlet): A switch for a power outlet. -
Switch ( switch): A generic switch.
Changing the device class of a switch
If a switch controls an outlet or a smart plug but shows up as a switch, or the other way around, you can change its device class.
You can only change the device class in the UI if the switch has a unique ID. A switch without a unique ID shows a message in its entity settings instead. For such a switch, you can change the device class in YAML with customization.
- Go to Settings > Devices & services > Entities and select the switch.
- In the top-right corner, select Settings
. - Under Show as, select Switch or Outlet.
- The other options, such as Light or Fan, don’t change the device class. Instead, Home Assistant creates a new entity of that type and hides the switch. For details, refer to Change device type of a switch.
- Select Update.
- Result: The switch shows the matching icon, unless you’ve set a custom icon for the switch.
List of triggers
The Switch integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following triggers. Each link below opens a dedicated page with examples, fields, and a step-by-step UI walkthrough.
-
Switch turned off (
switch.turned_off) Triggers when one or more switches turn off. -
Switch turned on (
switch.turned_on) Triggers when one or more switches turn on.
For an overview of every trigger across all integrations, see the triggers reference.
List of conditions
The Switch integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following conditions. Each link below opens a dedicated page with examples, fields, and a step-by-step UI walkthrough.
-
Switch is off (
switch.is_off) Tests if one or more switches are off. -
Switch is on (
switch.is_on) Tests if one or more switches are on.
For an overview of every condition across all integrations, see the conditions reference.
List of actions
The Switch integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following actions. Each link below opens a dedicated page with examples, parameters, and a step-by-step UI walkthrough.
-
Toggle switch (
switch.toggle) Toggles a switch on or off. -
Turn off switch (
switch.turn_off) Turns a switch off. -
Turn on switch (
switch.turn_on) Turns a switch on.
For an overview of every action across all integrations, see the actions reference.