Using KNX Wall Switch to Control Homeassistant

Hi!

I am having quite a hard integrating some new KNX components into my existing HomeAssistant Environment. I am using the really cool MDT BE-GT2Tx.01 Glastaster II Smart mit Temperatursensor.

What i am trying to accomplish is to

  • dim a (homematic) light in homeassistant using the KNX wall control
  • control (homematic) blinds in homeassistant using the KNX wall control
  • control a thermostat in homeassistant using the KNX wall control

For the light i am having some success by using “send values” instead of dimming on the KNX wall switch. That however is far away from great usability as switching on and off with a single push will not work together with dimming.

The problems that i am having with the “proper” dimmer configuration are:

  • KNX Dimmers seem to think in 0…100% whereas Homeassistant seems to think in 0 … 255. When i expose the 0…255 value as “percentage” it will not get adapted so 100 in KNX is not 100% in HA
  • KNX Dimmers control the dimming using 3.007 dim step datatype - I have only found how to control a KNX light from homeassistant - not the other way round
  • When using the “expose” feature of HomeAssistant values seem to be sent to the KNX bus but if I for instance expose the on/off state and send a change to it on the KNX bus homeassistant will not react to the change triggered by the wall switch - to circumvent this i have used automations but that looks really dirty an high error potential to me

I hope you can point me into the right direction on how to proceed with this integration. An example config would be really great if someone has that running :slight_smile:

Thanks + best regards

Michael

Hi :wave:

KNX uses 0…255 as well. “percentage” would be an invalid type for knx-expose - you can use “percent” if you have 0-100 values (even a string) or “percentU8” if you have 0-255 int values.
Same the other way around. If you get a raw payload from knx “100” it would not mean 100% - if you use a sensor with type “percent” you would get a 0-100 value.

There are some forum posts about using DPT3 and keeping state synced.
You may find some answers here: KNX Cookbook

1 Like

Hi!

Thanks for the reply - i also used the 5.004 Percentage (0.255) for the workaround which is not “nice” to use at the switch buttons. The MDT Glastaster seems to need 5.001 for the display when using it in proper dimming mode however. From the hint with DPT3 for the search however I figured that I could do that with a template sensor to do the maths from 255 to 100 as the value is only used for display anyways.

If I got the reading right, the solution for the DPT3 works around setting automations for each group address and the individual parameter values 09 “up”, 01 “down” and 00 “stop”. That would lead to having 3 automations per light I need to control and when dimming the lights to have several dozens of executions in the worst case. I’ll try to build that up now for a demo light but I still hope to find a more generic solution that does not rely on group addresses split across config files and automations. Also I am currently not sure how to implement the automation as the “dim” signal comes once only and the change needs to be performed multiple times until the user “stops” the dimming.

Thanks for the hint into the direction

best regards

Michael

Hi again!

The new automation possibilities allowed me to solve this in my demo setup. It features on/off, dim as well as hue change in a single automation.

Maybe this helps someone

My Automation:

