- Create motion-light-control.yaml blueprint for motion-activated lighting - Includes configurable quiet hours to prevent activation during night - Supports multiple lights with brightness and transition controls - Add CLAUDE.md documentation for repository guidance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
183 lines
5.4 KiB
YAML
183 lines
5.4 KiB
YAML
blueprint:
|
|
name: Motion-Activated Light Control
|
|
description: >
|
|
Turns lights on when motion is detected and keeps them on for a specified duration
|
|
after motion stops. Includes an optional quiet hours period where lights will not
|
|
turn on automatically (but can still be controlled manually).
|
|
|
|
Features:
|
|
- Multiple light support
|
|
- Configurable timeout after motion stops
|
|
- Optional quiet hours (e.g., nighttime) when lights won't turn on
|
|
- Brightness control during activation
|
|
- Option to only activate when lights are currently off
|
|
domain: automation
|
|
input:
|
|
motion_sensor:
|
|
name: Motion Sensor
|
|
description: The motion sensor that will trigger the lights
|
|
selector:
|
|
entity:
|
|
domain: binary_sensor
|
|
device_class:
|
|
- motion
|
|
- occupancy
|
|
target_lights:
|
|
name: Lights to Control
|
|
description: The light(s) to turn on when motion is detected
|
|
selector:
|
|
target:
|
|
entity:
|
|
domain: light
|
|
no_motion_duration:
|
|
name: No Motion Duration
|
|
description: How long to wait after motion stops before turning lights off
|
|
default: 300
|
|
selector:
|
|
number:
|
|
min: 10
|
|
max: 3600
|
|
unit_of_measurement: seconds
|
|
mode: slider
|
|
brightness_pct:
|
|
name: Brightness Percentage
|
|
description: Brightness level when turning on lights (0-100%)
|
|
default: 100
|
|
selector:
|
|
number:
|
|
min: 1
|
|
max: 100
|
|
unit_of_measurement: "%"
|
|
mode: slider
|
|
enable_quiet_hours:
|
|
name: Enable Quiet Hours
|
|
description: Enable a period where lights won't turn on automatically
|
|
default: false
|
|
selector:
|
|
boolean:
|
|
quiet_hours_start:
|
|
name: Quiet Hours Start Time
|
|
description: Start of quiet hours (lights won't turn on during this period)
|
|
default: "22:00:00"
|
|
selector:
|
|
time:
|
|
quiet_hours_end:
|
|
name: Quiet Hours End Time
|
|
description: End of quiet hours
|
|
default: "06:00:00"
|
|
selector:
|
|
time:
|
|
only_when_off:
|
|
name: Only Activate When Lights Are Off
|
|
description: Only turn on lights if they are currently off (prevents interference with manual control)
|
|
default: true
|
|
selector:
|
|
boolean:
|
|
transition_time:
|
|
name: Transition Time
|
|
description: Transition time in seconds when turning lights on or off
|
|
default: 1
|
|
selector:
|
|
number:
|
|
min: 0
|
|
max: 10
|
|
unit_of_measurement: seconds
|
|
mode: slider
|
|
|
|
mode: restart
|
|
max_exceeded: silent
|
|
|
|
variables:
|
|
quiet_hours_enabled: !input enable_quiet_hours
|
|
quiet_start: !input quiet_hours_start
|
|
quiet_end: !input quiet_hours_end
|
|
only_if_off: !input only_when_off
|
|
brightness: !input brightness_pct
|
|
transition: !input transition_time
|
|
lights: !input target_lights
|
|
|
|
# Calculate if we're currently in quiet hours
|
|
in_quiet_hours: >
|
|
{% if quiet_hours_enabled %}
|
|
{% set current_time = now().strftime('%H:%M:%S') %}
|
|
{% if quiet_start < quiet_end %}
|
|
{{ quiet_start <= current_time < quiet_end }}
|
|
{% else %}
|
|
{{ current_time >= quiet_start or current_time < quiet_end }}
|
|
{% endif %}
|
|
{% else %}
|
|
false
|
|
{% endif %}
|
|
|
|
# Check if any target lights are currently on
|
|
any_lights_on: >
|
|
{% set light_entities = [] %}
|
|
{% if lights.entity_id is defined %}
|
|
{% if lights.entity_id is string %}
|
|
{% set light_entities = [lights.entity_id] %}
|
|
{% else %}
|
|
{% set light_entities = lights.entity_id %}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% if lights.device_id is defined %}
|
|
{% for device in lights.device_id %}
|
|
{% set light_entities = light_entities + device_entities(device) | select('match', 'light.*') | list %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% if lights.area_id is defined %}
|
|
{% for area in lights.area_id %}
|
|
{% set light_entities = light_entities + area_entities(area) | select('match', 'light.*') | list %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% for entity in light_entities %}
|
|
{% if states(entity) == 'on' %}
|
|
true
|
|
{% endif %}
|
|
{% else %}
|
|
false
|
|
{% endfor %}
|
|
|
|
trigger:
|
|
- platform: state
|
|
entity_id: !input motion_sensor
|
|
to: "on"
|
|
id: motion_detected
|
|
- platform: state
|
|
entity_id: !input motion_sensor
|
|
to: "off"
|
|
for:
|
|
seconds: !input no_motion_duration
|
|
id: motion_stopped
|
|
|
|
condition: []
|
|
|
|
action:
|
|
- choose:
|
|
# Motion detected - turn on lights if conditions are met
|
|
- conditions:
|
|
- condition: trigger
|
|
id: motion_detected
|
|
- condition: template
|
|
value_template: "{{ not in_quiet_hours }}"
|
|
- condition: or
|
|
conditions:
|
|
- condition: template
|
|
value_template: "{{ not only_if_off }}"
|
|
- condition: template
|
|
value_template: "{{ not any_lights_on }}"
|
|
sequence:
|
|
- service: light.turn_on
|
|
target: !input target_lights
|
|
data:
|
|
brightness_pct: "{{ brightness }}"
|
|
transition: "{{ transition }}"
|
|
|
|
# Motion stopped for duration - turn off lights
|
|
- conditions:
|
|
- condition: trigger
|
|
id: motion_stopped
|
|
sequence:
|
|
- service: light.turn_off
|
|
target: !input target_lights
|
|
data:
|
|
transition: "{{ transition }}" |