KNX - relative dimming for lights

Tags: #<Tag:0x00007fc40d0345e8> #<Tag:0x00007fc40d034278> #<Tag:0x00007fc40d0340e8>

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

mode: restart
max_exceeded: silent

variables:
  target_lights: !input target_lights
  entity_list: >-
    {%- if target_lights.entity_id is string -%}
      {{ [target_lights.entity_id] }}
    {%- else -%}
      {{ target_lights.entity_id }}
    {%- endif -%}
  switch_address: !input switch_address
  dimm_address: !input dimm_address
  _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
  - platform: event
    event_type: automation_reloaded
  - platform: event
    event_type: knx_event
    event_data:
      destination: !input switch_address
  - platform: event
    event_type: knx_event
    event_data:
      destination: !input dimm_address

action:
  - choose:
    - conditions:
        - condition: template
          value_template: '{{ trigger is defined and trigger.platform == "event" and trigger.event.event_type == "knx_event" }}'
      sequence:
        - choose:
          # TURN ON
          - conditions:
              - condition: template
                value_template: "{{ trigger.event.data.destination == switch_address and trigger.event.data.data == 1 }}"
            sequence:
              - service: light.turn_on
                data:
                  entity_id: "{{ entity_list }}"
          # TURN OFF
          - conditions:
              - condition: template
                value_template: "{{ trigger.event.data.destination == switch_address and trigger.event.data.data == 0 }}"
            sequence:
              - service: light.turn_off
                data:
                  entity_id: "{{ entity_list }}"
          # DIMM UP
          - conditions:
              - condition: template
                value_template: >- 
                  {{ trigger.event.data.destination == dimm_address 
                    and (9 <= trigger.event.data.data <= 15) }}
            sequence:
              - repeat:
                  count: '{{ dimm_steps }}'
                  sequence:
                    - service: light.turn_on
                      data:
                        brightness_step: '{{ dimm_step }}'
                        entity_id: "{{ entity_list }}"
                    - delay:
                        milliseconds: '{{ dimm_delay }}'
          # DIMM DOWN
          - conditions:
              - condition: template
                value_template: >-
                  {{ trigger.event.data.destination == dimm_address 
                    and (1 <= trigger.event.data.data <= 7) }}
            sequence:
              - repeat:
                  count: '{{ dimm_steps }}'
                  sequence:
                    - service: light.turn_on
                      data:
                        brightness_step: '{{ -dimm_step }}'
                        entity_id: "{{ entity_list }}"
                    - delay:
                        milliseconds: '{{ dimm_delay }}'
    # INITIALIZE
    - conditions:
        condition: or
        conditions:
        - condition: template
          value_template: "{{ trigger is not defined }}"
        - condition: template
          value_template: '{{ trigger.platform == "homeassistant" }}'
        - condition: template
          value_template: '{{ trigger.platform == "event" and trigger.event.event_type == "automation_reloaded" }}'
      sequence:
        - service: knx.event_register
          data:
            address: '{{ switch_address }}'
        - service: knx.event_register
          data:
            address: '{{ dimm_address }}'
3 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. https://gist.github.com/farmio/bc23cc2a1a81408751947309408ff164

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.