alias: KNXTest2
description: ''
trigger:
  - platform: event
    event_type: knx_event
    event_data:
      address: 1/2/8
  - platform: event
    event_type: knx_event
    event_data:
      address: 1/1/10
  - platform: event
    event_type: knx_event
    event_data:
      address: 3/5/12
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{trigger.event.data.address=='1/2/8' and trigger.event.data.data
              == 9}}
        sequence:
          - repeat:
              count: '26'
              sequence:
                - service: light.turn_on
                  data:
                    brightness: >-
                      {{ [state_attr('light.esphomedemo1_led',
                      "brightness")|int(0) + 10, 255]|min }}
                  entity_id: light.esphomedemo1_led
                - delay: '00:00:00.5'
      - conditions:
          - condition: template
            value_template: >-
              {{trigger.event.data.address=='1/2/8' and trigger.event.data.data
              == 1}}
        sequence:
          - repeat:
              count: '26'
              sequence:
                - service: light.turn_on
                  data:
                    brightness: >-
                      {{ [state_attr('light.esphomedemo1_led',
                      "brightness")|int(0) - 10, 0]|max }}
                  entity_id: light.esphomedemo1_led
                - delay: '00:00:00.5'
      - conditions:
          - condition: template
            value_template: >-
              {{trigger.event.data.address=='1/1/10' and trigger.event.data.data
              == 1}}
        sequence:
          - service: light.turn_on
            data: {}
            entity_id: light.esphomedemo1_led
      - conditions:
          - condition: template
            value_template: >-
              {{trigger.event.data.address=='1/1/10' and trigger.event.data.data
              == 0}}
        sequence:
          - service: light.turn_off
            data: {}
            entity_id: light.esphomedemo1_led
      - conditions:
          - condition: template
            value_template: >-
              {{trigger.event.data.address=='3/5/12' and trigger.event.data.data
              == 1}}
        sequence:
          - repeat:
              count: '26'
              sequence:
                - service: light.turn_on
                  data:
                    hs_color: >-
                      {{ [ [state_attr('light.esphomedemo1_led',
                      "hs_color")[0]|int(0) - 10, 0]|max , 
                      state_attr('light.esphomedemo1_led',
                      "hs_color")[1]|int(0)]}}
                  entity_id: light.esphomedemo1_led
                - delay: '00:00:00.5'
      - conditions:
          - condition: template
            value_template: >-
              {{trigger.event.data.address=='3/5/12' and trigger.event.data.data
              == 9}}
        sequence:
          - repeat:
              count: '26'
              sequence:
                - service: light.turn_on
                  data:
                    hs_color: >-
                      {{ [ [state_attr('light.esphomedemo1_led',
                      "hs_color")[0]|int(0) + 10, 255]|min , 
                      state_attr('light.esphomedemo1_led',
                      "hs_color")[1]|int(0)]}}
                  entity_id: light.esphomedemo1_led
                - delay: '00:00:00.5'
    default: []
mode: restart

Group addresses:

Please do not comment on the address numbering - this is purely a dirty testboard setup :slight_smile:

best regards

Michael

1 Like

Great, thanks!
That was super helpful to control a shelly from KNX. I had to add the dimmer address to my configaration.yaml.

knx:
  fire_event: true
  fire_event_filter: ["6/1/24"]

And the group addresses for the dimmer in my knx_light.yaml with as well as in knx_switch.yaml. Maybe that is too much but it works now. Strangely it is enough to put only the dimmer address in fire_event_filter. I’m still new to this.

Regards,
David

Hi Michael,
I try to use my MDT glas push button to dim Hue lights (using conbee). Are you using one or two button dimming on the MDT button?
I use another approach to control my Sonos volume with a few scripts. In order to get it work, I also need to process event data 0 to stop dimming. But this is much more complex, so I would like to use your automation which is not working for me.

Hi!

I am using two button but it should be the same on one button style as well. Important for this to work is to use the “dimming” function and not “send values”.

as dcrabs already rightly mentioned it is important to add the dimming addresses to the fire_event_filter to make sure they trigger an event that can be handled by the automation.

Do you have any more hints what is not working for you?

Attached some screenshots of my configuration in ETS - i hope they help albeit being in German

best regards

Michael

Hi! As an automation noob I’m curious how this works.

I’d read it like this: when a telegram with payload “9” is received, set brightness to brightness +10 every 0,5sec → repeat 26 times.

  • why 26? Is this because HA brightness is 0-225?
  • when/why/how does it stop when you release the button?
  • Is a 0 Telegram sent for stop?

@ciko I have used wrong GA :roll_eyes:. Its working now, thank you so much. I am able to dim my Hue bulbs with my MDT glas puch button. Your approach is simple and easy to unterstand. My Sonos “dim” volume solution is much more complex as it uses 5 automations, 2 scripts and one input_boolean.

@farmio The MDT glas push button sends a 0 telegram to stop. This will restart and stop automation because condition to repeat is not true.

Edit: I did some changes to soft dim when turn on/off the lights. Its also possible to turn on / of the light by dimming.

