Hello there,
is it possible to make an automation which is triggered by a webhook that accepts data as in trigger.data and switches on the light that is specified in that data?
Has anyone an example of how to do this?
Hello there,
is it possible to make an automation which is triggered by a webhook that accepts data as in trigger.data and switches on the light that is specified in that data?
Has anyone an example of how to do this?
You didn’t say what would be calling the webhook and whether or not you can control how it formats the body of the post, but let’s assume you can. The easiest approach is for it to send the entity id of the light you want to turn on. The body of the POST would look like this:
{ "entity_id" : "light.some_light" }
Then your automation with the webhook would look something like
- id: '1719999997716'
alias: Webhook Turn On Light
description: ''
trigger:
- platform: webhook
allowed_methods:
- POST
local_only: false
webhook_id: some-webhook-id
condition: []
action:
- service: light.turn_on
target:
entity_id: '{{ trigger.json.entity_id }}'
If whatever is sending the POST to your webhook is not able to send json, or if you don’t know, then I would suggest setting up the webhook and then looking to see what shows up in trigger.data
inside the automation’s trace.
Hello there,
thank you for your help!
i did what you said, made the automation as you said, and tried to fire a curl to test:
curl -i --trace-ascii - -X POST https://my.webhook.url -d ‘{“entity_id”:“light.hue_gradient_lightstrip_1”}’ -H “Content-Type:application/json”
but nothing happened.
where/how can i see the automations trace?
Edit:
found the traces, but i got a problem.
When i call the webhook without the -H parameter of curl it does something.
If i use the -H parameter the action is NOT triggered anymore.
why???
IT WORKS!
escaping was the problem:
-H “Content-Type: application/json” -d “{"entity_id":"light.hue_gradient_lightstrip_1"}”
so it worked!
Thank you very very much!