What do you need before you start?
- A motion sensor that reports to Home Assistant. Any Zigbee, Matter or Wi-Fi sensor that appears as a motion or occupancy
binary_sensorworks. Our best Zigbee motion sensors roundup compares options. - A dimmable smart bulb or light strip that supports brightness and warm colour temperature. Plain on/off smart plugs cannot do a dim glow.
- A toggle helper. Home Assistant describes an
input_booleanas an entity that stores an on or off state you can set yourself. You create one under Settings, Devices & services, Helpers, then choose Toggle. - Entity IDs written down. The example uses
binary_sensor.hallway_motion,light.hallwayandinput_boolean.hallway_night_light. Swap in your own.
If you would rather start from a pre-built recipe, see our blueprints guide; building it by hand is still worth doing once because the pattern below reuses for stairs, bathrooms and bedrooms.
Away for a few days? See how to make an empty house look occupied with a Home Assistant presence simulation that varies lamp times each night.
Step 1: Tune the motion sensor for night use
Start at the sensor, because its own settings decide how twitchy the light feels. Most Zigbee sensors apply a hold time after movement before they report clear, and Home Assistant only sees what the sensor reports.
Two examples from Zigbee2MQTT's device pages. The SONOFF SNZB-03P exposes a motion_timeout setting, described as the occupied-to-unoccupied delay, adjustable between 5 and 60. The Aqara Motion Sensor P1 exposes a detection interval (from 2 to 65535 seconds), a motion sensitivity of low, medium or high, and an illuminance reading in lux. Changing the P1's settings requires pressing its pairing button immediately beforehand, otherwise the change fails.
For a night light, keep the sensor's own hold time short and let Home Assistant add the extra minute in Step 3. That way you tune the delay in one place, in the automation, rather than re-pairing a battery sensor every time you want to change it.
Home Assistant's binary sensor documentation lists both a motion class and an occupancy class, each showing Detected for on and Clear for off. Either works here, because the automation only cares about on and off.
Step 2: Create the toggle helper
Go to Settings, Devices & services, Helpers, choose Create helper, pick Toggle, name it "Hallway night light" and save. Its entity ID becomes input_boolean.hallway_night_light.
This helper records one fact: the automation, not a person, switched the light on. When the sensor clears, the automation only turns the light off if this flag is on. Without it, someone who deliberately turned the hallway light on at full brightness to look for a lost earring would have it switched off a minute after they stopped moving past the sensor.
Step 3: Build the automation
Open Settings, Automations & scenes, create a new automation, switch to YAML mode from the three-dot menu and paste the block below. It uses the current triggers, conditions and actions keys with trigger: and action: inside them.
alias: Hallway night light
description: Dim warm light on motion at night, off a minute after the hallway clears
mode: single
triggers:
- trigger: state
entity_id: binary_sensor.hallway_motion
to: "on"
id: motion_on
- trigger: state
entity_id: binary_sensor.hallway_motion
to: "off"
for: "00:01:00"
id: motion_clear
actions:
- choose:
- conditions:
- condition: trigger
id: motion_on
- condition: time
after: "22:00:00"
before: "06:30:00"
- condition: state
entity_id: light.hallway
state: "off"
sequence:
- action: input_boolean.turn_on
target:
entity_id: input_boolean.hallway_night_light
- action: light.turn_on
target:
entity_id: light.hallway
data:
brightness_pct: 10
color_temp_kelvin: 2700
transition: 2
- conditions:
- condition: trigger
id: motion_clear
- condition: state
entity_id: input_boolean.hallway_night_light
state: "on"
sequence:
- action: light.turn_off
target:
entity_id: light.hallway
data:
transition: 5
- action: input_boolean.turn_off
target:
entity_id: input_boolean.hallway_night_light
The two triggers. The first fires the moment the sensor reports on. The second uses Home Assistant's for option, which the docs describe as the time the new state must remain unchanged before the trigger fires, so it only fires once the sensor has stayed off for a full minute. If movement resumes in that window, the timer is cancelled. Home Assistant's documentation also notes that a for timer resets if Home Assistant restarts or automations are reloaded.
The conditions. The choose block runs different actions depending on which trigger ID fired. The motion branch requires the time window and that the light is currently off, so the automation never overrides a light someone has already set.
The actions. They use brightness_pct and color_temp_kelvin from the light.turn_on action, with transition as the fade time in seconds. Home Assistant's documentation says to use either brightness or brightness_pct for brightness, not both.
Does the time condition work past midnight?
Yes. Home Assistant's time condition documentation says that if Before is earlier than After, the time window goes past midnight. That is why after: "22:00:00" with before: "06:30:00" works as a single overnight window with no second condition.
One quirk from the same page: day-of-week checks use the current calendar day, so hours after midnight count as the next day. If you add a weekday filter, a 01:00 trip on Saturday morning counts as Saturday, not Friday night.
If your household's night is not a fixed clock window, swap the time condition for a sun-based one. Home Assistant documents a sun trigger with an offset, written in hh:mm:ss format, where a negative value fires before sunset and a positive one after. That suits UK winters, when it is dark by late afternoon, but a fixed window is more predictable for bedrooms and landings where daylight is not the issue.
Step 4: Pick brightness and colour for the glow
Ten per cent at 2700 K is a starting point, not a rule. Smart bulbs differ in how low they can dim and how warm they can go, so adjust the two numbers until the light is enough to see the floor without waking anyone. Lower Kelvin values are warmer and more yellow, higher values are cooler and bluer, according to the light.turn_on documentation. A lower value than 2700 gives a more amber glow if your bulb supports it.
Test at the real time of night, in the real hallway. A level that looks dim in a lit room can look bright at 3am. For a related approach to making lighting respond to time of day, our smart lighting automation tips include more ideas, and our scenes guide shows how to store a preset such as a "night glow" and reuse it from several automations.
| Setting | Where it lives | What it controls | Starting value |
|---|---|---|---|
| Sensor hold time | The sensor (for example SNZB-03P motion_timeout) | How long the sensor waits before reporting clear | Keep it short |
for on the clear trigger | The automation | How long the area must be clear before the light goes off | 1 minute |
brightness_pct | The turn-on action | How bright the glow is | 10% |
color_temp_kelvin | The turn-on action | How warm the glow is | 2700 K |
transition | Turn-on and turn-off actions | Fade time in seconds | 2 s on, 5 s off |
| Time window | The time condition | When the automation is allowed to run | 22:00 to 06:30 |
Step 5: Test it and read the trace
Save the automation, make sure the hallway light is off, then walk past the sensor during the time window. The light should fade up to the glow, and a minute after you leave it should fade out. To check the clear branch without waiting for the real hours, temporarily widen the time window in the condition, run through the sequence, then set it back.
If something does not fire, open the automation's trace first. Home Assistant's troubleshooting guide says most problems show up in the trace of the automation, and suggests selecting the step that ended the run and checking its details for the result or error.
Should the light stay on while someone is still in the room?
Yes, and the two-trigger design handles it. The light stays on as long as the sensor keeps reporting motion, and only goes off once the sensor has reported clear for the full minute. Because the second trigger waits for a sustained clear state, a person who pauses on the stairs does not get plunged into darkness.
That said, a passive infrared sensor only sees movement. Someone sitting still in the hallway can look the same as an empty hallway. For rooms where people stay put, such as a bathroom or office, a presence sensor is a better fit, and our mmWave presence sensor roundup covers the options. The same pattern also works for extractor fans, as in our bathroom extractor fan automation.
Why isn't my night light automation working?
The light never comes on. Check the time condition and the light-is-off condition in the trace. If the hallway light was already on, the motion branch will deliberately skip. Also confirm the sensor entity ID matches the one in your YAML.
The light comes on but never goes off. The for timer only starts once the sensor reports off. If the sensor keeps flickering to on because it is too sensitive, or because a pet is walking past, the minute never completes. Lower the sensor's sensitivity or accept a longer hold.
The light goes off after a manual switch-on. The helper flag should prevent this. If it still happens, check that the helper turns on in the motion branch and that you did not switch the light on during the exact same moment as a motion trigger.
It stops working after a restart. Home Assistant's trigger documentation states that for timers reset on a restart or an automation reload. A restart mid-window can therefore leave the light on until the next motion event. Set the helper to restore its previous state, which is its default, and consider a second automation to switch the light off if the helper is on and the sensor is clear.
Using a delay instead of the clear trigger. Some guides use a delay action. If you go that route, set the automation to restart mode. Home Assistant's automation modes documentation says restart stops the current run, including a delay or wait that is running, and starts a new run, whereas the default single mode ignores new triggers while a run is in progress.
What can you build on top of this?
Once the pattern works, copy the automation for the landing, the stairs and the bathroom, giving each its own helper. Add an illuminance condition if your sensor reports lux, so the light stays off on bright mornings. Or use a lower brightness for rooms with children asleep. Because the structure is the same each time, you only change the entity IDs, the time window and the glow settings.