- alias: KNX to Hue
  description: ""
  trigger:
    - platform: event
      event_type: knx_event
      event_data:
        address: 1/1/33 # switch ga, 1.001
    - platform: event
      event_type: knx_event
      event_data:
        address: 1/2/33 # dim step ga, 3.007
  condition: []
  action:
    - choose:
        - conditions: > # turn on
            {{ trigger.event.data.address=='1/1/33' and trigger.event.data.data == 1 }}
          sequence:
            - service: light.turn_on
              data:
                transition: 3
                brightness_pct: 100
              entity_id: light.hue_test
        - conditions: > # turn off
            {{ trigger.event.data.address=='1/1/33' and trigger.event.data.data == 0 }}
          sequence:
            - service: light.turn_off
              data:
                transition: 3
              entity_id: light.hue_test
        - conditions: > # dim up
            {{ trigger.event.data.address=='1/2/33' and trigger.event.data.data == 9 }}
          sequence:
            - repeat:
                count: "20"
                sequence:
                  - service: light.turn_on
                    data:
                      brightness_step_pct: 5
                    entity_id: light.hue_test
                  - delay: "00:00:00.25"
        - conditions: > # dim down
            {{ trigger.event.data.address=='1/2/33' and trigger.event.data.data == 1}}
          sequence:
            - repeat:
                count: "20"
                sequence:
                  - service: light.turn_on
                    data:
                      brightness_step_pct: -5
                    entity_id: light.hue_test
                  - delay: "00:00:00.25"
      default: []
  mode: restart

So I created a blueprint for this. Please be aware that HA 2021.2 is required for it to work (RC should be available today).

What is this service doing? Can’t find in docs…
knx.event_register

This is why it requires HA 2021.2 which will be released in RC probably later today (or you use current dev).

It registers an event for a group address. Its like configuring

knx:
  # previously called `fire_event_filter`
  event_filter: [<switch_address>, <dimm_address>] 

but without having to change configuration.

I’ve been waiting for this for some time, great to see this in the upcoming version! My idea was to use this for Sonos volume control, rather than setting the brightness of lights. Do you think this could work (after some minor modifications)?

Sure, why not. Just modify the target and the service calls.
PS: this works since ever. It’s just the blueprint and the Dynamic Event registration (initialization) that’s new.

Sorry for not reading carefully. Earlier @DessertBesom mentioned that this is way is much less complex than the previous idea to control the Sonos volume, which I also have been struggling with. I’m gonna try this as soon as possible.

I made the neccessary modifications for Sonos, I works nicely! Thanks!

very nice. You want to share it?

Sure, it’s quite simple, but works fine. The the first button is the on/off toggle plus the volume, the other button is the selector of the source. I’m gonna refine it by making dynamic grouping of Sonos players (I have a bunch :slight_smile:) based on the presence in each room. Grouping in Sonos is quite slow sometimes, it cannot follow presence in real-time, but it gives a feeling.

- alias: Control Sonos volume thru KNX Taster
  trigger:
  - platform: event
    event_type: knx_event
    event_data:
      destination: 6/0/2
  - platform: event
    event_type: knx_event
    event_data:
      destination: 6/0/0
  condition: []
  action:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.destination==''6/0/2'' and trigger.event.data.data == 1 }}'
      sequence:
      - service: media_player.media_play
        entity_id: media_player.fszt_folyoso
    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.destination==''6/0/2'' and trigger.event.data.data == 0 }}'
      sequence:
      - service: media_player.media_play_pause
        entity_id: media_player.fszt_folyoso
    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.destination==''6/0/0'' and trigger.event.data.data == 13 }}'
      sequence:
      - repeat:
          count: '25'
          sequence:
          - service: media_player.volume_up
            entity_id: media_player.fszt_folyoso
          - delay: '00:00:00.25'
    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.destination==''6/0/0'' and trigger.event.data.data == 5 }}'
      sequence:
      - repeat:
          count: '25'
          sequence:
          - service: media_player.volume_down
            entity_id: media_player.fszt_folyoso
          - delay: '00:00:00.25'
    default: []
  mode: restart

