I have tried to receive info from my sensor using webhook.
The script code (named hello_world.py):
logger.info("Script has been ran")
name = data.get("nm", "world")
t_data = data.get("t_data","empty")
logger.info("Hello %s", name)
hass.bus.fire(name, {"wow": "from a Python script!"})
headers = {'content-type': 'application/json'}
url = "http://hadom.ru/php/homeassistant_local.php"
data = '{"action": "get_state"}'
logger.info("Trigger data: %s", t_data)
The automation.yaml:
- id: ‘1597082219396’
alias: webhook_123
description: ‘’
trigger:- platform: webhook
webhook_id: 0987
condition: []
action:- service: python_script.hello_world
data:
nm: webhook call NEW
t_data: ‘{{t rigger.data }’
data_template:
message: ‘income data: {{ trigger.payload }}’
mode: single
- service: python_script.hello_world
- platform: webhook
The command to send message:```curl -H "Content-Type: application/json" -X POST -d '{"type":"text","data":"general"}' http://homeassistant.local:8123/api/webhook/0987```
And there are my logs:
2020-08-10 23:05:17 INFO (MainThread) [homeassistant.components.automation] Executing webhook_123
2020-08-10 23:05:17 INFO (MainThread) [homeassistant.components.automation] webhook_123: Running script
2020-08-10 23:05:17 INFO (MainThread) [homeassistant.components.automation] webhook_123: Executing step call service
2020-08-10 23:05:17 INFO (SyncWorker_1) [homeassistant.components.python_script] Executing hello_world.py: {‘nm’: ‘webhook call NEW’, ‘t_data’: ‘trigger.data’, ‘message’: ‘income data:’}
2020-08-10 23:05:17 INFO (SyncWorker_1) [homeassistant.components.python_script.hello_world.py] Script has been ran
2020-08-10 23:05:17 INFO (SyncWorker_1) [homeassistant.components.python_script.hello_world.py] Hello webhook call NEW
2020-08-10 23:05:17 INFO (SyncWorker_1) [homeassistant.components.python_script.hello_world.py] Trigger data: trigger.data
As you can see webhook has called automation->script but I can`t to get incoming data (json).
I have tried to set into automation - {{trigger.json}} also, but result are same - nothing comes.