Home Assistant

Closet and pantry light on a door sensor

A door contact turns the closet light on at a day or night level, off when the door closes, and off on a safety timer if the door is left open. Motion inside can hold the light while someone is still in there.

Difficulty · BeginnerSetup · 20–40 minutesHA · 2024.10 or newer
Get the pack · from $19Have us set it up

Some hardware links on this page are affiliate links. As an Amazon Associate I earn from qualifying purchases. We may earn a commission if you buy through them, at no extra cost to you. See the affiliate disclosure.

A closet light tied only to a door is right until someone shuts the door from the inside, or leaves it open and goes to work. This blueprint turns the light on when the contact opens, picks a day or night brightness, turns it off when the door has been closed (after a grace delay, and after motion inside clears), and turns it off anyway if the door stays open too long.

The contact has to be on when the door is open. If yours is the other way around, invert that sensor before you select it.

A battery reed you build yourself, instead of a contact you already have, is battery reed door sensor. A notify when any door or window sits open is door and window open notify. Motion that picks a scene rather than a single light is motion scene tiers.

What problem it solves

You want the pantry or closet light to follow the door, bright enough to see at night, and not left on all afternoon because the door did not latch.

How it works

  1. Open. The door binary sensor turns on. The light turns on at the day brightness, or the night brightness if the sun is below the horizon (or if the clock is inside the night window you set). Color temperature is sent only when that Kelvin value is above 0, so a bulb that has no tunable white is left alone.
  2. Close. The sensor turns off. The blueprint waits the grace delay (default 0, so it is immediate), checks the door is still closed, then waits until the motion sensor is off. Then it turns the light off.
  3. Someone still inside. If you have a motion sensor, select it. Closing the door does not turn the light off while that sensor is on. When motion clears and the door is already closed, the light turns off. If you have no motion sensor, create an input boolean, leave it off, and select that. The wait then finishes immediately.
  4. Door left open. A second trigger, the door on for N minutes (default 30), turns the light off and runs an optional action (a notification, a second light, whatever you put there). The light stays off until the door closes and opens again. Turn the safety timer input off to skip this.

The automation is mode: restart, so a new door event cancels a grace delay that is still running.

Snippet

The door entity, the light target, and the night choice are the inputs that matter first.

triggers:
  - trigger: state
    entity_id: !input door
    to: "on"
    id: open
  - trigger: state
    entity_id: !input door
    to: "off"
    id: close
  - trigger: state
    entity_id: !input door
    to: "on"
    for:
      minutes: !input max_on_minutes
    id: max_on

Setup outline

  1. Copy blueprints/automation/closet_door_light.yaml into config/blueprints/automation/edotdev/ and reload blueprints.
  2. Confirm the door sensor is on with the door open. Invert it if it is backwards.
  3. Create the automation. Pick the door, the light (or a light group), and a motion sensor or an input boolean that stays off.
  4. Set day and night brightness. Leave both Kelvin values at 0 unless the bulb accepts color_temp_kelvin.
  5. Leave the night window on sun, or switch it to clock and set the two times. The clock window may wrap past midnight.
  6. Open the door. The light should come on. Close it. The light should go off after the grace delay. Leave it open past the safety timer and confirm it goes off and stays off until you cycle the door.

Troubleshooting

  • The light turns on when the door shuts. The contact is on when closed. Invert that binary sensor. This blueprint does not have a separate invert input.
  • It never turns off. Motion is still on, or the sensor you picked is an input boolean you left on. The close path waits until that entity is off.
  • A short open does nothing. Another automation is turning the light off, or the target does not include the bulb you are watching.
  • Night brightness is used all day. Night source is sun and the sun entity is unavailable, or the clock window is inverted from what you wanted. sun follows sun.sun. clock compares the current time to the two times, and a start later than the end wraps overnight.
  • The safety timer fights the grace delay. That is mode: restart. The timer firing cancels an in-progress grace and turns the light off. If you do not want that, turn the safety timer input off.
  • Color temperature errors in the trace. The bulb rejected color_temp_kelvin. Set both Kelvin inputs back to 0.

Credits

Closet, pantry, and cupboard lighting is a long-running topic on the Home Assistant forum: Closet, pantry, and cupboard lighting.

Changelog

v1.0 · Oct 31, 2026: First publish.