Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Home Assistant Blueprint: Smart Dimmer V2.0
blueprint:
name: Smart Light Dimmer V2.0
description: |
Version 2.0
Dim or turn off light based on the value of a light sensor
source_url: https://gist.github.com/Twanne/45868f53efb65bbd998d8aed2dca0f76
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
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
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 ) }}"
days: !input schedule_days
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: template
value_template: "{{ now().strftime('%a') | lower in days }}"
action:
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment