All docs

Docs/forgot-to-turn-off.yaml

Forgot to Turn Off - No Presence Light Safety

automation · HA 2025.7.0+ · 3 inputs

A simple safety-net blueprint for lights that have been left on. Created by @0libote GitHub: https://github.com/0libote/HA-BPs Behaviour: - Never turns lights on and never changes brightness, colour, scenes, or other automation state. - Supports one or multiple motion, occupancy, or presence sensors. - Starts the safety countdown only when every selected presence sensor is clear, and turns the selected lights off only if every sensor stays clear for the entire configured time. - If a selected light is turned on while the area is already clear, starts a fresh safety countdown and only acts if all sensors remain clear for that entire countdown. - If Home Assistant restarts while the area is clear, starts a fresh safety countdown rather than immediately switching anything off. - Motion or occupancy returning on any selected sensor during a safety countdown prevents that countdown from switching the lights off. - Unknown or unavailable sensors are treated as not clear, so a sensor fault cannot cause an automatic switch-off. This blueprint is intentionally passive. It does not try to own the lights or replace your existing lighting automations. It is just a final "forgot to turn it off" safety net.

Manual import URL: https://github.com/0libote/HA-BPs/blob/main/blueprints/forgot-to-turn-off.yaml

Setup guide

Forgot to Turn Off

Forgot to Turn Off

![Import blueprint](https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https%3A%2F%2Fgithub.com%2F0libote%2FHA-BPs%2Fblob%2Fmain%2Fblueprints%2Fforgot-to-turn-off.yaml)

Manual import URL:

https://github.com/0libote/HA-BPs/blob/main/blueprints/forgot-to-turn-off.yaml

This is a passive safety net for lights controlled manually or by other automations. It never turns a light on or changes brightness, colour, scenes or another automation.

Configure

The countdown restarts safely after Home Assistant starts or a selected light is turned on while the area is already clear. Unknown or unavailable sensors are treated as occupied so a sensor fault cannot cause an automatic switch-off.

Troubleshooting

View the YAML

Input reference

Every field, default and selector — generated from the YAML at build time.

Presence sensors · open by default
InputSelectorDefault
Motion / Occupancy Sensors
presence_sensor
Select one or more sensors covering the area. Every selected sensor must stay clear for the full timeout before the lights are switched off.
entity null
Lighting lights · open by default
InputSelectorDefault
Lights to Turn Off
target_lights
These lights are only ever switched off by this blueprint.
entity null
Timing timing · open by default
InputSelectorDefault
No Presence Before Off
no_presence_duration
How long every selected sensor must stay continuously clear before the lights are switched off.
duration {"hours":1,"minutes":0,"seconds":0}

Source

Full blueprint — also on GitHub.

blueprint:
  name: Forgot to Turn Off - No Presence Light Safety
  author: 0libote
  description: |
    A simple safety-net blueprint for lights that have been left on.

    Created by @0libote
    GitHub: https://github.com/0libote/HA-BPs

    Behaviour:
    - Never turns lights on and never changes brightness, colour, scenes, or
      other automation state.
    - Supports one or multiple motion, occupancy, or presence sensors.
    - Starts the safety countdown only when every selected presence sensor is
      clear, and turns the selected lights off only if every sensor stays clear
      for the entire configured time.
    - If a selected light is turned on while the area is already clear, starts
      a fresh safety countdown and only acts if all sensors remain clear for
      that entire countdown.
    - If Home Assistant restarts while the area is clear, starts a fresh safety
      countdown rather than immediately switching anything off.
    - Motion or occupancy returning on any selected sensor during a safety
      countdown prevents that countdown from switching the lights off.
    - Unknown or unavailable sensors are treated as not clear, so a sensor fault
      cannot cause an automatic switch-off.

    This blueprint is intentionally passive. It does not try to own the lights
    or replace your existing lighting automations. It is just a final
    "forgot to turn it off" safety net.

  domain: automation
  source_url: https://github.com/0libote/HA-BPs/blob/main/blueprints/forgot-to-turn-off.yaml

  homeassistant:
    min_version: 2025.7.0

  input:
    sensors:
      name: Presence
      icon: mdi:motion-sensor
      collapsed: false
      input:
        presence_sensor:
          name: Motion / Occupancy Sensors
          description: |
            Select one or more sensors covering the area. Every selected sensor
            must stay clear for the full timeout before the lights are switched off.
          selector:
            entity:
              multiple: true
              filter:
                - domain: binary_sensor
                  device_class: occupancy
                - domain: binary_sensor
                  device_class: motion
                - domain: binary_sensor
                  device_class: presence

    lights:
      name: Lighting
      icon: mdi:lightbulb-group-off-outline
      collapsed: false
      input:
        target_lights:
          name: Lights to Turn Off
          description: These lights are only ever switched off by this blueprint.
          selector:
            entity:
              multiple: true
              filter:
                - domain: light

    timing:
      name: Timing
      icon: mdi:timer-outline
      collapsed: false
      input:
        no_presence_duration:
          name: No Presence Before Off
          description: How long every selected sensor must stay continuously clear before the lights are switched off.
          default:
            hours: 1
            minutes: 0
            seconds: 0
          selector:
            duration:
              enable_day: true

variables:
  presence_sensors: !input presence_sensor
  target_lights: !input target_lights

trigger:
  - platform: state
    entity_id: !input presence_sensor
    to: "off"
    id: presence_cleared

  - platform: state
    entity_id: !input target_lights
    to: "on"
    id: light_turned_on

  - platform: homeassistant
    event: start
    id: home_assistant_started

condition: []

action:
  - condition: template
    value_template: >
      {{ trigger.id in
         ['presence_cleared', 'light_turned_on', 'home_assistant_started'] }}

  - alias: Only start when every selected presence sensor is clear
    condition: template
    value_template: >
      {{ (expand(presence_sensors) | list | count) > 0
         and (expand(presence_sensors)
              | rejectattr('state', 'eq', 'off')
              | list
              | count) == 0 }}

  - alias: Remember exactly when each sensor became clear
    variables:
      clear_state_signature: >
        {% set ns = namespace(parts=[]) %}
        {% for sensor in expand(presence_sensors) | sort(attribute='entity_id') %}
          {% set ns.parts = ns.parts +
             [sensor.entity_id ~ '=' ~ sensor.last_changed] %}
        {% endfor %}
        {{ ns.parts | join('|') }}

  - delay: !input no_presence_duration

  - alias: Every sensor must still be clear
    condition: template
    value_template: >
      {{ (expand(presence_sensors) | list | count) > 0
         and (expand(presence_sensors)
              | rejectattr('state', 'eq', 'off')
              | list
              | count) == 0 }}

  - alias: No selected sensor may have detected presence during the countdown
    condition: template
    value_template: >
      {% set ns = namespace(parts=[]) %}
      {% for sensor in expand(presence_sensors) | sort(attribute='entity_id') %}
        {% set ns.parts = ns.parts +
           [sensor.entity_id ~ '=' ~ sensor.last_changed] %}
      {% endfor %}
      {{ ns.parts | join('|') == clear_state_signature }}

  - alias: Only act if at least one selected light is still on
    condition: template
    value_template: >
      {{ (expand(target_lights)
           | selectattr('state', 'eq', 'on')
           | list
           | count) > 0 }}

  - action: light.turn_off
    target:
      entity_id: !input target_lights

mode: parallel
max: 20
max_exceeded: silent