From a074d8284fcbe0004d8fb976da088a0cde311b54 Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 29 Aug 2025 20:12:44 +0000 Subject: [PATCH] =?UTF-8?q?blueprints/automation/motion-light.yaml=20hinzu?= =?UTF-8?q?gef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blueprints/automation/motion-light.yaml | 121 ++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 blueprints/automation/motion-light.yaml diff --git a/blueprints/automation/motion-light.yaml b/blueprints/automation/motion-light.yaml new file mode 100644 index 0000000..f15e0c1 --- /dev/null +++ b/blueprints/automation/motion-light.yaml @@ -0,0 +1,121 @@ +blueprint: + name: Motion-activated Light with Optional Lux + description: Turn on a light when motion is detected, optionally only if lux is below a threshold. + domain: automation + author: ChatGPT + input: + motion_entity: + name: Motion Sensor + selector: + entity: + filter: + - device_class: occupancy + domain: binary_sensor + - device_class: motion + domain: binary_sensor + light_target: + name: Light + selector: + target: + entity: + domain: light + lux_entity: + name: Lux Sensor (optional) + default: "" + selector: + entity: + domain: sensor + device_class: illuminance + lux_threshold: + name: Lux Threshold + description: Only turn on the light if lux is below this value. + default: 50 + selector: + number: + min: 0 + max: 1000 + unit_of_measurement: lx + no_motion_wait: + name: Wait time + description: Time to leave the light on after last motion is detected. + default: 120 + selector: + number: + min: 0 + max: 3600 + unit_of_measurement: seconds + +mode: restart +max_exceeded: silent + +trigger: + - platform: state + entity_id: !input motion_entity + from: "off" + to: "on" + +variables: + lux_entity_var: !input lux_entity + lux_threshold_var: !input lux_threshold + first_light: "{{ expand(!input light_target) | map(attribute='entity_id') | first }}" + supports_brightness: "{{ 'brightness' in state_attr(first_light, 'supported_color_modes') | default([]) }}" + +condition: + - alias: "Optional lux check" + condition: template + value_template: > + {% if lux_entity_var | length > 0 and states(lux_entity_var) not in ['unknown','unavailable','none',''] %} + {{ states(lux_entity_var) | float(0) < lux_threshold_var | float(0) }} + {% else %} + true + {% endif %} + +action: + - alias: "Set dynamic brightness" + variables: + max_brightness: 255 + sun_elevation: "{{ state_attr('sun.sun','elevation') | float(0) }}" + current_lux: > + {% if lux_entity_var | length > 0 %} + {{ states(lux_entity_var) | float(0) }} + {% else %} + 0 + {% endif %} + brightness: >- + {% set base = 50 %} + {% if sun_elevation > 10 %} + {% set base = 100 %} + {% elif sun_elevation > 0 %} + {% set base = 150 %} + {% else %} + {% set base = 200 %} + {% endif %} + {% if current_lux > 50 %} + {% set base = base - ((current_lux / 500) * base) | int %} + {% endif %} + {{ [base, max_brightness] | min }} + + - alias: "Turn on the light safely" + choose: + - conditions: "{{ supports_brightness }}" + sequence: + - service: light.turn_on + target: !input light_target + data: + brightness: "{{ brightness }}" + default: + - service: light.turn_on + target: !input light_target + + - alias: "Wait until no motion" + wait_for_trigger: + - platform: state + entity_id: !input motion_entity + from: "on" + to: "off" + + - delay: !input no_motion_wait + + - alias: "Turn off the light" + service: light.turn_off + target: !input light_target \ No newline at end of file