Toggle a light
The Toggle action flips a light to the opposite state. If the light is off, it turns on. If it’s on, it turns off. This is handy for a single button or a motion sensor that should cycle a light without you having to know what state it’s in.
When Toggle turns a light on, you can also set the brightness, color, color temperature, or a transition at the same time, just like you would with Turn on. Those options are ignored when Toggle turns the light off.
Using this action from the user interface
If you prefer building automations and scripts visually, Home Assistant walks you through this action step by step. You pick what to target, tweak a few options, and save. No YAML knowledge required.
To toggle a light from an automation or a script:
- Go to Settings > Automations & scenes.
- Open an existing automation or script, or select Create to start a new one.
- If you’re setting up a new automation, add a trigger in the When section. Scripts don’t need a trigger. They run when something else calls them.
- In the Then do section, select Add action.
- From the search box, search for and select Light: Toggle.
- Under Targets, choose what you want to toggle:
- To toggle a specific light, select the entity.
- To toggle every light in a room, select an area.
- To toggle every light on a floor, select a floor.
- To toggle lights sharing a tag, select a label.
- Optional: under Advanced options, set the brightness, color, color temperature, or transition that should apply when the light turns on.
- Select Save.
Options in the UI
How long, in seconds, the light takes to reach the new state. Use this for a smooth fade instead of switching instantly.
How bright the light should be when the toggle turns it on, on a scale from 0 (off) to 255 (brightest).
How bright the light should be when the toggle turns it on, from 0% (off) to 100% (brightest).
A color for the light when the toggle turns it on. You can pick a named color, a color from the color wheel, or a specific value in RGB, hue/sat, or XY format.
Warm or cool white, measured in Kelvin, for when the toggle turns the light on. Lower is warmer (more yellow), higher is cooler (more blue).
A light effect to play when the toggle turns the light on, for example a color loop or a candle flicker. Available effects depend on the light.
Ask the light to flash briefly, either short or long. Useful as a visual notification.
Using this action in YAML
If you work directly in YAML, or you want to know exactly what Home Assistant does under the hood, this section has the technical reference. It lists the field names you use in YAML, their types, and which ones are required.
In YAML, refer to this action as light.toggle. A basic example looks like this:
action: light.toggle
target:
entity_id: light.hallway
This flips light.hallway to the opposite state.
Options in YAML
YAML sometimes provides additional options for more complex use cases that are not available through the UI.
Duration, in seconds, it takes to reach the next state. Use this to fade smoothly instead of switching instantly.
Number indicating brightness when the light turns on, where 0 is off, 1 is the minimum, and 255 is the maximum.
Percentage of full brightness when the light turns on, where 0 is off, 1 is the minimum, and 100 is the maximum.
A human-readable color name to apply when the light turns on, for example warm_white, tomato, or cornflowerblue.
Color temperature in Kelvin to apply when the light turns on. Lower values are warmer (more yellow), higher values are cooler (more blue).
The color in RGB format to apply when the light turns on. A list of three integers between 0 and 255 representing red, green, and blue.
Color in hue/sat format to apply when the light turns on. A list of two integers, where hue is 0 to 360 and saturation is 0 to 100.
Color in XY format to apply when the light turns on. A list of two decimal numbers between 0 and 1.
Light effect to apply when the light turns on. Available effects depend on the specific light.
Targets
This action supports targets. A target tells Home Assistant what the action should act on. You can point it at a single entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more], a device, an area, a floor, or a label, and Home Assistant runs the action on every matching light entity behind that target.
-
Entity: one specific light entity, such as
light.living_room. - Device: every light entity that belongs to a device.
- Area: every light entity in a room or area.
- Floor: every light entity on a floor.
- Label: every light entity that shares a label.
You can also mix target types in one call. For example, combine a specific entity with an area to run the action on both at once.
Good to know
- The Toggle action works on any light entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more], such as bulbs, groups, fixtures, or strips.
- When Toggle turns a light on, any brightness, color, or transition options you set are applied. When it turns a light off, those options are ignored.
- If you use Toggle on a group of lights, each light in the group flips its own state. Some lights may turn on while others turn off. To treat a group as one unit, create a dedicated light group first.
- If you already know the state you want, use Turn on a light or Turn off a light instead. They make the intent clearer in the automation’s name.
Try it yourself
Ready to test this? Open Developer tools > Actions, search for this action, fill in the fields, and select Perform action. You see what happens on your actual entitiesAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] without writing a line of YAML.
More examples
Real scenarios where this action shows up in automations and scripts. Copy any example and adapt it to your setup.
You don’t need to edit YAML to use these examples. Copy a YAML snippet from this page, open the automation editor in Home Assistant, and press Ctrl+V (or Cmd+V on Mac). Home Assistant automatically converts the pasted YAML into the visual editor format, whether it’s a full automation, a single trigger, a condition, or an action.
Action: flip the hallway light with a single button press
Wire a physical button or a dashboard tile to a single toggle action so it acts like a light switch.
- Action: Light: Toggle
- Target: Hallway light
YAML example for a one-button hallway toggle
action: light.toggle
target:
entity_id: light.hallway
Action: toggle the kitchen light to a warm white tone
When the toggle turns the kitchen light on, have it come up dim and warm instead of at full blast.
- Action: Light: Toggle
- Target: Kitchen light
- Brightness percentage: 40
- Color: warm_white
YAML example for a warm toggle
action: light.toggle
target:
entity_id: light.kitchen
data:
brightness_pct: 40
color_name: warm_white
Automation: toggle the hallway light with a physical button
Keep a smart button on the wall and flip the hallway light whenever you press it. A great way to add a light switch where there isn’t one.
- Trigger: Device: Button pressed
- Action: Light: Toggle
- Target: Hallway light
YAML example for a button-driven hallway toggle
alias: "Hallway button toggle"
triggers:
- trigger: state
entity_id: event.hallway_button
- trigger: event
event_type: zha_event
event_data:
device_ieee: "00:11:22:33:44:55:66:77"
command: "single"
actions:
- action: light.toggle
target:
entity_id: light.hallway
Automation: toggle the bathroom light on motion
When the bathroom motion sensor fires, flip the light. The next motion event flips it back, so you can also use the same automation to cut the light when you leave.
- Trigger: Motion sensor detects motion
- Action: Light: Toggle
- Target: Bathroom light
YAML example for toggling the bathroom light on motion
alias: "Toggle bathroom light on motion"
triggers:
- trigger: state
entity_id: binary_sensor.bathroom_motion
to: "on"
actions:
- action: light.toggle
target:
entity_id: light.bathroom
Automation: toggle the pantry light when the door opens
When the pantry door opens, flip the light. Close the door and the same trigger flips it back off the next time around.
- Trigger: Door sensor opens
- Action: Light: Toggle
- Target: Pantry light
YAML example for a pantry door toggle
alias: "Toggle pantry light on door"
triggers:
- trigger: state
entity_id: binary_sensor.pantry_door
to: "on"
actions:
- action: light.toggle
target:
entity_id: light.pantry
Still stuck?
The Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the action you’re calling and what you expected to happen, or share on our subreddit /r/homeassistant.
AI assistants like ChatGPT or Claude can also explain actions or suggest the right one when you describe what you want in plain language.
Related actions
These actions work well alongside this one:
-
Turn on a light - Turn a light on. Optionally set brightness, color, color temperature, an effect, or a transition.
-
Turn off a light - Turn a light off. Optionally fade it out with a transition, or have it flash briefly before it goes dark.