I have a webhook, and that webhook gets POSTed using a JSON {"event": "foo"}
. How do I set a condition so my automation only runs for certain events? I can’t use the Numeric state or State conditions, since they won’t let me access the trigger, since it isn’t an entity.
If you make an automation with no actions, you can view the trace & the variables that the automation creates under the Traces page, in the Changed Variables tab on the trigger node:
…
trigger:
platform: webhook
webhook_id: …
json:
event: ABC
You can then use a “Template condition” in the automation editor. For example, {{ trigger.json.event == 'ABC' }}
will return true for the above event. In YAML format,
condition: template
value_template: "{{ trigger.json.event == 'ABC' }}"
Hi,
I have a similar problem/question. receiving following data: (webhook post from Unifi Protect)
Shown under Changed Variables
this:
entity_id: automation.web_hook_test
state: 'on'
attributes:
id: '1726530021578'
last_triggered: '2024-09-18T18:44:01.393831+00:00'
mode: single
current: 0
friendly_name: web hook test
last_changed: '2024-09-18T18:53:50.947392+00:00'
last_reported: '2024-09-18T18:53:50.947392+00:00'
last_updated: '2024-09-18T18:53:50.947392+00:00'
context:
id: 01J837QMF32Y6KDPYKYTKSXQ4A
parent_id: null
user_id: null
trigger:
platform: webhook
webhook_id: XXXXXXXXXXXXXXXXX'
json:
alarm:
name: Person of interest
sources: []
conditions:
- condition:
type: is
source: face_of_interest
triggers:
- device: 28704E12AE9F
value: Boris
key: face_of_interest
timestamp: 1726685684188
query:
__type: <class 'multidict._multidict.MultiDictProxy'>
repr: <MultiDictProxy()>
description: webhook
id: '0'
idx: '0'
alias: null
Trying with the following automation:
alias: web hook test
description: ""
trigger:
- platform: webhook
allowed_methods:
- POST
- PUT
local_only: true
webhook_id: "XXXXXXXXXXXXX"
condition:
- condition: template
value_template: "{{ trigger.json.alarm.triggers.value == 'Boris' }}"
action:
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.googlehome8818
message: Hallo
target:
entity_id: tts.home_assistant_cloud
mode: single
But just can’t get the condition to pass. Tried all different variations of path to the value. But I am starting to think I took a wrong approach.
Would be great if some could take a look.
Thanks
Boris