Problems executing shell_command curl with template

I have a couple of TTLOCKs and a Gateway which I’m trying to access using HA, with no formal integration support. I can successfully connect to the locks from the command line with curl as per the TTLOCK API docs, so I know it’s possible. I’m pretty new to this and I’ve worked through just about every kind of shell command structure in HA to get this working. I’m stuck!

The API requires the POST request to contain the current timestamp in milliseconds, so I’ve used a template for this parameter. I’ve had this work as a command_line binary sensor but I don’t want to lock and unlock the doors every time I restart HA! I’m now trying a shell_command setup like this. It’s in a separate YAML file which is included in the main configuration.yaml.

shell_command: !include shell_commands.yaml

(and then in shell_commands.yaml)
back_door_unlock: >
    /usr/bin/curl --location -g --request POST 'https://api.ttlock.com/v3/lock/unlock' \
    --data-urlencode 'clientId=redacted' \
    --data-urlencode 'accessToken=redacted' \
    --data-urlencode 'lockId=redacted' \
    --data-urlencode 'date={{ (now().timestamp() | int * 1000 ) }}'

If I run this in a terminal (substituting in the current millis for the date parameter), it works. But I can’t get it to fire in HA! I’m testing by using the Services tab in Developer Tools. I get a green tick when I try to run the service, but nothing happens at the lock. Debug logs show that the template is not getting parsed correctly:

2022-04-16 14:01:51 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/usr/bin/curl --location -g --request POST 'https://api.ttlock.com/v3/lock/unlock' \ --data-urlencode 'clientId=xxx' \ --data-urlencode 'accessToken=xxx' \ --data-urlencode 'lockId=xxx' \ --data-urlencode 'date={{ (now().timestamp() | int * 1000 ) }}'
`, return code: 6

After this I see an HTML response saying The request sent by the client was syntactically incorrect.

How can I get this working?