Forked from farmio/knx-relative-dimming-for-lights.yaml
Last active
December 16, 2024 16:25
-
-
Save Neffez/2b4919648fb8cb1608ee1805e67ceb0c to your computer and use it in GitHub Desktop.
KNX - relative dimming for lights blueprint
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: KNX - relative dimming and color temp for lights | |
description: Control Home Assistant light entities from KNX switching and relative dimming (DPT 3.007) telegrams. | |
homeassistant: | |
# `knx.telegram` trigger and `enabled` templates require Home Assistant 2024.6.0 | |
min_version: "2024.6.0" | |
domain: automation | |
input: | |
target_lights: | |
name: Light | |
description: The lights that shall be controlled. | |
selector: | |
target: | |
entity: | |
domain: light | |
switch_address: | |
name: Switch group address | |
description: > | |
Group address for switching the lights on and off. DPT 1 | |
Example: '1/2/3' | |
default: null | |
dimm_address: | |
name: Relative dimming address | |
description: > | |
Group address for dimming the lights. DPT 3.007 | |
Example: '1/2/4' | |
default: null | |
color_temp_address: | |
name: Relative color temp address | |
description: > | |
Group address for color temp. DPT 3.007 | |
Example: '1/2/4' | |
default: null | |
dimm_time: | |
name: Dimm time | |
description: Time dimming from 0 to 100% shall take. | |
selector: | |
number: | |
min: 1 | |
max: 20 | |
step: 0.1 | |
unit_of_measurement: seconds | |
mode: slider | |
default: 5 | |
dimm_steps: | |
name: Dimm steps | |
description: Steps used to dimm from 0 to 100%. | |
selector: | |
number: | |
min: 2 | |
max: 100 | |
step: 1 | |
unit_of_measurement: steps | |
mode: slider | |
default: 10 | |
color_temp_time: | |
name: Color temp time | |
description: Time changing color temp from 0 to 100% shall take. | |
selector: | |
number: | |
min: 1 | |
max: 20 | |
step: 0.1 | |
unit_of_measurement: seconds | |
mode: slider | |
default: 5 | |
color_temp_steps: | |
name: Color temp steps | |
description: Steps used to change color temp from 0 to 100%. | |
selector: | |
number: | |
min: 2 | |
max: 100 | |
step: 1 | |
unit_of_measurement: steps | |
mode: slider | |
default: 13 | |
color_temp_min: | |
name: Minimum color temp | |
description: The minimum color temp of the light | |
selector: | |
number: | |
min: 0 | |
max: 14000 | |
step: 50 | |
unit_of_measurement: kelvin | |
mode: slider | |
default: 2700 | |
color_temp_max: | |
name: Maximum color temp | |
description: The maximum color temp of the light | |
selector: | |
number: | |
min: 0 | |
max: 14000 | |
step: 50 | |
unit_of_measurement: kelvin | |
mode: slider | |
default: 4000 | |
# no matched condition stops repeat sequence to stop dimming (dimm 0) | |
mode: restart | |
max_exceeded: silent | |
variables: | |
_dimm_time: !input dimm_time | |
_dimm_steps: !input dimm_steps | |
dimm_time: "{{ _dimm_time|float }}" | |
dimm_steps: "{{ _dimm_steps|int }}" | |
dimm_step: "{{ (255 / dimm_steps) | round(0, 'ceil') }}" | |
dimm_delay: "{{ dimm_time * 1000 / dimm_steps }}" | |
_color_temp_min: !input color_temp_min | |
_color_temp_max: !input color_temp_max | |
color_temp_min: "{{ _color_temp_min|int }}" | |
color_temp_max: "{{ _color_temp_max|int }}" | |
_color_temp_time: !input color_temp_time | |
_color_temp_steps: !input color_temp_steps | |
color_temp_time: "{{ _color_temp_time|float }}" | |
color_temp_steps: "{{ _color_temp_steps|int }}" | |
color_temp_step: "{{ ((color_temp_max - color_temp_min) / color_temp_steps) | round(0, 'ceil') }}" | |
color_temp_delay: "{{ color_temp_time * 1000 / color_temp_steps }}" | |
_target_lights: !input target_lights | |
trigger_variables: | |
_switch_address: !input switch_address | |
_dimm_address: !input dimm_address | |
_color_temp_address: !input color_temp_address | |
trigger: | |
- platform: knx.telegram | |
destination: !input switch_address | |
group_value_read: false | |
group_value_response: false | |
id: "switch" | |
enabled: "{{ _switch_address != None }}" | |
- platform: knx.telegram | |
destination: !input dimm_address | |
group_value_read: false | |
group_value_response: false | |
id: "dimm" | |
enabled: "{{ _dimm_address != None }}" | |
- platform: knx.telegram | |
destination: !input color_temp_address | |
group_value_read: false | |
group_value_response: false | |
id: "color_temp" | |
enabled: "{{ _color_temp_address != None }}" | |
action: | |
- choose: | |
# TURN ON | |
- conditions: | |
condition: and | |
conditions: | |
- condition: trigger | |
id: "switch" | |
- "{{ trigger.payload == 1 }}" | |
sequence: | |
- service: light.turn_on | |
target: !input target_lights | |
# TURN OFF | |
- conditions: | |
condition: and | |
conditions: | |
- condition: trigger | |
id: "switch" | |
- "{{ trigger.payload == 0 }}" | |
sequence: | |
- service: light.turn_off | |
target: !input target_lights | |
# DIMM UP | |
- conditions: | |
condition: and | |
conditions: | |
- condition: trigger | |
id: "dimm" | |
- "{{ 9 <= trigger.payload <= 15 }}" | |
sequence: | |
- repeat: | |
count: '{{ dimm_steps }}' | |
sequence: | |
- service: light.turn_on | |
target: !input target_lights | |
data: | |
brightness_step: '{{ dimm_step }}' | |
- delay: | |
milliseconds: '{{ dimm_delay }}' | |
# DIMM DOWN | |
- conditions: | |
condition: and | |
conditions: | |
- condition: trigger | |
id: "dimm" | |
- "{{ 1 <= trigger.payload <= 7 }}" | |
sequence: | |
- repeat: | |
count: '{{ dimm_steps }}' | |
sequence: | |
- service: light.turn_on | |
target: !input target_lights | |
data: | |
brightness_step: '{{ -dimm_step }}' | |
- delay: | |
milliseconds: '{{ dimm_delay }}' | |
# COLOR TEMP UP | |
- conditions: | |
condition: and | |
conditions: | |
- condition: trigger | |
id: "color_temp" | |
- "{{ 9 <= trigger.payload <= 15 }}" | |
sequence: | |
- repeat: | |
count: '{{ color_temp_steps }}' | |
sequence: | |
- service: light.turn_on | |
target: !input target_lights | |
data: | |
kelvin: "{{ state_attr(_target_lights, 'color_temp_kelvin') + color_temp_step }}" | |
- delay: | |
milliseconds: '{{ color_temp_delay }}' | |
# COLOR TEMP DOWN | |
- conditions: | |
condition: and | |
conditions: | |
- condition: trigger | |
id: "color_temp" | |
- "{{ 1 <= trigger.payload <= 7 }}" | |
sequence: | |
- repeat: | |
count: '{{ color_temp_steps }}' | |
sequence: | |
- service: light.turn_on | |
target: !input target_lights | |
data: | |
kelvin: "{{ state_attr(_target_lights, 'color_temp_kelvin') - color_temp_step }}" | |
- delay: | |
milliseconds: '{{ color_temp_delay }}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment