Skip to content

Instantly share code, notes, and snippets.

@mikebirdgeneau
Last active March 21, 2022 14:33
Show Gist options
  • Save mikebirdgeneau/70fc7aa307a17a34bc7eb92e158c2128 to your computer and use it in GitHub Desktop.
Save mikebirdgeneau/70fc7aa307a17a34bc7eb92e158c2128 to your computer and use it in GitHub Desktop.
HomeAssistant Dynamic Lighting Blueprint
blueprint:
name: Smart light dimmer w motion
description: |
Version 0.1
Dim or turn off light based on the value of a light sensor & motion
source_url: https://gist.github.com/mikebirdgeneau/70fc7aa307a17a34bc7eb92e158c2128
domain: automation
input:
light_sensor_entity:
name: Light Sensor
selector:
entity:
domain: sensor
device_class: illuminance
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: 255
step: 1
mode: slider
light_value_2:
name: Dimming value 2
description: Brightness of the light at minimum ambient light.
default: 255
selector:
number:
min: 0
max: 255
step: 1
mode: slider
target_light:
name: Target light
selector:
target:
entity:
domain: light
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:
motion_sensor:
name: Motion Sensor
description: Motion Sensor used to activate room lighting
selector:
target:
entity:
domain: sensor
device_class: motion
no_motion_duration:
name: No Activity Minutes
description: How many minutes should the lighting remain activated without motion.
selector:
number:
min: 0
max: 1440
step: 1
mode: single
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 ) }}"
trigger:
platform: state
entity_id: !input light_sensor_entity
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: state
entity_id: !input motion_sensor
state: 'off'
for:
minutes: !input no_motion_duration
action:
- service: light.turn_on
data:
brightness: >
{% if states(light_sensor)|int > maxB %}
0
{% else %}
{{ (( slope * states(light_sensor)|int ) + constant)|round }}
{% endif %}
target: !input target_light
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment