starob
September 20, 2023, 5:10pm
1
I’m trying to extract an image file name from an event using trigger.event.data but I tried & searched here for hours and have no idea how to do that. Maybe a guru can help?
The event looks like this
event_type: call_service
data:
domain: telegram_bot
service: send_photo
service_data:
target: xxxxxxxxxx
url: >-
http://192.168.1.200:3000/api/storage/matches/snapshot.jpg
caption: 'Caption'
origin: LOCAL
time_fired: "2023-09-20T16:14:07.690043+00:00"
context:
id: 01HASNXHT9B28YNNVJAAMCMD52
parent_id: null
user_id: null
This is the automation I use. I tried many different variations of trigger.event.data.url and trigger.event.data.service_data.url but none of them worked. I’m getting “invalid key” or similar errors.
- id: '20230920171511'
alias: 'Notification Image Test'
initial_state: 'on'
trigger:
platform: event
event_type: call_service
event_data:
domain: telegram_bot
service: send_photo
action:
- service: notify.robert
data:
message: 'Notification Image Test'
data:
photo:
- url: {{ trigger.event.data.url }}
caption: 'Image'
123
(Taras)
September 20, 2023, 5:28pm
2
Wrap the template in quotes.
url: '{{ trigger.event.data.url }}'
Reference
Important template rules
starob
September 20, 2023, 8:08pm
3
Thank you. Unfortunately I’m now getting this error:
Logger: homeassistant.helpers.template
Source: helpers/template.py:232
First occurred: 22:03:27 (1 occurrences)
Last logged: 22:03:27
Template variable warning: 'dict object' has no attribute 'url' when rendering '{{ trigger.event.data.url }}'
123
(Taras)
September 20, 2023, 8:28pm
4
Check the automation’s trace and confirm trigger.event.data
has a url
property.
Based on the example you posted above, I believe it should be like this:
url: '{{ trigger.event.data.service_data.url }}'
1 Like
yebaws
February 20, 2024, 6:07pm
5
Trying to do something similar. I want to get the remoteJid of a whatsapp group every time I receive a new whatsapp group message and then send it in a whatsapp message
Output from listening service is as below:
event_type: new_whatsapp_message
data:
clientId: default
type: conversation
key:
remoteJid: [email protected]
fromMe: false
id: 711E3107xxxxxxxxxxx06176FC23B
participant: [email protected]
messageTimestamp: 1708420501
pushName: Lxxxxxxxxey
broadcast: false
message:
conversation: Hel
origin: REMOTE
time_fired: "2024-02-20T09:15:02.148603+00:00"
context:
id: 01HQ2WR4M4A6A5Q2S4D7V3HHVZ
parent_id: null
user_id: e9c44cxxxxxxxxxxxb34c0e
this is my (failed) attempt to get the remoteJid and send it in a Whatsapp:
alias: get remote Jid
description: ""
trigger:
- platform: event
event_type: new_whatsapp_message
condition: []
action:
- service: whatsapp.send_message
data:
clientId: default
to: [email protected]
body: "{{ trigger.event.data.remoteJid }}"
mode: single
The trace says
“Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’”
Not sure what I’ve missed?
yebaws
February 20, 2024, 7:35pm
6
to answer my own question,
{{ trigger.event.data.key.remoteJid }}
is what I should have used
I have a similar problem and dont want to open a new topic.
Maybe someone can help me with my issue.
I want to extract data from an event fired by an automation.
In the developer tools (events) i can see the data i want to extract :
event_type: alexa_actionable_notification
data:
event_id: auto_klima
event_response: ResponseNone
event_response_type: ResponseNone
origin: REMOTE
time_fired: "2025-01-20T11:05:36.479533+00:00"
context:
id: 01JJ1P7CEZEBAYYJQEMB4NY97B
parent_id: null
user_id: 0002f87b5519437491e34e900e772fae
And with this automation i wanted to extract the “event_response” :
alias: Alexa 2
description: ""
triggers:
- trigger: event
event_type: alexa_actionable_notification
event_data:
event_id: auto_klima
conditions: []
actions:
- action: input_text.set_value
metadata: {}
data:
value: "{{ trigger.event.data.event_repsonse }}"
target:
entity_id: input_text.demo_alex_antwort
mode: single
But the Trace shows me this:
Value is empty. But i want the value of event_response (ResponseNone)
I hope someone can help me.
Okay i had a typo. repsonse should be response.