Turn lights or devices on when a room is occupied, off when empty

Includes Home Assistant automation

This automation uses a presence sensor to switch a light on when someone is in a room and off once it empties. A plain motion sensor times out and drops the light while you sit still, so you end up waving an arm to bring it back.

Get an automation idea like this - plus the week's smart home news and gear - in your inbox every Friday.

occupiednoyesemptyoffice occupiedoffice empty for 2minutesoffice illuminance below40Nothing happensTurn on (office)Turn off (office)
Trigger Condition Action Wait Nothing

What you need

  • A presence sensor for the room, usually sold as an mmWave or human presence sensor. What matters is that it uses radar to keep reporting you as present after you stop moving, rather than a plain PIR motion sensor that only reacts to movement. Some pair the two: radar to hold you, and a PIR element for a fast catch as you walk in. Others are radar only. Either works, because the radar is what does the real job here.
  • A smart light for the room. To control a fan or a heater instead, put it on a smart plug or an in-wall relay. Your hub drives a switched load the same way it drives a bulb.
  • A hub that can act on a held presence state and a delay. Home Assistant and Homey do this cleanly. The cloud assistants do a lighter version, covered below.
  • Optional: a light sensor, or a presence sensor with one built in, so the light stays off when the room is already bright.

How it works

A plain motion sensor turns the light on when it sees movement and off on a timer after the last motion it caught. Sit still to read or work, and the timer runs out. The light dies, and you wave an arm to bring it back. That arm-wave is the sign you are switching on motion, not on occupancy.

Presence sensing drops the timer. Radar is what makes that possible. It keeps seeing you after you stop moving, down to the rise and fall of breathing. So the room reads occupied for as long as anyone is in it, and clear only once it truly empties. Some sensors add a PIR element for a faster catch the instant you walk in, but it is the radar that holds you in a chair. The rule is then plain: presence turns on means light on, presence stays clear for a couple of minutes means light off. Gate the turn-on on a brightness reading and the light stays dark when the afternoon sun already did the job.

A presence sensor is only as good as its radar's real reach, and that reach can fall well short of the number on the box. A sensor rated for several meters can have its range set wide open and still register someone only when they are right next to it. It reports the room empty while you sit at the far side of it. Then the light cuts out while you are still there, the same arm-waving you left motion sensing to escape. The fault is not in the automation. It is a sensor that stopped seeing a person who was still there.

Getting presence to hold

This idea lives or dies on the sensor's setup, not the automation. Worth getting right before you trust it:

  • Aim and range. Radar covers a cone, and its useful reach is often shorter than the spec. Verify it rather than trusting the box. Point it where people actually sit, and open its range to the whole room rather than the near wall. A sensor that only registers you a short distance away will drop you the moment you settle.
  • A moving fan or a billowing curtain reads as a person to radar. Better sensors let you carve out a zone to ignore, so the fan in the corner does not hold the light on in an empty room.
  • The clear delay. Presence sensors carry their own no-presence timer, usually adjustable from a few seconds to a minute. The automation adds a little grace on top. Too short and a brief radar dropout blinks the light; too long and an empty room burns power. A minute or two, combined, is a sane start.
  • If your sensor exposes PIR and radar as two separate readings rather than one occupancy state, hold the light while either is active and release it only when both go quiet. That is the manual version of what a fused presence entity gives you.

Where it runs, and where it half-runs

Home Assistant and Homey run the full version locally: held presence, a brightness condition, a clearing delay. The cloud assistants are more limited but not shut out. A recent Amazon Echo with built-in ultrasound or Omnisense sensing can trigger an Alexa Routine as a room fills or empties, no extra sensor needed. That handles plain on and off well. What those routines do not do reliably is the only-when-dark condition or a graceful clearing delay. And getting a third-party presence sensor into Alexa or Google is its own snag. Pairing a sensor's hub over Matter often will not surface the presence the way the vendor's own skill does. The sensor you bought may not appear where you expect it. For the hold-and-dim version, this is a Home Assistant or Homey job.

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

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: Lights follow the room, on when occupied and dark, off once it empties
description: Turn a light on when the room becomes occupied and is dark, and off a couple of minutes after presence clears. Swap in your own entity names.
mode: single
trigger:
  - platform: state
    entity_id: binary_sensor.office_presence
    to: "on"
    id: occupied
  - platform: state
    entity_id: binary_sensor.office_presence
    to: "off"
    for:
      minutes: 2
    id: empty
action:
  - choose:
      - conditions:
          - condition: trigger
            id: occupied
          - condition: numeric_state
            entity_id: sensor.office_illuminance
            below: 40
        sequence:
          - service: homeassistant.turn_on
            target:
              entity_id: light.office
      - conditions:
          - condition: trigger
            id: empty
        sequence:
          - service: homeassistant.turn_off
            target:
              entity_id: light.office

Tagged: presence-detection, lighting-automation, energy-saving

Want more ideas like this?

One or two fresh automation ideas every week, plus the smart home news and gear worth knowing. Delivered every Friday.