The quickest route is the built-in Motion-activated Light blueprint. It takes a motion sensor and a light, and turns the light off after a quiet period. If you want more control, write the automation by hand. Both approaches follow the same logic.
Before you start
- Your motion sensor should report
onwhen it sees motion andoffwhen motion clears. Motion sensors usually have themotionoroccupancydevice class. - Check the sensor under Developer Tools > States. Walk past it and confirm the state changes.
- Decide how long the light should stay on after motion stops.
Option 1: the Motion-activated Light blueprint
- Go to Settings > Automations & scenes > Blueprints.
- Select Motion-activated Light and choose Create automation.
- Pick your motion sensor and the light.
- Set the wait time, which is how long the light stays on after motion stops. The default is about two minutes. Adjust it for the room.
- Save the automation.
The blueprint uses restart mode, so new motion resets the timer. Some community blueprints have similar names but behave differently. Check which one you have installed before you rely on it.
Option 2: a manual automation
A manual automation shows exactly what happens, which makes it easy to change. The pattern is to turn the light on when motion starts, wait for motion to stop, pause, and then turn the light off.
automation:
- alias: "Hallway lights on motion"
mode: restart
triggers:
- trigger: state
entity_id: binary_sensor.hallway_motion
to: "on"
actions:
- action: light.turn_on
target:
entity_id: light.hallway
- wait_for_trigger:
- trigger: state
entity_id: binary_sensor.hallway_motion
to: "off"
- delay: "00:02:00"
- action: light.turn_off
target:
entity_id: light.hallway
mode: restart is the important line. Without it, motion during the delay is ignored, and the light can turn off while someone is still in the room.
Only turn on at night
To keep the lights off during the day, add a condition. You can use either of these:
- A sun condition, such as “after sunset”, which uses the sun’s position rather than a sensor.
- A numeric state condition on an illuminance sensor, so the light only comes on when the room is dark.
conditions:
- condition: numeric_state
entity_id: sensor.hallway_illuminance
below: 30
Choose the threshold for your room. Many people start somewhere around 20 to 50 lux and adjust it after reading the sensor during the day and at night. The value above is only a placeholder.
Place a lux sensor where it does not see the light itself. If the light’s glow pushes the reading over your threshold, the condition will fail the next time motion is detected.
Dim the light at night
For night visits, you can set a lower brightness and a warmer colour in the light.turn_on action. Not every bulb supports colour temperature, so test with your own lights.
- action: light.turn_on
target:
entity_id: light.hallway
data:
brightness_pct: 20
color_temp_kelvin: 2700
Choose the right motion sensor
- PIR sensors detect movement. They can miss someone who sits still. Many keep reporting motion for a while after it stops, so check your model’s behaviour before you set the wait time.
- mmWave presence sensors can detect people who are sitting or standing still, which suits rooms such as bathrooms and bedrooms.
To cover a room with several sensors, combine them in a Group helper of the binary sensor type. The group is on whenever any sensor in it is on.
Add a manual override
To stop the automation during a movie or a visit, add a condition that checks an input_boolean helper:
conditions:
- condition: state
entity_id: input_boolean.movie_mode
state: "off"
Turning on input_boolean.movie_mode then stops the automation from running.
Common mistakes
- Using
mode: single. The off-timer does not reset when new motion arrives. Userestart. - Forgetting the sensor’s own delay. The total time before the light turns off is the sensor’s cooldown plus your wait time.
- Turning the light off without checking. If someone switched the light on by hand, the automation can switch it off while they are still using the room. Add a condition, or accept that trade-off.
- Placing a lux sensor where it sees the light. See the note above.
If the automation never fires, see why your automation isn’t triggering. To learn how blueprints are imported and checked, see the blueprints guide. For modes and actions, see the automations and actions guide.