Automation does not trigger based on KNX event

Hi,

I want to trigger an automation based on below KNX Event. Every time a “1” is received on GA 5/0/2, stuff should happen.

The event:

event_type: knx_event
data:
  data: 1
  destination: 5/0/2
  direction: Incoming
  value: null
  source: 1.0.2
  telegramtype: GroupValueWrite
origin: LOCAL
time_fired: "2023-01-19T10:56:27.030023+00:00"
context:
  id: 01GQ4TRFWPE0G9K7GA9K75E1QP
  parent_id: null
  user_id: null

My automation:

- id: '1674125540577'
  alias: Paniekschakelaar
  description: ''
  trigger:
  - platform: event
    event_type: knx_event
  condition:
  - condition: template
    value_template: "{{ trigger.event.data.destination == '5/0/2'  and\n   trigger.event.data.data[0]
      == 1 }}\n"
    enabled: true
  action:

The automation never triggers. It does when I remove the condition “trigger.event.data.data[0]
== 1”.

What am I overlooking?

You’ve got some stray \n in there that aren’t helping you.

Thanks for the quick reply.

I copied the automation from my automations.yaml file. However, the automation was created via the UI. I think the UI added the \n (it’s not even visible in the UI).

Anyway, I got rid of the \n, but it didn’t solve the issue…

Any reason you’re not simply putting the required details in the trigger?

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

Beyond that, it’s probably because:

  • 1 is a number and '1' is a string.
  • The event data isn’t an array, so [0] makes no sense

Exactly that :+1:

A integer is used for DPT 1, 2 and 3 payloads. Longer payloads are always a list of int - even if it has just one item. This is because payloads < 6 Bit are encoded differently than others in KNX.

I was inspired by this topic. I applied this method successfully on another automation trigger.

But based on your and Matthias’ input (thanks!), it works!

If the trigger is something like:

event_type: knx_event
data:
  data: 0
  destination: 5/0/3
  direction: Incoming
  value: null
  source: 1.0.2
  telegramtype: GroupValueWrite
origin: LOCAL
time_fired: "2023-01-19T14:21:18.472764+00:00"
context:
  id: 01GQ56FK882CDJGHE0YS6ZFS4Y
  parent_id: null
  user_id: null

I can trigger the automation by defining it like:

  trigger:
  - platform: event
    event_type: knx_event
    event_data:
      destination: 5/0/3
      data: 0

However, the trigger of my other KNX event is slightly different:

event_type: knx_event
data:
  data:
    - 7
  destination: 3/2/0
  direction: Incoming
  value: null
  source: 1.1.65
  telegramtype: GroupValueWrite
origin: LOCAL

And that’s why I had to work with an array for my automation trigger:

  trigger:
  - platform: event
    event_type: knx_event
    event_data: {}
  condition:
  - condition: template
    value_template: "{{ trigger.event.data.destination == '3/2/0' and\n   trigger.event.data.data[0]
      == 7 }}\n"
    enabled: true