Last active
September 19, 2026 15:45
-
-
Save bmfurtado/1b92f7f108617c932ffd03fe7d26aad3 to your computer and use it in GitHub Desktop.
Sensor Triggered Light HA Automation Blueprint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| blueprint: | |
| name: Door light after dark (manual control preserved) | |
| description: >- | |
| Turns a light on for a set time when a door opens, but only when the sun is | |
| below a configurable elevation. Never touches a light that was already on, | |
| and backs off if the light is turned off manually during the window. | |
| Re-opening the door during the window restarts the timer. | |
| domain: automation | |
| homeassistant: | |
| min_version: 2024.10.0 | |
| input: | |
| door_sensor: | |
| name: Door sensor | |
| description: Binary sensor that is "on" when the door is open. | |
| selector: | |
| entity: | |
| filter: | |
| - domain: binary_sensor | |
| device_class: | |
| - door | |
| - garage_door | |
| - opening | |
| - window | |
| light_entity: | |
| name: Light | |
| description: Light (or switch) to control. Single entity. | |
| selector: | |
| entity: | |
| filter: | |
| - domain: light | |
| - domain: switch | |
| on_duration: | |
| name: On duration | |
| description: How long the light stays on after the last door opening. | |
| default: | |
| hours: 0 | |
| minutes: 5 | |
| seconds: 0 | |
| selector: | |
| duration: | |
| sun_elevation: | |
| name: Sun elevation threshold | |
| description: >- | |
| Only run when the sun's elevation is below this. 0 is sunset/sunrise, | |
| 3 to 6 is "getting dim", negative values are proper dusk. | |
| default: 4 | |
| selector: | |
| number: | |
| min: -12 | |
| max: 20 | |
| step: 0.5 | |
| unit_of_measurement: "°" | |
| mode: slider | |
| mode: single | |
| max_exceeded: silent | |
| # !input can't be used inside templates, so expose the entity id as a variable. | |
| variables: | |
| light_entity: !input light_entity | |
| triggers: | |
| - trigger: state | |
| entity_id: !input door_sensor | |
| from: "off" | |
| to: "on" | |
| conditions: | |
| - condition: numeric_state | |
| entity_id: sun.sun | |
| attribute: elevation | |
| below: !input sun_elevation | |
| # Already on means someone else owns the light, so leave it alone. | |
| - condition: state | |
| entity_id: !input light_entity | |
| state: "off" | |
| actions: | |
| - action: homeassistant.turn_on | |
| target: | |
| entity_id: !input light_entity | |
| - repeat: | |
| sequence: | |
| - wait_for_trigger: | |
| - trigger: state | |
| entity_id: !input light_entity | |
| to: "off" | |
| - trigger: state | |
| entity_id: !input door_sensor | |
| from: "off" | |
| to: "on" | |
| timeout: !input on_duration | |
| # Keep looping only while the wake-up was the door re-opening. | |
| until: >- | |
| {{ wait.trigger is none | |
| or wait.trigger.entity_id == light_entity }} | |
| # Timed out: nobody intervened, turn it off. | |
| # Manually turned off: do nothing. | |
| - if: "{{ wait.trigger is none }}" | |
| then: | |
| - action: homeassistant.turn_off | |
| target: | |
| entity_id: !input light_entity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment