Using KNX Wall Switch to Control Homeassistant

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”.

I never used blueprints, need to understand them first. Anyhow you are right my issue was around the new “destination” naming.
Thank you!!

You can just copy&paste the Forum link from above to import it.

Hi, I am new to HA and KNX, so please bear with me.

I want to connect a KNX wall switch with a Shelly Plug S to which I attached a light. The KNX wall switch is configured in ETS to “toggle”. It sends GA “3/0/0” and also reads GA “0/1/0” and “0/1/3” to sync its state with “global” actions like “All lights off” and “All lights in room (Wohnzimmer) off”. The connection between the KNX wall switch and the Shelly Plug S needs to be bidirectional: If I toggle the wall switch, the Shelly/light should toggle. If I toggle the Shelly/light via HA, the wall switch state should be synchronized to that the next toggle of the wall switch is correct.

In addition to this thread, I also read the following related topics several times.

Below you find my current solution. It works exactly as described above. So basically all good. However, I have a few questions:

  • Is this really the best, cleanest, minimal way to achieve this? I doubt that so many lines of “code” are required for such a “common” scenario.
  • If yes, how can I make this reusable? I have like 5+ same scenarios? Is this possible with scripts or templates? As said, I am new to HA and don’t know them yet.

My current solution:

Shelly integration provides:

light.wohnzimmer_stehlampe

KNX wall switch → Shelly/light:

knx:
  binary_sensor:
    - name: "Wohnzimmer Schalter Stehlampe"
      state_address:
        - "3/0/0"
        - "0/1/0"
        - "0/1/3"

automation:
  - alias: "Wohnzimmer Stehlampe anschalten via KNX Schalter"
    trigger:
      - platform: state
        entity_id: binary_sensor.wohnzimmer_schalter_stehlampe
        to: "on"
    action:
      - service: light.turn_on
        entity_id: light.wohnzimmer_stehlampe
  - alias: "Wohnzimmer Stehlampe ausschalten via KNX Schalter"
    trigger:
      - platform: state
        entity_id: binary_sensor.wohnzimmer_schalter_stehlampe
        to: "off"
    action:
      - service: light.turn_off
        entity_id: light.wohnzimmer_stehlampe

Shelly/light → KNX wall switch:

knx:
  expose:
    - type: binary
      entity_id: light.wohnzimmer_stehlampe
      address: "3/0/0"

Thanks upfront and also for making this HA and KNX things happen. Cool stuff.

Be aware that a binary sensor sends GroupValueRead requests to its first state_address periodically by default. An expose on the other hand answers such - so HA is (maybe - depending on which telegram is faster) answering itself if you use the same addresses for these.

If 3/0/0 is exclusively used for this light I wouldn’t use a binary_sensor - it already has its HA entity from the shelly integration anyway. Just use a knx_event as trigger in an automation matching the 3 GAs and the payload (1 or 0) directly.

Enter the world of blueprints! About blueprints - Home Assistant
See also Topics tagged knx there are already 2 which could fit your needs (one of them is mine :wink:). You can also just use them as examples on how to use knx_event.
Just be aware that reloading the KNX integration breaks register_event and register_expose services - so maybe better configure them in yaml.