- alias: Step thru Sonos favorites input select with KNX Taster
  description: ''
  trigger:
  - event_data:
      destination: 6/0/1
      data: 1
    event_type: knx_event
    platform: event
  condition: []
  action:
  - service: input_select.select_next
    data:
      entity_id: input_select.sonos_favorites
  - service: media_player.select_source
    entity_id: media_player.fszt_folyoso
    data_template:
      source: '{{ states(''input_select.sonos_favorites'') }}'
  - service: media_player.media_play
    entity_id: media_player.fszt_folyoso
  mode: single
1 Like

Dear Farmio, all,
after hours of various trials, I definitely need your help…

I’ve a KNX Wall Switch operating as one button dimmer with the 2 objects (one is 1.001 and the other one 3.007), as per your example I believe.
I want to use this switch to control a SHELLY light through HA.
I do see the knx_event with the right data in the log, but the light doesn’t switch nor dimmer…
The Shelly light already works fine with a simple dimmer control in lovelace…
I’m using the HA core-2021.4.6.

I post here below the YAML conf I’ve in my light file package configuration:

Thanks a lot in advance for helping.
Simone

knx:
  #fire_event: true
  event_filter: ["0/0/7", "0/0/15"]
light:
  - platform: mqtt
    schema: template
    name: lucep
    command_topic: "shellies/shellydimmerpranzo/light/0/set"
    state_topic: "shellies/shellydimmerpranzo/light/0/status"
    command_on_template: >
      {"turn": "on"
      {%- if brightness is defined -%}
      , "brightness": {{brightness | float | multiply(0.3922) | round(0)}}
      {%- endif -%}
      }
    state_template: '{%- if value_json.ison %}on{% else %}off{% endif %}'
    brightness_template: '{{ value_json.brightness | float | multiply(2.55) | round(0) }}'
    command_off_template: '{"turn":"off"}'
    qos: 0
automation:
- alias: ziop
  description: ""
  trigger:
    - platform: event
      event_type: knx_event
      event_data:
        address: 0/0/7 # dim step ga, 3.007
    - platform: event
      event_type: knx_event
      event_data:
        address: 0/0/15 # switch ga, 1.001
  condition: []
  action:
    - choose:
        - conditions:
            - condition: template
              value_template: >-
                {{trigger.event.data.address=='0/0/7' and trigger.event.data.data
                == 9}}
          sequence:
            - repeat:
                count: '26'
                sequence:
                  - service: light.turn_on
                    data:
                      brightness: >-
                        {{ [state_attr('light.lucep',
                        "brightness")|int(0) + 10, 255]|min }}
                    entity_id: light.lucep
                  - delay: '00:00:00.5'
        - conditions:
            - condition: template
              value_template: >-
                {{trigger.event.data.address=='0/0/7' and trigger.event.data.data
                == 1}}
          sequence:
            - repeat:
                count: '26'
                sequence:
                  - service: light.turn_on
                    data:
                      brightness: >-
                        {{ [state_attr('light.lucep',
                        "brightness")|int(0) - 10, 0]|max }}
                    entity_id: light.lucep
                  - delay: '00:00:00.5'
        - conditions:
            - condition: template
              value_template: >-
                {{trigger.event.data.address=='0/0/15' and trigger.event.data.data
                == 1}}
          sequence:
            - service: light.turn_on
              data: {}
              entity_id: light.lucep
        - conditions:
            - condition: template
              value_template: >-
                {{trigger.event.data.address=='0/0/15' and trigger.event.data.data
                == 0}}
          sequence:
            - service: light.turn_off
              data: {}
              entity_id: light.lucep
      default: []
  mode: restart

PS: It also works switching the light if I do for example the following, but then I don’t know how to dimmer it…

knx:
  binary_sensor:
    - name: "pulsante_pranzo"
      state_address: '0/0/15'
automation:
- alias: prova_knx_on 
  trigger:
    platform: state
    entity_id: binary_sensor.pulsante_pranzo
    to: 'on'
  action:
    service: light.turn_on
    entity_id: light.lucep
- alias: prova_knx_off
  trigger:
    platform: state
    entity_id: binary_sensor.pulsante_pranzo
    to: 'off'
  action:
    service: light.turn_off
    entity_id: light.lucep

Hi!
Have a look at my blueprint (or just use it, it does exactly what you are looking for).

The destination address field of the event is called “destination”, not “address”.