Last active
September 7, 2026 17:30
-
-
Save csrui/b03157f7b778be18cb8e477317951a26 to your computer and use it in GitHub Desktop.
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: Presence and illuminance controlled lighting | |
| description: >- | |
| Turns on selected lights or switches when presence is detected and | |
| illuminance is below the configured threshold. | |
| The automation only takes control when ALL selected entities are currently | |
| off. If any selected entity is already on, the automation assumes it was | |
| turned on manually and leaves it alone. | |
| Once the automation turns the entities on, it waits for presence to clear | |
| and optionally turns them off after the configured absence delay. | |
| It also reacts if illuminance drops below the threshold while presence is | |
| already detected. | |
| domain: automation | |
| input: | |
| illuminance_sensor: | |
| name: Illuminance sensor | |
| description: Sensor that reports the current light level in lux. | |
| selector: | |
| entity: | |
| filter: | |
| - domain: sensor | |
| device_class: illuminance | |
| presence_sensor: | |
| name: Presence sensor | |
| description: Binary sensor that is on while presence is detected. | |
| selector: | |
| entity: | |
| filter: | |
| - domain: binary_sensor | |
| light_entities: | |
| name: Lights or switches | |
| description: >- | |
| Lights or switches controlled by this automation. | |
| The automation will only activate if all of them are currently off. | |
| selector: | |
| entity: | |
| multiple: true | |
| filter: | |
| - domain: light | |
| - domain: switch | |
| lux_threshold: | |
| name: Illuminance threshold | |
| description: Lights may turn on when the measured level is below this value. | |
| default: 100 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 2000 | |
| step: 1 | |
| unit_of_measurement: lx | |
| mode: box | |
| turn_off_after_absence: | |
| name: Turn off after absence | |
| description: Turn the selected lights off after presence clears. | |
| default: true | |
| selector: | |
| boolean: | |
| absence_delay: | |
| name: Absence delay | |
| description: How long presence must remain clear before turning lights off. | |
| default: | |
| minutes: 2 | |
| selector: | |
| duration: | |
| mode: restart | |
| max_exceeded: silent | |
| variables: | |
| presence_entity: !input presence_sensor | |
| illuminance_entity: !input illuminance_sensor | |
| controlled_entities: !input light_entities | |
| turn_off_enabled: !input turn_off_after_absence | |
| threshold: !input lux_threshold | |
| triggers: | |
| # Presence appears | |
| - trigger: state | |
| entity_id: !input presence_sensor | |
| from: "off" | |
| to: "on" | |
| id: presence_detected | |
| # Room becomes dark while somebody may already be present | |
| - trigger: numeric_state | |
| entity_id: !input illuminance_sensor | |
| below: !input lux_threshold | |
| id: became_dark | |
| conditions: | |
| # Presence must currently exist. | |
| - condition: template | |
| value_template: > | |
| {{ is_state(presence_entity, 'on') }} | |
| # Lux must currently be below threshold. | |
| - condition: template | |
| value_template: > | |
| {{ states(illuminance_entity) | float(999999) < threshold | float }} | |
| # IMPORTANT: | |
| # Only take control if ALL selected devices are currently off. | |
| - condition: template | |
| value_template: > | |
| {{ expand(controlled_entities) | |
| | selectattr('state', 'eq', 'off') | |
| | list | |
| | count | |
| == controlled_entities | count }} | |
| actions: | |
| # We now know that every target was off before the automation acted. | |
| - action: homeassistant.turn_on | |
| target: | |
| entity_id: !input light_entities | |
| # If automatic switch-off is disabled, finish here. | |
| - if: | |
| - condition: template | |
| value_template: "{{ turn_off_enabled }}" | |
| then: | |
| # Keep THIS automation run alive until absence has lasted | |
| # for the configured amount of time. | |
| - wait_for_trigger: | |
| - trigger: state | |
| entity_id: !input presence_sensor | |
| from: "on" | |
| to: "off" | |
| for: !input absence_delay | |
| # Because this run only exists when the automation itself | |
| # switched the entities on, it is safe to switch them off. | |
| - action: homeassistant.turn_off | |
| target: | |
| entity_id: !input light_entities |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment