Last active
November 13, 2022 13:31
-
-
Save QNimbus/db3b5be1bf9cf902df137d00acddde1c 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 metadata | |
blueprint: | |
name: Motion activated area light | |
description: | | |
Use one or more sensors to trigger a dimmable area light. Manual operation of the light will (temporarily) disable the automation. | |
Required entities: | |
- Sensor(s) | |
- Light entity | |
GitHub: [Click Here](https://gist.github.com/QNimbus/db3b5be1bf9cf902df137d00acddde1c) | |
ℹ️ Version 2022.11.2 | |
domain: automation | |
source_url: https://gist.github.com/QNimbus/db3b5be1bf9cf902df137d00acddde1c | |
input: | |
trigger_sensors: | |
name: Sensor(s) | |
description: Sensor entities that will trigger the light | |
selector: | |
entity: | |
multiple: true | |
domain: binary_sensor | |
area_light: | |
name: Light | |
description: Area light | |
selector: | |
entity: | |
multiple: false | |
domain: light | |
schedule_time_entity_on: | |
name: "Start time entity" | |
description: |- | |
The **input_datetime** entity to determine when the automation becomes active. | |
selector: | |
entity: | |
multiple: false | |
domain: input_datetime | |
schedule_time_entity_off: | |
name: "End time entity" | |
description: |- | |
The **input_datetime** entity to determine when the automation becomes inactive. | |
selector: | |
entity: | |
multiple: false | |
domain: input_datetime | |
light_target: | |
name: Light intensity | |
description: |- | |
Light intensity for dimmable lights | |
_Default is 50%_ | |
default: 50 | |
selector: | |
number: | |
min: 1 | |
max: 100 | |
mode: slider | |
unit_of_measurement: "%" | |
light_on_duration: | |
name: "Lights on duration" | |
description: |- | |
Time duration to keep lights on after last motion was detected. | |
_Default is 2 minutes_ | |
default: 2 | |
selector: | |
number: | |
min: 0.5 | |
max: 59.5 | |
step: 0.5 | |
unit_of_measurement: minutes | |
delay_duration: | |
name: Inactive after override | |
description: |- | |
Delay re-enabling automation after manual operation of light. | |
_Default is 5 minutes_ | |
default: 5 | |
selector: | |
number: | |
min: 0.5 | |
max: 59.5 | |
step: 0.5 | |
unit_of_measurement: minutes | |
trigger_variables: | |
light_target: !input light_target | |
area_light: !input area_light | |
variables: | |
automation_name: "{{ this.entity_id }}" | |
first_run: "{{ this.attributes.current == 0 }}" | |
area_light: !input area_light | |
delay_duration: !input delay_duration | |
light_on_duration: !input light_on_duration | |
schedule_time_entity_on: !input schedule_time_entity_on | |
schedule_time_entity_off: !input schedule_time_entity_off | |
# Automation schema | |
mode: parallel | |
trigger: | |
# One or more sensors tripped | |
- platform: state | |
alias: "Trigger: sensor(s)" | |
id: motion_sensor_tripped | |
entity_id: !input trigger_sensors | |
from: "off" | |
to: "on" | |
# Brightness of area light was manually changed during automation run | |
- platform: numeric_state | |
alias: "Trigger: manual override" | |
id: manual_override | |
entity_id: !input area_light | |
attribute: brightness | |
value_template: |- | |
{% set val = state.attributes.brightness %} | |
{{ 1 if val and (val - light_target)|abs > 1 else 0 }} | |
above: 0 | |
# For debugging purposes | |
# Example: curl -X POST -d '{ "key": "value" }' http://homeassistant.local:8123/api/webhook/-debug-somTbR1Rvkk36rta7t8oLz_2 | |
- platform: webhook | |
alias: "Trigger: debug" | |
id: debug_trigger | |
enabled: false | |
webhook_id: "-debug-somTbR1Rvkk36rta7t8oLz_2" | |
condition: [] | |
action: | |
- choose: | |
# Debug trigger | |
- conditions: | |
- condition: trigger | |
id: debug_trigger | |
sequence: [] | |
# If light intensity of dimmer has changed | |
- conditions: | |
- condition: trigger | |
id: manual_override | |
- condition: state | |
entity_id: !input area_light | |
state: "on" | |
sequence: | |
- service: automation.turn_off | |
data: | |
stop_actions: false | |
target: | |
entity_id: "{{ automation_name }}" | |
- wait_for_trigger: | |
- platform: state | |
entity_id: | |
- !input area_light | |
to: "off" | |
continue_on_timeout: false | |
- delay: | |
minutes: !input delay_duration | |
- service: automation.turn_on | |
data: {} | |
target: | |
entity_id: "{{ automation_name }}" | |
# If motion sensor tripped | |
- conditions: | |
- condition: trigger | |
id: motion_sensor_tripped | |
alias: If motion sensor tripped | |
- condition: state | |
entity_id: !input area_light | |
state: "off" | |
- condition: time | |
after: !input schedule_time_entity_on | |
before: !input schedule_time_entity_off | |
sequence: | |
- service: light.turn_on | |
data: | |
brightness: !input light_target | |
target: | |
entity_id: !input area_light | |
- wait_for_trigger: | |
- platform: template | |
value_template: |- | |
{{ states(automation_name) == "off" }} | |
- platform: state | |
entity_id: !input area_light | |
from: "on" | |
to: "off" | |
- platform: state | |
entity_id: !input trigger_sensors | |
from: "on" | |
to: "off" | |
for: | |
minutes: !input light_on_duration | |
continue_on_timeout: false | |
- choose: | |
- conditions: | |
- condition: state | |
entity_id: !input area_light | |
state: "off" | |
sequence: | |
- service: automation.turn_off | |
data: | |
stop_actions: false | |
target: | |
entity_id: "{{ automation_name }}" | |
- delay: | |
minutes: !input delay_duration | |
- service: automation.turn_on | |
data: {} | |
target: | |
entity_id: "{{ automation_name }}" | |
- conditions: | |
- condition: template | |
value_template: |- | |
{{ states(automation_name) == "on" }} | |
sequence: | |
- service: light.turn_off | |
data: {} | |
target: | |
entity_id: !input area_light | |
default: [] | |
default: [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment