Skip to content

Instantly share code, notes, and snippets.

@JohNan
Last active January 17, 2022 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohNan/ea8e966c8f7be369fd191a781d1902ca to your computer and use it in GitHub Desktop.
Save JohNan/ea8e966c8f7be369fd191a781d1902ca to your computer and use it in GitHub Desktop.
Motion-activated light with brightness level
blueprint:
name: Motion-activated Light with brightness level
description: Turn on a light when motion is detected with a certain brightness level
domain: automation
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
light_target:
name: Light
selector:
target:
entity:
domain: light
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
time_before:
name: Time Before
description: Before this time the brightness level before will be used
default: '19:00:00'
selector:
time: {}
time_after:
name: Time After
description: After this time the brightness level after will be used
default: 08:00:00
selector:
time: {}
brightness_level_before_time:
name: Brightness level before time
description: Brightness level before a certain time
default: 100
selector:
number:
min: 5
max: 100
mode: slider
step: 5
unit_of_measurement: "%"
brightness_level_after_time:
name: Brightness level after time
description: Brightness level after a certain time
default: 25
selector:
number:
min: 5
max: 100
mode: slider
step: 5
unit_of_measurement: "%"
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
variables:
before_time: !input 'time_before'
after_time: !input 'time_after'
trigger:
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
action:
- alias: "Turn on the light"
service: light.turn_on
target: !input light_target
data:
transition: 1
brightness_pct: >
{% if ('sun.sun', 'above_horizon') and now().hour >= today_at(after_time).hour and now().hour < today_at(before_time).hour
%}
!input brightness_level_before_time
{% else %}
!input brightness_level_after_time
{% endif %}
- alias: "Wait until there is no motion from device"
wait_for_trigger:
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
- alias: "Wait the number of seconds that has been set"
delay: !input no_motion_wait
- alias: "Turn off the light"
service: light.turn_off
target: !input light_target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment