Button Toggles a Room Light¶
Difficulty: Level 1
The Starter Kit's button already controls the kit's own RGB LEDs in Button Controlled LEDs. This tutorial takes it further: pressing the button fires a Home Assistant automation that toggles any light in your home. Same physical button, but now it reaches across your whole house.
Before you start
Work through these pages first. This tutorial assumes your device is flashed, the Button module is wired up, and the kit is connected to Home Assistant:
- First Steps to create your starter kit device in ESPHome Device Builder.
- Adding the Button Module to wire up the input.
- Connect to Home Assistant to bring the device's entities into HA.
Find your button entity¶
The Button module shows up in Home Assistant as a binary sensor. You need its entity ID before building the automation.
- Open Settings → Devices & services → ESPHome in Home Assistant.
- Click your Starter Kit device.
- Under Entities, look for a binary sensor named Button Module. Click it to open the entity detail, then note the entity ID shown near the top of the dialog - it will look something like
binary_sensor.esphome_starter_kit_button_module. Keep that ID handy.
Build the automation¶
- Open Settings → Automations & scenes in Home Assistant.
- Click + Create automation in the bottom right, then choose Create new automation.
-
Under Triggers, click + Add trigger and choose Entity → State.
- Entity → select your button entity (the binary sensor you found above)
- To →
On(1)
- The button registers as a binary sensor.
Onmaps to a pressed state - the moment you push the button down. Home Assistant fires the automation at that instant.
-
Under Then do, click + Add action and choose Perform action (labeled Call service in older versions of Home Assistant).
- Search for and select light.toggle (1)
- Under Targets, click Choose entity and pick the light you want to control.
light.toggleturns the light on if it is off, and off if it is on - one action handles both directions. If you want to always turn on or always turn off, uselight.turn_onorlight.turn_offinstead.
-
Give the automation a name like
Button toggles room light. - Click Save.
What the automation looks like in YAML
Home Assistant stores automations as YAML. Select Edit in YAML from the three-dot menu on the automation to see or paste the raw config. Your entity IDs will differ from the example below.
Test the automation¶
Press the button on the Button module. The light you targeted toggles. Press again and it toggles back.
Your kit is now a physical remote for Home Assistant!
Any light in your home - a bedside lamp, a ceiling group, a smart bulb strip - is one button press away. Swap light.toggle for light.turn_on with a brightness_pct to land on a specific brightness, or target a light group to control a whole room at once.
New to ESPHome? We're here to help.
Stuck on a step or want to show off what you built? Ask questions and share projects with the Apollo community.