Skip to content

Instantly share code, notes, and snippets.

@ignacio82
Last active August 2, 2022 17:12
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 ignacio82/d1e3ae98ad35182e6d974e2ac4801e5c to your computer and use it in GitHub Desktop.
Save ignacio82/d1e3ae98ad35182e6d974e2ac4801e5c to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Motion Smart Dimmer V1.0
blueprint:
name: Motion Smart Light Dimmer V1.0
description: |
Version 1.0
Dim or turn off light based on the value of a light sensor
source_url: https://gist.github.com/ignacio82/d1e3ae98ad35182e6d974e2ac4801e5c/edit
domain: automation
input:
schedule_start:
name: Schedule start time
description: Automation only runs after this time.
selector:
time:
schedule_stop:
name: Schedule stop time
description: Automation does not run after this time.
selector:
time:
schedule_days:
name: Run on these days
description: |
Days on which the automation will run.
Write days in short form, seperated by punctuation marks and/or spaces.
(i.e.: mon, tue, wed,...)
selector:
text:
light_sensor_entity:
name: Light Sensor
selector:
entity:
domain: sensor
device_class: illuminance
motion_entity:
name: Motion Sensor
description: Motion Sensor or a group with Motion Sensors (But can be anything switching between "on" and "off")
selector:
entity:
max_brightness_value:
name: Maximum ambient light value
description: Light is turned off above this value.
default: 500
selector:
number:
min: 0
max: 1000
step: 10
unit_of_measurement: lx
mode: slider
min_brightness_value:
name: Minimum ambient light value
description: The light does not change brightness further under this value.
default: 0
selector:
number:
min: 0
max: 1000
step: 10
unit_of_measurement: lx
mode: slider
light_value_1:
name: Dimming value 1
description: Brightness of the light at maximum ambient light.
default: 0
selector:
number:
min: 0
max: 100
step: 1
mode: slider
unit_of_measurement: '%'
light_value_2:
name: Dimming value 2
description: Brightness of the light at minimum ambient light.
default: 100
selector:
number:
min: 0
max: 100
step: 1
mode: slider
unit_of_measurement: '%'
target_light:
name: Target lights
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
mode: restart
max_exceeded: silent
variables:
light_sensor: !input light_sensor_entity
maxB: !input max_brightness_value
minB: !input min_brightness_value
light1: !input light_value_1
light2: !input light_value_2
slope: "{{ ( light1 - light2 ) / ( maxB - minB ) }}"
constant: "{{ light1 - ( slope * maxB ) }}"
days: !input schedule_days
motion_entity: !input motion_entity
trigger:
- platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
- platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
for: !input no_motion_wait
condition:
- condition: numeric_state
entity_id: !input light_sensor_entity
above: !input min_brightness_value
- condition: time
after: !input schedule_start
before: !input schedule_stop
- condition: template
value_template: "{{ now().strftime('%a') | lower in days }}"
action:
- choose:
# Trigger to state == "on"
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'on' }}"
- service: light.turn_on
data:
brightness_pct: >
{% if states(light_sensor)|int > maxB %}
0
{% else %}
{{ (( slope * states(light_sensor)|int ) + constant)|round }}
{% endif %}
target: !input target_light
# Trigger to state = "off"
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'off' }}"
- service: light.turn_off
target: !input target_light
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment