KNX - relative dimming for lights

This is a blueprint for connecting KNX devices using relative dimming (DPT 3.007) with Home Assistant Light entities.

It requires:

  • Home Assistant Core 2021.2 or newer
  • a light entity supporting brightness
  • a working KNX integration (at least knx: in your configuration.yaml)

It should work right away after creation or restart of Home Assistant. If it doesn’t try the “Execute” button to initialize events.

blueprint:
  name: KNX - relative dimming for lights
  description: Controll Home Assistant Light entities from KNX switching and relative dimming (DPT 3.007) telegrams.
  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'
    dimm_address:
      name: Relative dimming address
      description: >
        Group address for dimming the lights. DPT 3.007
        Example: '1/2/4'
    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:
  - platform: homeassistant
    event: start
    id: "initialize"
  - platform: event
    event_type: automation_reloaded
    id: "initialize"
  # when KNX integration was reloaded
  - platform: event
    event_type: service_registered
    event_data:
      domain: knx
      service: event_register
    id: "initialize"
  - platform: event
    event_type: knx_event
    event_data:
      destination: !input switch_address
      telegramtype: GroupValueWrite
    id: "switch"
  - platform: event
    event_type: knx_event
    event_data:
      destination: !input dimm_address
      telegramtype: GroupValueWrite
    id: "dimm"

action:
  - choose:
    # TURN ON
    - conditions:
        condition: and
        conditions:
          - condition: trigger
            id: "switch"
          - "{{ trigger.event.data.data == 1 }}"
      sequence:
        - service: light.turn_on
          target: !input target_lights
    # TURN OFF
    - conditions:
        condition: and
        conditions:
          - condition: trigger
            id: "switch"
          - "{{ trigger.event.data.data == 0 }}"
      sequence:
        - service: light.turn_off
          target: !input target_lights
    # DIMM UP
    - conditions:
        condition: and
        conditions:
          - condition: trigger
            id: "dimm"
          - "{{ 9 <= trigger.event.data.data <= 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.event.data.data <= 7 }}"
      sequence:
        - repeat:
            count: '{{ dimm_steps }}'
            sequence:
              - service: light.turn_on
                target: !input target_lights
                data:
                  brightness_step: '{{ -dimm_step }}'
              - delay:
                  milliseconds: '{{ dimm_delay }}'
    # INITIALIZE
    - conditions:
        condition: trigger
        id: "initialize"
      sequence:
        - service: knx.event_register
          data:
            address: !input switch_address
        - service: knx.event_register
          data:
            address: !input dimm_address
7 Likes

Do you know when core-2021.2 will be available?
Currently I have core-2021.1.5

Tomorrow. Or currently on the beta/rc channel.

I tried from beta channel, looks like working, thanks

Hi Matthias,
I just tried your blueprint, which is a great idea but I have an issue, others might have this to.
I use Gira tastsensor 2 buttons, in the actual config they send value 12 for dimming up and value of 4 for dimming down.
In your template this is 9 and 1, maybe we can make this configurable ? Or is it something in my KNX config ?

    "event_type": "knx_event",
    "data": {
        "data": 12,
        "destination": "4/1/70",
        "direction": "Incoming",
        "source": "1.1.103",
        "telegramtype": "GroupValueWrite"
    },
    "origin": "LOCAL",
    "time_fired": "2021-02-06T09:20:25.713045+00:00",
    "context": {
        "id": "e18c4a5ae830c1a0a51f383b219a783b",
        "parent_id": null,
        "user_id": null
    }
}
1 Like

Can you look up (in the manual and in ETS) which DPT is used by your switch?
There are multiple ways to dimm in KNX. The blueprint is currently tailored for DPT 3.007

Maybe I can changeover to be more universal.

From what I found, my switches use 4 Bit relative dimming object (0-100%), from my understanding this is DPT3.007.
So I looked a bit further and found following in a document from ABB:

Relative dimming
Dimming according to the KNX standard (EIS2) takes place via this 4-bit communication object. Start-stop dimming or steptype dimming can be selected.
0 = Stop
1 = 100% dimming darker
2 = 50% dimming darker
3 = 25% dimming darker
4 = 12.5% dimming darker
5 = 6.25% dimming darker
6 = 3.2% dimming darker
7 = 1.6% dimming darker
8 = Stop
9 = 100% dimming brighter
10 = 50% dimming brighter
11 = 25% dimming brighter
12 = 12.5% dimming brighter
13 = 6.25% dimming brighter
14 = 3.2% dimming brighter
15 = 1.6% dimming brighter
Object, relative dimming
No.  Object name          Data type
1     Relative dimming    4 Bit EIS2 / DPT 3.007

So finally I looked into the knx parameters of my switch, and indeed, my dimstep is configured to 12,5% per step. So I suppose yours is at 100% ?

So the most simple solution for a universal blueprint without changing KNX parameters would be:

  • Dim up: 9-15
  • Dim down: 1-7
1 Like

I’ve updated it to accept different step codes. Step codes are not evaluated, only control bit.

And because editing here isn’t really fun I’ve also uploaded it to github. KNX - relative dimming for lights blueprint · GitHub

I can’t even change this setting for my switches ¯\(ツ)

2 Likes

Thanks for blueprint. My KNX setup is based Jung KNX hardware. Took me a while to realize my setup is using DTP 3.007 dimming. Updated to Home Assistant to core-2021.6.4, created automation using your blueprint for the first time and have the following results:

  1. Lights On - works as expected.
  2. Lights Off - turns off the light as expected, but then keeps repeating the cycle forever and jams the KNX bus with the same “OFF” command every 2-3 seconds. Used EMS to monitor activity on the bus. The only way to escape the situation is by stopping/reloading automation.
  3. Dim-up/down doesn’t work and for some reason produces the following data type error each time:

Logger: homeassistant.helpers.script
Source: helpers/script.py:650
First occurred: 5:50:03 PM (4 occurrences)
Last logged: 5:50:04 PM

Error in ‘choose[0]’ evaluation: In ‘template’ condition: TypeError: ‘<=’ not supported between instances of ‘int’ and ‘tuple’

Any thoughts what may have caused it?

Seems like the received payload for dimming is not a proper DPT 3.
Troubleshooting

my MDT switches seem to require that the brightness value for the dim-state is also set to 0 in order for the state to be displayed correctly on the switches. If the dim value is not 0 but the switch is off, it is still displayed as ON in my switches. Do you see a way to somehow add this to the blueprint?

This blueprint only handled communication from Knx to HA, not the other way.
Feel free to extend (and publish) a version that handles bidirektional communication - it’s definitively possible. Or just use Knx expose

I already use expose, but the brightness is not set to 0 by HA when the light is turned off

Have a look at the default Attribute - see documentation linked above.

I am already doing/using that, but the “MDT Glastaster II Smart” still does show the light as ON for some reason. But if you say it should send the default value when the light is off, I need to investigate further as to what’s wrong in my setup

edit: just monitored the group messages on the bus, and when the light is turned off, there is no group message for the brightness. When I turn it on and change the brightness, the messages are sent to the bus, so the config in general is working. Only when OFF, the telegram for the brightness is missing on my end. I am mapping Hue bulbs to KNX.

:thinking: maybe Xknx unneeded expose by mptei · Pull Request #48311 · home-assistant/core · GitHub broke that feature. We really need some tests around this integration…

I don’t see how this PR could affect this, as this PR only changes the behavior if no attribute is exposed. But let’s not hijack this thread any further with bug hunting. I’ll see what I can do in regards to extending the blueprint as a one-stop solution. I can create a github ticket for the expose issue if you want.

Hm maybe it was the wrong PR. There were some changes - that one was kind of the beginning of this.
Yes, please create an issue so we can track the fix for this.

Hi :wave:!
Small update for this.

Areas should work properly now.
The blueprint also keeps working when the KNX integration was reloaded.

Happy new year :tada:

1 Like

Hi @farmio,

Thanks for this blueprint!
I just made some modifications to be able to also send the state change of the light back to the KNX Bus.
Are you interested to add this too?