Automate a light with a motion sensor
ActivitiesProjects
Turn on a light when a sensor detects motion and test that it switches off after a quiet period.
Automating a light with a motion sensor links three pieces: a motion sensor entity, a controllable light entity, and an automation that tells the light how to respond when movement starts or stops. Once your hardware and integrations expose those two entities to a platform like Home Assistant, you can build the rule in a visual automation editor without writing code. Authoring a reusable YAML blueprint later is an optional step that assumes comfort with YAML, configuration-file editing, and scripts.
Switching on movement and waiting for a quiet room
The simplest automation mirrors the sensor directly, turning a light on whenever motion is detected and switching it off the moment the sensor clears—the pattern used in a basic kitchen-light teaching example. In everyday rooms, though, an immediate shutoff can leave you in the dark whenever you pause. A delayed-clear setup handles this with two state triggers: one fires when the motion entity changes to `on`, and the second fires only after the entity has stayed `off` for a chosen stretch, such as two minutes. When adapting a shared example like that, replace the placeholder sensor and light entity IDs with the ones belonging to your own installation, and adjust the shutoff interval to fit how the room is actually used.
A clear-duration trigger handles renewed movement cleanly. If the sensor detects motion again before the quiet countdown finishes, the timer stops; once the sensor returns to clear, the full duration starts over from the beginning. Keep one limitation in mind: an automation sitting inside a delay, wait, or trigger duration does not resume after a system restart. If you need a light to recover cleanly across a reboot, pair a start trigger with a condition rather than relying on a simple timeout alone.
Positioning a passive infrared sensor
A passive infrared (PIR) motion sensor reacts to shifts in the heat pattern across its field of view. Inside the housing, a Fresnel lens divides that field of view into small detection zones. Because walking straight toward a PIR detector crosses fewer zones than moving sideways across them, mounting the sensor at right angles to the usual line of travel improves detection. Keep a PIR sensor pointed away from direct sunlight, heat sources, and strong airflow, and avoid placing it to watch through glass panes, since PIR detectors do not detect movement behind glass. Follow your specific sensor's manual for its recommended mounting height and coverage area rather than assuming one placement rule fits every model.
Sensitivity, daylight limits, and the condition trap
Depending on the sensor and app you use, you can often fine-tune motion sensitivity—turning it down if the light fires too readily or raising it if intended movement goes unnoticed—along with a daylight threshold that suppresses activation when the room is already bright, separate day and night behavior, and an adjustable post-trigger timer. When you add a time or darkness condition inside Home Assistant, remember that conditions are evaluated only at the moment a trigger fires. A condition becoming true later does not start the automation on its own, so if a room is already occupied when a darkness or schedule window begins, that threshold needs its own trigger for the light to respond at that moment.
Testing with real movement and reusing the setup
After saving the automation, walk into the sensor's view to trigger a real motion event and wait through the clear period to confirm both the turn-on and shutoff actions work. Testing by clicking Run actions in the editor skips triggers and conditions completely, and any automation that reads `trigger` data to decide whether to switch the light on or off can behave differently during a manual run. If the light fails to react during a real test, open the automation's run trace: it shows whether the trigger never fired, a condition stopped the run, or the light action itself failed or had no effect.
Once a single-room automation is working reliably, you can turn it into a reusable YAML blueprint instead of rebuilding the same logic for every hallway or closet. Blueprint files live under `<config>/blueprints/automation/` and use configurable inputs—narrowed by selectors to motion-class binary sensors and light targets—so you can create new room automations from the blueprint in the Home Assistant UI.
