Trigger automation with KNX Scene Event

Hi,

I try to trigger an automation with the following knx_event which is apearing on the HA event bus as follows

{
    "event_type": "knx_event",
    "data": {
        "address": "0/7/0",
        "data": [
            1
        ]
    },
    "origin": "LOCAL",
    "time_fired": "2021-02-04T15:21:56.221910+00:00",
    "context": {
        "id": "94b7b9a740d44c8ba6b0d0f6b2f3ae18",
        "parent_id": null,
        "user_id": null
    }
}

The following automation is not triggered. I don’t understand why.

- alias: Szene_Wohnzimmer
  trigger:
    platform: event
    event_type: knx_event
    event_data:
      address: '0/7/0'
      data: [ 1 ]
  condition: []
  action:
    - service: script.evening_livingroom

I tried as well this with no success.

data: 1

Appreciate your help.

Regards.
Ralf

The author of the following post encountered the same challenge. The solution was to use a condition because it provides more control for accessing the list item in data.

In your case it would be:

    trigger:
      platform: event
      event_type: knx_event
    condition:
      condition: template
      value_template: >
        {{ trigger.event.data.address == '0/7/0' and
           trigger.event.data.data[0] == 1 }}

You could also try this and see if it works:

    trigger:
      platform: event
      event_type: knx_event
      event_data:
        address: '0/7/0'
    condition:
      condition: template
      value_template: '{{ trigger.event.data.data[0] == 1 }}'
2 Likes

You are my hero. I was not able to find the referenced thread. Sorry. It works now.

1 Like

Until you update to 2021.2. then you will have to change address to destination for the GroupAddress.

3 Likes

Thanks for highlighting this. Update to 2021.2 is on the list. Your post saves a lot of frustration.

@farmio, I got no conclusive answer about where address is changed to destination starting 2021.2.

In the knx_event data construct only or everywhere in the knx HA universe?

Only in the event data of knx_event

@farmio thank you for pointing out the solution. I have over 20 automations based on KNX telegrams and I was really panicking for a bit :slight_smile:

@balloob This change should be announced at the same level as the security vulnerabilities were announced (what was also the reason why I upgraded my production Home Assistant without looking further inside the release notes). Even my outdoor alarm was firering once because of this change :smiley:

Kind regards,
Stijn

my trigger not run, any ideas? can i log the knx_event ?

trigger:
  - platform: event
    event_type: knx_event
condition:
  - condition: template
    value_template: >
      {{ trigger.event.data.destination == '1/0/108' and trigger.event.data.data
      == 0 }}
action:
  - service: light.turn_off
    target:
      entity_id:
        - light.hue_color_floor_2
        - light.hue_color_floor_1
        - light.hue_adore_wall_1
        - light.hue_aurelle_panel_1
        - light.hue_centura_color_spot_1
mode: single

Sure. Go to developer tools -> events
and filter for “knx_event”

Can you try this?

in the yaml:

knx:
    event_filter: ["0/0/1", "1/0/13"]

brought by me the solution

Sure. Valid point. You need to enable the event being sent to HA. By default not all KNX Events are sent.

I couldn’t get it to work at first.
The ‘event_filter’ in the KNX yaml gave me more issues than solutions.
What does that do exactly? I’m unable to find clear documentation on that.

What did work for me was filtering on the ‘destination’ and ‘value’ attributes of the knx_event.
I noticed that filter on the ‘value’ attribute was better then the ‘data’ attribute, because some actors will start counting the scene numbers from 0, while others start from 1, so the ‘data’ attribute will not always match the scene number while the 'value always matched for me.

trigger:
  - platform: event
    event_type: knx_event
    event_data:
      destination: '0/1/1'
      value: 5

It’s just event: now - no more “_filter”. See KNX - Home Assistant
If you configured this with type: scene_number you’ll get a value of payload +1 where payload is the first item of the data field (data is a list for DPT 5 / 17).

2 Likes

Blockquote
It’s just event: now - no more “_filter”. See KNX - Home Assistant

That explains a lot :slightly_smiling_face:
Thanks!

1 Like

Fyi, for other readers: In my case it was ‘destination’ and not address, as follows:

trigger:
  - platform: event
    event_type: knx_event
condition:
  - condition: template
    value_template: |
      {{ trigger.event.data.destination == '7/0/0' and
         trigger.event.data.data[0] == 5 }}

Also, I had to first run service KNX: Register knx_event before any events got picked up by knx_event

Hi,

May I just add another question regarding knx event data and conditions. I succeeded receiving the event, but I cannot access the data in a condition. The sent data is a simple on/off switch data type (1.001, DTP_Switch, 0 = Off, 1 = On) and received correctly, at least from what I saw in the event listener. My goal was having one automation for each address and implementing different conditional actions, eg. 0 to turn the light off, 1 to turn it on. As a workaround I implemented an automation for each address and data:

alias: "KNX event: Living room - ceiling light Off (2/0/120)"
description: KNX event listener for the living room ceiling light
trigger:
  - platform: event
    event_type: knx_event
    event_data:
      address: 2/0/120
      data: 0
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.hue_fair_pendant_1
mode: single

This is working but makes the code hard to maintain since I have quite a lot of automations listening to the same address. Is there an approach having a single event listener for one address with conditions and different actions?

That’s my setup (knx.xaml):

knx:
  event:
    # Living room - ceiling light (2/0/120 - 2/0/124)
    - address:
      - "2/0/120"
      - "2/0/121"

And that’s what I’d like to achive:

alias: "KNX event: Data condition test"
description: Test automation for receiving knx events with data condition
trigger:
  - platform: event
    event_type: knx_event
    event_data:
      address: 2/0/120
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: trigger.event.data.data[0] == 1
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.hue_fair_pendant_1
      - conditions:
          - condition: template
            value_template: trigger.event.data.data[0] == 0
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.hue_fair_pendant_1
mode: single

I just added on an off for the example, but I’d like to add further values to increase/decrease the brightness.

Many thanks in advance,
Br

It’s destination:, not address:.
Also you may have a look at my blueprint which handles exactly what you want to achieve without the need to set event-addresses in yaml: KNX - relative dimming for lights blueprint · GitHub

The hell…you’re absolutely right. Thanks, that looks promising!

btw: many thanks for the knx integration, absolutely brilliant!