Last active
December 23, 2025 18:08
-
-
Save LasseSkogland/4bd83de0ea4645c35c8baacc56023e14 to your computer and use it in GitHub Desktop.
A simple motion sensor for lights, Home Assistant 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: Motion-Activated Light (Strictly Optional) | |
| description: > | |
| Turns on a light when motion is detected. Attributes are only sent | |
| if they are provided in the configuration. | |
| domain: automation | |
| input: | |
| motion_sensor: | |
| name: Motion Sensor | |
| selector: | |
| entity: | |
| domain: binary_sensor | |
| device_class: occupancy | |
| target_light: | |
| name: Light | |
| selector: | |
| target: | |
| entity: | |
| domain: light | |
| off_delay: | |
| name: Turn off delay | |
| default: 30 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 3600 | |
| unit_of_measurement: seconds | |
| brightness: | |
| name: Brightness (Optional) | |
| default: 0 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 100 | |
| unit_of_measurement: "%" | |
| color_temp: | |
| name: Color Temperature (Optional) | |
| default: 0 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 6500 | |
| unit_of_measurement: K | |
| on_transition: | |
| name: On Transition (Optional) | |
| default: 0 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 30 | |
| unit_of_measurement: seconds | |
| off_transition: | |
| name: Off Transition (Optional) | |
| default: 0 | |
| selector: | |
| number: | |
| min: 0 | |
| max: 30 | |
| unit_of_measurement: seconds | |
| mode: restart | |
| variables: | |
| brightness_val: !input brightness | |
| color_temp_val: !input color_temp | |
| on_tr_val: !input on_transition | |
| off_tr_val: !input off_transition | |
| trigger: | |
| - platform: state | |
| entity_id: !input motion_sensor | |
| to: "on" | |
| id: "on" | |
| - platform: state | |
| entity_id: !input motion_sensor | |
| to: "off" | |
| for: | |
| seconds: !input off_delay | |
| id: "off" | |
| action: | |
| - choose: | |
| - conditions: | |
| - condition: trigger | |
| id: "on" | |
| sequence: | |
| - action: light.turn_on | |
| target: !input target_light | |
| data: > | |
| {% set data = {} %} | |
| {% if brightness_val | int(0) > 0 %} | |
| {% set data = dict(data, brightness_pct=brightness_val | int) %} | |
| {% endif %} | |
| {% if color_temp_val | int(0) > 0 %} | |
| {# Fixed: kelvin is deprecated in favor of color_temp_kelvin #} | |
| {% set data = dict(data, color_temp_kelvin=color_temp_val | int) %} | |
| {% endif %} | |
| {% if on_tr_val | int(0) > 0 %} | |
| {% set data = dict(data, transition=on_tr_val | int) %} | |
| {% endif %} | |
| {{ data }} | |
| - conditions: | |
| - condition: trigger | |
| id: "off" | |
| sequence: | |
| - action: light.turn_off | |
| target: !input target_light | |
| data: > | |
| {% set data = {} %} | |
| {% if off_tr_val | int(0) > 0 %} | |
| {% set data = dict(data, transition=off_tr_val | int) %} | |
| {% endif %} | |
| {{ data }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment