Passing variables from MQTT trigger payload to shell script

I’m trying to run a shell command (to send an infrared code with lirc) based on an MQTT payload. I was hoping this would be farily easy but for some reason the below setup doesn’t work yet. The script receives no parameters…

automation:
   - id: irsend
     alias: IR Send                                                                                                                                                                
     trigger:
         platform: mqtt                                                                                                                                                            
         topic: "home/irsend/pi1"
     action:
         service: shell_command.irsend
         data_template:
             device: '{{ trigger.payload_json.device }}'
             key: '{{ trigger.payload_json.key }}'
 
shell_command:
     irsend: /home/homeautomation/homeassistant/scripts/media/irsend.sh "{{ device }}" "{{ key }}"

The irsend.sh shell script runs but receives no arguments. The MQTT stream seems fine:

home/irsend/pi1 {"VIP1853":"KEY_1"}  

I already tried around playing with different quote encapsulation in the irsend shell_command, but that didn’t help either.

Does anybody see what I’m missing or doing wrong here? Or have I found a bug?

This?

irsend: '/home/homeautomation/homeassistant/scripts/media/irsend.sh {{ device }} {{ key }}'

I tried that too, didn’t work no :frowning:

I know it’s doable. Hmmm while I’m waiting for 0.50

automation:
   - id: irsend
     alias: IR Send                                                                                                                                                                
     trigger:
         platform: mqtt                                                                                                                                                            
         topic: "home/irsend/pi1"
     action:
         service: shell_command.irsend
         data_template:
             value: '{{ trigger.payload_json.device }} {{ trigger.payload_json.key }}'
 
shell_command:
     irsend: '/home/homeautomation/homeassistant/scripts/media/irsend.sh {{ value }}'

Thanks, I’lll give it a try…

In the meantime I tried passing a raw {{ trigger.payload }} for both parameters, instead of the interpreted JSON, just to try to pinpoint the problem, and those did get passed! (not exactly what I want but good for testing of course). The two parameters came through without doublequotes though (as {VIP1853:KEY_1}), but I guess some kind of shell injection protection may play a part here.

I solved it… It seems like the original code was indeed fine and I was just being stupid looking in the wrong place:

When I said the JSON payload looked fine, I overlooked the fact that it wasn’t at all: the attributes were missing. With proper JSON the original automation now it works as expected:

home/irsend/pi1 {"device":"VIP1853","key":"KEY_1"}