-
-
Save farmio/bc23cc2a1a81408751947309408ff164 to your computer and use it in GitHub Desktop.
blueprint: | |
name: KNX - relative dimming 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 controled. | |
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 | |
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: 4 | |
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: 20 | |
# 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 }}" | |
trigger_variables: | |
_switch_address: !input switch_address | |
_dimm_address: !input dimm_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 }}" | |
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 }}' |
Yeah, kelvin should be fine for Phillips Finance white
Updated to use knx.telegram
trigger released in HA 2024.6
@farmio This works absolutely perfectly, I can‘t thank you enough. Implementing this myself would have been hell.
I have a question though: how can I alter this to mimic the KNX behaviour „don‘t turn off through relative dimming“? I.e. when I dim down I want the light to stay at the lowest brightness instead of turning off. The Home Assistant UI also behaves this way.
@bob-lobster I think it depends on the target entity. Not every one turns off on brightness = 0 - or is configurable (like most KNX actuators).
If you can't set it in the target integration, try modifying line 134 to set an absolute brightness based on max(current_brightness - dimm_step, 1)
or something like that.
Thanks I changed it to
brightness: “max(state_attr('light.bed', 'brightness')-dimm_step, 2)“
With absolute brightness 1 they would be at 1 % and on in HA but the bulbs were off.
They are Hue bulbs via Skyconnect actually but I couldn‘t figure out how to change the behaviour there.
Hi,
thank you for this blueprint code.
It works great for me. I am using an MDT KNX Wall Switch with an HUE ceiling light.
I could set those paramters for my claims.
Is it possible to add one more slider for an inital value?
Right now i switch on and off on a plus and a minus button with a short tap and same with dimming the light, but with long taps.
I would like to switch on the light everytime to 100% by Default. Right now it turns on by default with the last value
Cheers
Christian
@CyberChris79 Hi 👋! IMO turn on value should be handled by the actuator - most provide configurations for that.
The intention of this blueprint is to provide a reference for the usage of Knx actions and triggers - for other blueprint creators. So I don't plan to add any features to it.
Feel free to fork it and modify to your needs.
Or have a look for existing forks - maybe the thing you are looking was already done by someone else.
Depends on the actuator, I guess. The ones I know support DPT 3 color temp dimming, just like brightness.
And HA supports Kelvin too, so no need to deal with Mireds afaic.