wao
October 11, 2022, 8:37pm
21
Hi Matthias,
I’m using the blueprint you mentioned and it’s working fine, many thanks! I just created another automation using the knx_event as trigger and am still fighting with the data part. The called path will follow the turn_off command where the data is 0 although the data is 1.
What I captured on the bus:
event_type: knx_event
data:
data: 1
destination: 2/4/0
direction: Incoming
value: null
source: 1.1.43
telegramtype: GroupValueWrite
origin: LOCAL
time_fired: "2022-10-11T20:35:50.933339+00:00"
context:
id: 01GF4C5H0N5Q2J95JWF2VAQ47F
parent_id: null
user_id: null
This is the mentioned automation:
alias: "KNX event: Presence detection ground floor (2/4/0)"
description: Presence detection ground floor (with night light)
trigger:
- platform: event
event_type: knx_event
event_data:
destination: 2/4/0
telegramtype: GroupValueWrite
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.night_mode
state: "on"
sequence:
- if:
- condition: template
value_template: trigger.event.data.data == 1
alias: KNX bus data == 1 (ON)
then:
- service: light.turn_on
data_template:
brightness_pct: |
{{ states('input_number.night_light_brightness') | float }}
target:
entity_id:
- light.bath_gf_nightlight
- light.hall_gf_nightlight
else:
- service: light.turn_off
data: {}
target:
entity_id:
- light.bath_gf_nightlight
- light.hall_gf_nightlight
default:
- if:
- condition: template
value_template: trigger.event.data.data == 1
alias: KNX bus data == 1 (ON)
then:
- service: light.turn_on
data: {}
target:
entity_id: light.hall_gf
else:
- service: light.turn_off
data: {}
target:
entity_id: light.hall_gf
alias: Select nightmode (on or off)
Any idea what I’m missing?
farmio
(Matthias Alphart)
October 11, 2022, 9:05pm
22
first thing that comes to my mind would be to wrap this in "{{ }}"
.
1 Like
wao
October 11, 2022, 9:12pm
23
Awesome, that did the trick! Thanks!!!
value_template: "{{trigger.event.data.data == 1}}"
Guess am more used to strongly typed languages and compiler errors
Geolin
November 8, 2023, 9:26pm
24
Hello,
I try to capture data for a KNX Scene. This is what I get from the knx_event:
event_type: knx_event
data:
data:
- 1
destination: 0/3/0
direction: Incoming
value: null
source: 1.1.252
telegramtype: GroupValueWrite
origin: LOCAL
time_fired: "2023-11-08T21:21:33.278669+00:00"
context:
id: 01HERCZP2YMK0555H6W8RM7K0Z
parent_id: null
user_id: null
Any idea what I need to put in the template ? Currently I am using:
{{trigger.event.data.data[0] == 1}}
As you can see in the knx_event log the data[0] field got “- 1” as value. No clue how to put that in the template.
Thanks for your help!
farmio
(Matthias Alphart)
November 8, 2023, 10:47pm
25
Hi !
Thats not 100% correct.
The trigger.event.data.data
filed received a list with 1 item: 1
.
The value of this item trigger.event.data.data[0]
is 1
.
Mind that data[0]
addresses the first item of the list data
.
data:
- 1
is yaml representation for a list with 1 item with value 1
.
This looks OK after all.
It still depends on your trigger - if you already put the data
field in the trigger, it will only fire if it matches.
Geolin
November 8, 2023, 11:20pm
26
Ah, thank you. I didn’t know that.
So the whole yaml looks like this:
trigger:
- platform: event
event_type: knx_event
event_data:
destination: 0/3/0
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{trigger.event.data.data[0] == 0}}"
sequence:
- service: switch.turn_off
data: {}
target:
entity_id: input_boolean.knx_0_3_0_szene_schalten
- conditions:
- condition: template
value_template: "{{trigger.event.data.data[1] == 1}}"
sequence:
- service: switch.turn_on
data: {}
target:
entity_id: input_boolean.knx_0_3_0_szene_schalten
mode: single
I was testing it with these settings but I didn’t see that any of the conditions were true when the event for 0/3/0 came.
I have to test it again.
MandeepR
(Mandeep)
April 1, 2024, 2:30pm
27
Dear @farmio
After a lot of reading I am trying to trigger an automation based on KNX event trigger but have not succeeded yet.
The knx event records as:
event_type: knx_event
data:
data:
- 0
destination: 5/0/0
direction: Incoming
value: null
source: 1.2.9
telegramtype: GroupValueWrite
origin: LOCAL
time_fired: "2024-04-01T12:09:13.659815+00:00"
context:
id: 01HTCS0J5VFPEVJNSC3QQ2XABG
parent_id: null
user_id: null
I have used the following automations but none of it worked.
alias: Test Automation
description: ""
trigger:
- platform: event
event_type: knx_event
condition:
- condition: template
value_template: >
"{{ trigger.event.destination == '5/0/0' and trigger.event.data.data[0] ==
0 }}"
action:
- service: light.turn_on
target:
entity_id:
- light.gf_kavya_dresser_all_lights
data:
brightness: 255
mode: single
next:
alias: Test Automation
description: ""
trigger:
- platform: event
event_type: knx_event
event_data:
data:
- 0
condition: []
action:
- service: light.turn_on
target:
entity_id:
- light.gf_kavya_dresser_all_lights
data:
brightness: 255
mode: single
Another one:
alias: Automation testing
description: ""
trigger:
- platform: device
domain: knx
device_id: 6a0d0ed7f6c3a8d2e878bca5effad87b
type: telegram
destination:
- 5/0/0
condition:
- condition: template
value_template: "\"{{trigger.event.data.data[0] == 0}}\""
action:
- service: light.turn_on
metadata: {}
data:
brightness: 255
target:
entity_id: light.gf_kavya_bedroom_ll3_both_paired
mode: single
I have included the following in the configuration. I can see the blue line on trigger in the above options where I am using condition so the configuration for knx event seems to be working.
knx:
event:
- address:
- "5/0/0"
Can you please help me make it work.
farmio
(Matthias Alphart)
April 1, 2024, 3:48pm
28
If you use
Can’t work since I think you need to use trigger.event.data.destination
…
Is not an event so
No .event
there, and I don’t know what the "\"
is for. Click on the header when a telegram comes in to see the data structure. See Home Assistant - KNX: trigger actions from a KNX switch
MandeepR
(Mandeep)
April 1, 2024, 4:41pm
29
Thanks for our prompt reply @farmio .
Based on the video you sent, I checked the variables of the trigger:
variables:
trigger:
id: "0"
idx: "0"
alias: null
destination: 5/0/0
destination_name: ""
direction: Incoming
dpt_main: null
dpt_sub: null
dpt_name: null
payload:
- 0
source: 1.2.9
source_name: ""
telegramtype: GroupValueWrite
timestamp: "2024-04-01T22:00:59.171126+05:30"
unit: null
value: null
context: null
And changed the automation to the below but it did not work.
alias: Automation testing
description: ""
trigger:
- platform: device
domain: knx
device_id: 6a0d0ed7f6c3a8d2e878bca5effad87b
type: telegram
destination:
- 5/0/0
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.payload == 0 }}"
sequence:
- service: light.turn_on
target:
entity_id: light.gf_kavya_dresser_all_lights
data:
brightness: 255
mode: single
I tried the following which also did not work.
alias: Automation testing
description: ""
trigger:
- platform: event
event_type: ""
condition:
- condition: template
value_template: >-
"{{ trigger.event.data.destination == '5/0/0' and
trigger.event.data.data[0] == 0 }}"
action:
- service: light.turn_on
target:
entity_id:
- light.gf_kavya_dresser_all_lights
data:
brightness: 255
mode: single
If it makes any difference, I am using a scene group address from KNX.
farmio
(Matthias Alphart)
April 1, 2024, 5:21pm
30
MandeepR:
destination:
- 5/0/0
This expects a list with 1 item. It’s only a string though so you’d need to use
destination: 5/0/0
MandeepR
(Mandeep)
April 1, 2024, 6:32pm
31
Thanks @farmio
Tried the following but did not work.
alias: Automation testing
description: ""
trigger:
- platform: device
domain: knx
device_id: 6a0d0ed7f6c3a8d2e878bca5effad87b
type: telegram
destination: 5/0/0
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.payload == 0 }}"
sequence:
- service: light.turn_on
target:
entity_id: light.gf_kavya_dresser_all_lights
data:
brightness: 255
mode: single
farmio
(Matthias Alphart)
April 1, 2024, 6:39pm
32
But your payload seems to be a list
MandeepR:
payload:
- 0
I’d recommend to read some yaml tutorials before you move on.
MandeepR
(Mandeep)
April 1, 2024, 7:04pm
33
Thanks for directing me there. It worked now.
{{ trigger.payload[0] == 0 }}