Control a Light with a Door state, with an optional on time condition

Description

Just a simple blueprint to control a Light’s on/off state by a Door’s open/closed state. It also contains a parameter to set a minimum on time for the light for the Door closing to turn the light back off. Some examples of how/why you would set this are included below.

Blueprint Code

Click the badge to import this Blueprint:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Or you can copy the code below:

blueprint:
  name: 'Control Light with Door'
  description: 'Control a Light by the. state of the door, with a turn-off condition to mimic occupancy'
  domain: automation
  input:
    controlling_door:
      name: "Door"
      description: "Door that controls the on/off state of the Light"
      selector:
        entity:
          domain: binary_sensor
    controlled_light:
      name: "Light"
      description: "Light that is controlled by open/closed state of the Door"
      selector:
        entity:
    closed_delay:
      name: "Light On Time"
      description: "Minimum time the light needs to be on for a Closed Door state to trigger turning the light off. This can mimic an occupancy state to stop the light from turning off right after turning on"
      selector:
        number:
          min: 0
          max: 3600

trigger:
  - platform: state
    entity_id: !input controlling_door

action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: !input controlling_door
                state: 'on'
              - condition: state
                entity_id: !input controlled_light
                state: 'off'
        sequence:
          - service: homeassistant.turn_on
            target:
              entity_id: !input controlled_light
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: !input controlling_door
                state: 'off'
              - condition: state
                entity_id: !input controlled_light
                state: 'on'
                for: 
                  seconds: !input closed_delay
        sequence:
          - service: homeassistant.turn_off
            target:
              entity_id: !input controlled_light
    default: []
mode: single

Examples

The blueprint contains a parameter called Light On Time, which is the time the light must be on before a door closed event will turn the light back off.

With a Light On Time of zero, you can use this to just turn on and off a light in sync with the door, which is useful for rooms like a Closet or Laundry Room. A Light On Time of around 30 seconds or greater will turn the light on when the door opens, but when the door closes it will only turn the light off if the light has been on for more than 30 seconds (or whatever Light On Time is set too). This is useful for rooms that will be occupied with one open/close of the door and unoccupied by another open/close, such a Bathroom or a Basement.

Technically, the Turn On Time only needs to be set for a few seconds (the time needed to enter a room and close the door) but higher times can prevent the automation from fighting you in unique edge cases, like entering and exiting a room quickly because you forgot something.