I just want to share what I finally did.
In configuration.yaml:
rest_command:
trigger_rest_event:
url: https://your.site/api/events/{{ event_type }}
method: post
headers:
authorization: !secret ha_secret_bearer
payload: "{{ event_data |to_json }}"
content_type: "application/json"
verify_ssl: true
You need an auth bearer for that!
Parameters to call are even_type
for the name of the event and event_data
as all data to include with the event.
This allows me to call the service rest_command.trigger_rest_event
from automations.
Then there is only one automation to handle all webhooks and call that service to fire the events.
alias: "REST Event from WebHook"
description: ""
trigger:
- platform: webhook
webhook_id: your_webhook_id1
id: ShortCuts
- platform: webhook
webhook_id: your_webhook_id2
id: Geofency
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: ShortCuts
sequence:
- service: rest_command.trigger_rest_event
data:
event_type: webhook.shortcuts.{{ trigger.json.trigger }}
event_data: "{{ trigger.json }}"
- conditions:
- condition: trigger
id: Geofency
sequence:
- service: rest_command.trigger_rest_event
data:
event_type: webhook.geofency.{{ trigger.json.name }}
event_data: "{{ trigger.json }}"
mode: single
As you see, I implemented two basic formats. One for the iOS app Geofency
and the other one for the iOS Shotcuts
app.
In Shortcuts
one JSON data needs to be added to the request: trigger
which is later used as the name for the event: webhook.shortcuts.trigger
.
For Geofency
the event is named by the place that Geofency
tiggered the webhook from: webhook.geofency.place
.
All JSON data from the webhooks is also added to the events.
Now I can act on the events as on all other events and can also query when they got last_fired
.
Since all data is attached to the event I can use them in templates in the automations.
Hope this helps somebody else if needed.
Edit:
I now derive the event name from the webhook using “-” as separator. Even simpler like that.
sequence:
- service: rest_command.trigger_rest_event
data:
event_type: webhook.{{ trigger.webhook_id.split('-')[0] }}
event_data: "{{ trigger.json }}"