Syntax for passing variable data to automation via webhook

Until a week or so ago I knew nothing about HA and how to program it. I don’t know much more now! So assume I’m a total ignoramus and don’t use too many big words.
I have set up an automation using UI which may or may not be correct. My bet would be on the latter. The aim is to invoke the service lock.set_usercode. It needs 3 parameters. The node_id will always be 3, the code_slot will always be 1, and the usercode will vary every time. I can’t work out how to format from the UI to display in this post but this is what I have set up:

`Action type
Call service

Service
lock.set_usercode
Service data
data: ‘node_id:‘3’ code_slot:‘1’’
data_template:
usercode: ‘{{trigger.data}}’`

I’ve sort of cobbled this together as my best shot to get it to work. I’m calling it remotely using a webhook I got from Home Assistant Cloud. I’m using a curl command to try and set the usercode to =1234:
curl -X POST webhook -d "{{1234}}"

Again I’ve sort of cobbled this together from the few examples I can find. I’m sure the syntax is incorrect. I’ve tried a few dozen combinations of brackets/quotes without success. It is definitely working as far as invoking the automation because I see entries in the log. It’s just not updating the usercode. Can anyone tell me if the automation is correctly set up? And what syntax should I be using in the curl command line for passing variable data? The forum has helped hugely to get me to this stage. Any help would be greatly appreciated.

OK, I have made some progress. I’ve proved that the automation with a hardcoded usercode works. Service data as YAML:

service: lock.set_usercode
data:
  node_id: 3
  code_slot: 1
  usercode: 1234

If I use my curl command in Outlook VBA to just call the webhook with no parameters then it works, although there is a delay in it registering. So what do I need to replace “1234” with in the automation code to accept a variable, and where on the Curl command line do I put the variable data?

OK Finally got there after trying lots and lots of variations. For anyone else who might have the same problem here is what worked. My service data YAML in the Automation configuration is set to:

service: lock.set_usercode
data:
  node_id: 3
  code_slot: 1
data_template:
  usercode: "{{trigger.data.usercode}}"

And my curl command line looks like:
curl -X POST -d usercode=“1234” webhook

3 Likes