Turn on lights automatically when motion is detected

Last updated:

Includes Home Assistant automation

Motion-activated lighting turns a lamp or ceiling light on the moment a sensor sees movement, then off again once the room has been quiet for a few minutes. Without it, you are feeling along the wall for a switch in a room you are only crossing.

noyeshallway motion detectedhallway illuminancebelow 40 or hallwayceiling is onNothing happensTurn on (hallway ceiling)Wait until no hallwaymotionWait 5 minutesTurn off (hallway ceiling)
Trigger Condition Action Wait Nothing

What you need

Three things, and the sensor you pick decides whether you keep this automation or delete it after a week.

  • A motion sensor covering the way you walk into the room. Get one that reports light level in lux as well as motion, usually sold as a multi-sensor. That second reading is the whole trick, for reasons a few paragraphs down.
  • A light the platform can switch: a smart bulb, a smart switch in place of the wall switch, or an ordinary lamp plugged into a smart plug.
  • A hub to run the automation. On Apple Home that means a HomePod or an Apple TV, and sensor-triggered automations do not run without one.

How it works

The timer is the part you tune. Five minutes fits a hallway you pass through. Fifteen suits a bathroom. Any fresh movement restarts the count, so the light does not drop out from under someone who is still moving around.

This is where most people's version turns annoying.

You go shopping for a motion sensor, so you come home with a sensor that reports motion and nothing else. It fires just as happily at two in the afternoon with sunlight already across the floor, and the light comes on for nobody's benefit. A sensor that reports light level too lets the automation check whether the room is dark before it bothers.

Add that check and the automation goes quiet whenever the sun is doing the job for free.

The check has one wrinkle. A light sensor sitting in its own light's throw reads well above the threshold as soon as the light comes on. The second person through the door then arrives in a room that no longer looks dark. A naive version refuses to run for them, so their motion is ignored. The first person's timer runs out underneath them, and the light goes off with someone standing right there. The automation has to accept two reasons to run: the room is dark, or this light is already on.

Why the light comes on when nobody is there

Because passive infrared sensors do not see people. They see moving heat, so a curtain lifting over a radiator or a car's headlights sweeping through a window can be enough to set one off.

Placement is most of the fix, and it is worth doing before you commit. Add the sensor to your app first, hold it where you plan to mount it, then walk the room and watch what it reports. Aiming it across the doorway rather than out at the window is trivial at that stage and a nuisance once it is stuck to the wall.

The darkness check is where platforms differ

The plain version runs everywhere. Apple Home builds the timeout right into the automation as a "Turn Off After" step, and Alexa can drive the whole thing from the occupancy sensing already inside an Echo.

The light-level condition is the split. Home Assistant, Homey and SmartThings can hold a numeric lux condition without complaint. On Apple Home and Alexa, the honest fallback is restricting the automation to a time window such as sunset to sunrise. It is cruder, since it knows nothing about an overcast afternoon or a room with the blinds shut, but it catches the case that actually irritates you.

When motion is the wrong sensor

Sit still and a motion sensor stops reporting. The timer runs down and the light goes off on someone who never left, which is why waving an arm at the ceiling is a familiar smart home ritual.

So this automation belongs where people pass through: hallways, stairs, bathrooms, garages, the cupboard under the stairs. For rooms where people settle, a presence sensor holds the room occupied while you sit still, and that is a different automation: lights that follow occupancy rather than movement. Some sensors carry both kinds of detection in one unit, so the choice is not permanent.

This idea is shared for inspiration only, not professional advice. If it involves wiring, breakers, or high-draw appliances, verify ratings and your local electrical code, or hire a licensed electrician. Read our full disclaimer.

Get the Home Assistant Automation YAML

Validated against Home Assistant 2026.8.3 Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Example automation (Home Assistant). A starting point; swap in your own entity names.

alias: Hallway light on motion, only when dark
description: >-
  Turns the hallway light on when motion is detected and the room is dark, then
  off again five minutes after the sensor goes quiet. Swap in your own entity
  names.
mode: restart
triggers:
  - trigger: state
    entity_id: binary_sensor.hallway_motion
    to: "on"
conditions:
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.hallway_illuminance
        below: 40
      - condition: state
        entity_id: light.hallway_ceiling
        state: "on"
actions:
  - action: light.turn_on
    target:
      entity_id: light.hallway_ceiling
  - wait_for_trigger:
      - trigger: state
        entity_id: binary_sensor.hallway_motion
        to: "off"
  - delay:
      minutes: 5
  - action: light.turn_off
    target:
      entity_id: light.hallway_ceiling

That automation is yours to keep

Get a fresh idea like it - plus the week's smart home news and gear - in your inbox every Friday. Free, and unsubscribing is one click.

Related Ideas

Tagged: lighting, motion-detection, sensors

Want more ideas like this?

Fresh automation ideas plus the smart home news and gear worth knowing, in your inbox every Friday.