Skip to main content

Wire a Motion-Activated Light

Goal: turn a light on when motion is detected and back off after the area goes quiet — a complete, real automation built from the pieces in the other automation guides.

This combines two macros (lights on, lights off) with two triggers (on motion, on no-motion). It's the canonical pattern; once you've built it, most reactive automations follow the same shape.

Before you start

  • You're logged in as an administrator.
  • A motion/occupancy sensor is commissioned and reporting — it exposes an attribute that goes true on motion (see Commission a Device).
  • The light zone you want to control exists.

1. Build the two macros

Following Build a Macro, create:

  • motion_lights_on — one command step: the light zone → on (or set_level to a brightness).
  • motion_lights_off — one command step: the light zone → off.

Turn Elevated off on both — these run from automation and shouldn't require an elevated user.

2. Trigger ON when motion starts

Following Create a Trigger, create motion_on:

  • Trigger Condition — the sensor's motion attribute becomes true.
  • Action — run motion_lights_on.
  • Schedule (optional) — limit active hours to evening/night if you only want it after dark.
  • Debounce — a small value keeps repeated motion from re-firing constantly.

3. Trigger OFF when motion clears

Create a second trigger, motion_off:

  • Trigger Condition — the motion attribute becomes false (no motion).
  • Action — run motion_lights_off.
  • Debounce — set this to your desired "hold" time so the lights stay on through brief stillness instead of snapping off the instant motion stops.

:::tip Two ways to do the off-delay The simplest hold is the off trigger's debounce. If your sensor reports occupancy with its own timeout, you can instead let the sensor drive the false transition and keep the debounce small. Either is fine — pick the one that matches how your sensor behaves. :::

4. Test it

  1. Walk into the area — the light should come on (within the active hours, if you set them).
  2. Leave and stay out — after the hold time, it should turn off.
  3. If it flickers or hangs on, adjust the debounce on the relevant trigger.

Why build it this way?

Keeping the actions in macros and the events in triggers means you can reuse the same motion_lights_on macro from a schedule or a UI button, and you can retarget the automation by editing one macro instead of the trigger. This separation is the same one described in Concepts → Architecture.