HA webhook

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
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.

Almost solved:

- id: '1597082219396'
  alias: webhook_123
  description: ''
  trigger:
  - platform: webhook
    webhook_id: 0987
  condition: []
  action: 
    - service: python_script.hello_world
      data: 
        nm: webhook call NEW
      data_template:
        message: '{{ trigger.json }}'
  mode: single

I have putted income value into data_tamplate section. Now it resend data into python script.
Now, I have faced with another problem - the value comes into python as STRING and I can to operate with it as array.

logger.info("Trigger data: %s", t_data)
logger.info("data: %s", t_data['data'])

the first string works, second gives me error

if t_data is a string, you can’t use __getitem__ on it because it’s not a dictionary. You have to parse the data. Also, just so you know, your script is passing t_data out, which in your case will default to ‘empty’… unless you’ve changed your python script.