Last active
October 2, 2023 19:59
-
-
Save robsonke/73f7c683ac6f87a7e9e5fe67f2f7e660 to your computer and use it in GitHub Desktop.
Based on https://gist.github.com/Danielbook/ad8dacabb8dc01e7cf062cbd8c1a00ed but with different brightness values for day and night and support for multiple motion sensors
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 with illuminance, nightmode and dimmable | |
description: Turn on a light when motion is detected and illuminance is below a | |
set Lux level. The light will dim before it is turned off to signal that it has | |
not detected motion in quite a while. There is also two timers, on for daytime | |
and one for nighttime. | |
domain: automation | |
input: | |
motion_entity: | |
name: Motion Sensor | |
selector: | |
entity: | |
domain: | |
- binary_sensor | |
device_class: | |
- motion | |
multiple: true | |
lux_entity: | |
name: Illuminance Sensor | |
selector: | |
entity: | |
domain: | |
- sensor | |
device_class: | |
- illuminance | |
multiple: false | |
lux_level: | |
name: Illuminance level | |
description: If lux is below this value and motion is detected, the light will | |
turn on. | |
default: 100 | |
selector: | |
number: | |
min: 0.0 | |
max: 1000.0 | |
step: 1.0 | |
mode: slider | |
light_target: | |
name: Light | |
selector: | |
target: | |
entity: | |
- domain: | |
- light | |
dim_time: | |
name: Dim light | |
description: The light will start dim this many seconds before it is turned | |
off if no motion has been detected to signal that the light will soon turn | |
off. | |
default: 30 | |
selector: | |
number: | |
min: 0.0 | |
max: 120.0 | |
unit_of_measurement: seconds | |
step: 1.0 | |
mode: slider | |
no_motion_wait_day: | |
name: Wait time (day) | |
description: Time to leave the light on after last motion is detected during | |
the day. | |
default: 300 | |
selector: | |
number: | |
min: 0.0 | |
max: 600.0 | |
unit_of_measurement: seconds | |
step: 1.0 | |
mode: slider | |
no_motion_wait_night: | |
name: Wait time (night) | |
description: Time to leave the light on after last motion is detected during | |
the night. | |
default: 120 | |
selector: | |
number: | |
min: 0.0 | |
max: 600.0 | |
unit_of_measurement: seconds | |
step: 1.0 | |
mode: slider | |
night_time_start_helper: | |
name: Night time helper (Start) | |
description: When should it be considered night time? | |
default: '19:00:00' | |
selector: | |
time: {} | |
night_time_end_helper: | |
name: Night time helper (End) | |
description: When should it be considered day time? | |
default: 08:00:00 | |
selector: | |
time: {} | |
sleep_time_start_helper: | |
name: Sleep time helper (Start) | |
description: From when do we want to keep the lights off and let the kids sleep? | |
default: '23:30:00' | |
selector: | |
time: {} | |
sleep_time_end_helper: | |
name: Sleep time helper (End) | |
description: Till when do we want to keep the lights off and let the kids sleep? | |
default: 06:00:00 | |
selector: | |
time: {} | |
day_brightness: | |
name: Day brightness | |
description: Brightness, in daytime mode | |
default: 100 | |
selector: | |
number: | |
min: 1.0 | |
max: 100.0 | |
step: 1.0 | |
mode: slider | |
night_brightness: | |
name: Night brightness | |
description: Brightness, in night mode | |
default: 20 | |
selector: | |
number: | |
min: 1.0 | |
max: 100.0 | |
step: 1.0 | |
mode: slider | |
source_url: https://gist.github.com/robsonke/73f7c683ac6f87a7e9e5fe67f2f7e660 | |
mode: restart | |
max_exceeded: silent | |
variables: | |
local_night_end: !input night_time_end_helper | |
local_night_start: !input night_time_start_helper | |
local_sleep_start: !input sleep_time_start_helper | |
local_sleep_end: !input sleep_time_end_helper | |
local_motion_delay_day: !input no_motion_wait_day | |
local_motion_delay_night: !input no_motion_wait_night | |
local_motion_dim_time: !input dim_time | |
local_day_brightness: !input day_brightness | |
local_night_brightness: !input night_brightness | |
local_current_brightness: >- | |
{% if today_at(local_night_end) < now() and now() < today_at(local_night_start) %} | |
{{ local_day_brightness }} | |
{% else %} {{ local_night_brightness }} {% endif %} | |
trigger: | |
platform: state | |
entity_id: !input motion_entity | |
from: 'off' | |
to: 'on' | |
condition: | |
- condition: numeric_state | |
entity_id: !input lux_entity | |
below: !input lux_level | |
- condition: template | |
value_template: > | |
{{ today_at(local_sleep_end) < now() and now() < today_at(local_sleep_start) }} | |
action: | |
- service: light.turn_on | |
target: !input light_target | |
data: | |
brightness_pct: '{{ local_current_brightness }}' | |
- wait_for_trigger: | |
platform: state | |
entity_id: !input motion_entity | |
from: 'on' | |
- delay: ' {% if today_at(local_night_end) < now() and now() < today_at(local_night_start) %} | |
{{ local_motion_delay_day - local_motion_dim_time }} | |
{% else %} {{ local_motion_delay_night - local_motion_dim_time }} {% endif %} ' | |
- service: light.turn_off | |
target: !input light_target | |
data: | |
transition: !input dim_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment