Motion Magic: Motion-Activated Automation
Now your home reacts to you moving through it. The Zigbee motion sensor detects movement with infrared, just like an alarm system, but you will use it for everyday convenience: lights that turn on as you enter a room and off when you leave. You will pair and place the sensor, then build a pair of automations that switch a light on with motion and off after a delay.
How a motion sensor works
The motion sensor detects movement using infrared light, the same technology used in alarm and security systems. It reports two states: detected when it senses motion, and clear when it has seen no movement for a few seconds. That simple pair of states is enough to make a room respond to a person walking in and going quiet when they leave. It is the same idea as the PIR sensor from Month 1, now speaking Zigbee to your hub.
Placement matters
Where and how you angle the sensor changes how well it works. Put it where people actually move, a doorway, a hallway, near a workstation, and aim it so people cross its field of view rather than walk straight at it, because motion sensors detect movement across their view better than toward it. Good placement is the difference between lights that trigger reliably and ones that miss you.
Two automations: on, then off
Motion lighting takes a pair of automations working together. The first turns the light on when motion is detected, often with a condition like after sunset so it only runs when it is actually dim. The second waits for the motion to clear and then, after a short delay such as two minutes, turns the light off. The delay is important: without it the light would flick off the instant you paused. With it, you get a room that lights up as you enter and quietly powers down after you have truly left.
Working through it
Pair the sensor. Add it through ZHA, entering pairing mode with the reset button or by reinserting the battery, then name it (like hallway motion) and assign a room.
Position it well. Mount it where people move and angle it so they cross its field of view rather than walk directly at it.
Test it. Walk in front and confirm the state goes to detected, then returns to clear after a few still seconds.
Automate the light on. Create an automation triggered by motion detected, with an after-sunset condition, and the action to turn on your bulb or plug.
Automate the light off. Create a second automation triggered by motion cleared, with an action to wait two minutes and then turn the light off.
Motion on after dark, off after a delay
# Automation 1: light ON when motion is detected after sunset
alias: Motion light on
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: "on" # motion detected
condition:
- condition: sun
after: sunset
action:
- service: light.turn_on
target: { entity_id: light.hallway_bulb }
# Automation 2: light OFF two minutes after motion clears
alias: Motion light off
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: "off" # motion cleared
for: { minutes: 2 } # stayed clear for 2 minutes
action:
- service: light.turn_off
target: { entity_id: light.hallway_bulb }
The first automation lights the room on motion, but only after sunset. The second waits until motion has been clear for two full minutes before turning the light off, so a brief pause does not plunge you into the dark.
Common mistakes and troubleshooting
The sensor misses you. Re-aim it so you cross its field of view rather than walk toward it, and place it where movement actually happens.
The light turns off while you are still there. Increase the off delay so a short period of stillness does not trigger it; motion sensors only report clear after no movement.
The light comes on in daylight. Add an after-sunset condition to the on automation.
Only one automation, so the light never turns off. You need a second automation triggered by motion clearing to turn it off.
Next: Next you will monitor temperature and humidity and control a fan automatically.