Passing automation variable to shell_command

I’m trying to set up a homemade infrared remote using ESP8266. I have a few devices and want to write as few scripts as possible. I am therefore trying to make it as dynamic as possible but am falling at the first hurdle it seems.

This is the yaml I have so far (amalgamated for ease of reading):

hastebin yaml and relevant log

It doesn’t seem that the variable is being used in the command, but from the log I can see that the variable seems to be being passed correctly. I’m thinking it’s my syntax in the shell_command causing me the issues, but I’ve spent ages trying all the different combinations I can think of, and scoured google to no avail.

Any input would be greatly appreciated!