Edit: Updated 1-1-2022
Description:
Simple blueprint that accepts 2 binary sensor inputs to control a light.
Inputs:
Binary Sensor On - Binary sensor that is used to for turning On, and holding “On” state will increase brightness
Binary Sensor Off - Binary sensor that is used to for turning Off, and holding “On” state will decrease brightness
Hold threshold - Time to consider binary sensor input is being held, instead of just pushed.
Brightness step - Percentage brightness increase/decrease in each transition step.
Brightness step delay - Length of delay between each brightness step.
Default Brightness - Default brightness that light will turn on with.
Output:
Target Light - Whatever light you wish to control that can be dimmed via brightness.
blueprint:
name: Light controller
description: Turn a light On/Off/Up/Down based on binary sensor
domain: automation
input:
light_turn_on:
name: Binary Sensor On
description: This sensor is used to register turn On state
selector:
entity:
domain: binary_sensor
light_turn_off:
name: Binary Sensor Off
description: This sensor is used to register turn Off state
selector:
entity:
domain: binary_sensor
target_light:
name: Light
selector:
entity:
domain: light
hold_threshold:
name: Hold threshold
description: Time to consider binary sensor input is being held, instead of just pushed.
default: "0.8"
selector:
number:
min: "0.05"
max: "10"
step: "0.05"
unit_of_measurement: s
brightness_step_pct:
name: Brightness step
description: Percentage brightness increase/decrease in each transition step.
default: "10"
selector:
number:
min: "1"
max: "100"
unit_of_measurement: "%"
delay_steps:
name: Brightness step delay
description: Length of delay between each brightness step.
default: "0.3"
selector:
number:
min: "0"
max: "5"
step: "0.01"
unit_of_measurement: s
default_brightness:
name: Default Brightness
default: 190
selector:
number:
min: 1
max: 255
mode: slider
# Trigger when binary_sensor is changed from Off to On
trigger:
- platform: state
entity_id:
- !input light_turn_on
- !input light_turn_off
to: 'on'
condition: []
# Declare blueprint inputs as variables for use in {{templates}}
variables:
light_turn_on: !input light_turn_on
light_turn_off: !input light_turn_off
target_light: !input target_light
brightness_step_pct_positive: !input brightness_step_pct
brightness_step_pct_negative: "{{ brightness_step_pct_positive|int * -1 }}"
action:
- wait_for_trigger:
- platform: state
entity_id: !input light_turn_on
id: turn_on
to: "off"
from: "on"
- platform: state
entity_id: !input light_turn_off
id: turn_off
to: "off"
from: "on"
timeout: !input hold_threshold
continue_on_timeout: true
- choose:
- conditions:
- condition: template
value_template: '{{ wait.trigger.id == "turn_on" }}'
sequence:
- service: light.turn_on
entity_id: !input target_light
data:
brightness: !input default_brightness
- conditions:
- condition: template
value_template: '{{ wait.trigger.id == "turn_off" }}'
sequence:
- service: light.turn_off
entity_id: !input target_light
- conditions:
- condition: template
value_template: '{{ ( trigger.entity_id ) == ( light_turn_on ) and wait.trigger == none }}'
sequence:
repeat:
while:
- condition: state
entity_id: !input light_turn_on
state: "on"
sequence:
- service: light.turn_on
data:
brightness_step_pct: "{{ brightness_step_pct_positive }}"
entity_id: !input target_light
- delay:
seconds: !input delay_steps
- conditions:
- condition: template
value_template: '{{ ( trigger.entity_id ) == ( light_turn_off ) and wait.trigger == none }}'
sequence:
repeat:
while:
- condition: state
entity_id: !input light_turn_off
state: "on"
sequence:
- service: light.turn_on
data:
brightness_step_pct: "{{ brightness_step_pct_negative }}"
entity_id: !input target_light
- delay:
seconds: !input delay_steps
Extra IHC / LK information:
I use this automation with my ICH wireless 2 or 4-button wall switch.
How to setup binary sensor in configuration.yaml:
Hold CTRL down and the point on “Tryk (Øverst venstre)” and “Tryk (Øverst højre)”, to get ID numbers for your IHC setup in the configuration.yaml.