The Night Light Pattern: Zone-Triggered Lighting That Actually Works
You've got a security panel with motion sensors in every room. You've got smart lights. Why not make them work together?
Walk into the kitchen at 2 AM and the lights come on at 30% — bright enough to see, dim enough not to blind you. Walk out, and they turn off after 2 minutes. No voice command. No app. No thinking.
Here's the automation pattern that makes this work, and the three mistakes that will break it.
The Pattern
automation:
- alias: "Night Light — Kitchen Motion"
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.elk_kitchen_pir
to: "on"
condition:
- condition: sun
after: sunset
- condition: state
entity_id: light.kitchen_cans
state: "off"
action:
- service: light.turn_on
target:
entity_id: light.kitchen_cans
data:
brightness_pct: 30
- delay: "00:02:00"
- service: light.turn_off
target:
entity_id: light.kitchen_cansSimple. But every line matters.
Why mode: restart
If you walk through the kitchen, the light comes on and the 2-minute timer starts. If you walk through again 90 seconds later, mode: restart cancels the running timer and starts a fresh 2-minute countdown. Without restart mode, the second trigger gets dropped and the light turns off 30 seconds later (from the first timer).
For night lights, restart is always the right mode. For zone monitoring (multiple sensors firing simultaneously), use parallel. For alarm response (only one instance), use single.
Why Check If the Light Is Off
The condition state: "off" on the light prevents this automation from overriding manual lighting. If you've turned the kitchen lights to 100% for cooking, you don't want a motion sensor dimming them to 30%.
Mistake #1: Forgetting the Sun Condition
Without condition: sun, after: sunset, this fires during the day too. Motion sensor triggers at noon → lights turn on to 30% → looks broken. Always gate night lights on sun position.
Mistake #2: Movie Mode
In my living room, the motion sensor is 8 feet from the TV. Without a movie mode check, the lights flash on at 30% every time someone shifts on the couch during a movie.
Add this condition for rooms with media players:
- condition: not
conditions:
- condition: state
entity_id: media_player.living_room_tv
state: playingMistake #3: Using entity_id: all
Never use entity_id: all for any lighting automation. I learned this the hard way — my alarm flash automation targeted "all" lights and turned on the pool pump relay, the gas fireplace ignitor relay, and a receptacle controlling a space heater. At 2 AM.
Always list specific entities.
Combining PIR + Camera AI
Wired PIR sensors are instant but only work at night (infrared can't distinguish body heat from sun-heated surroundings during the day). Camera AI person detection has a 1-2 second delay but works 24/7.
Use both as triggers:
trigger:
- platform: state
entity_id: binary_sensor.elk_driveway_pir
to: "on"
- platform: state
entity_id: input_boolean.cam_front_driveway_person
to: "on"Either source fires the lights. The PIR fires first at night; the camera covers daytime. Total coverage.
Tool of the Week: HA Package Architecture
Instead of one massive automations.yaml, split your automations into packages — one per domain:
# configuration.yaml
homeassistant:
packages: !include_dir_named packagesThen create /config/packages/night_lights.yaml, garage.yaml, security_modes.yaml, etc. Each file is self-contained with its own automations, input_booleans, timers, and scripts.
Benefits: easier to debug, easier to share, easier to disable an entire domain by renaming the file.
Tuesday: The M1XEP TCP drop — why your ELK panel disconnects from HA during an actual alarm, and the workaround that saved my system.
— The Automated Home