Help using templates in shell commands

Hey,

I’ve got an HDMI matrix switcher from Extron that can receive commands over an ethernet connection via telnet. I’d like to be able to control this in home assistant.

So for example, I have this in place as a test and it works…

extron_smx_hdmi: echo 03*02*01! | curl telnet://192.168.254.174

The command being processed by the switch is 03*02*01!. The 02 indicates the desired HDMI input and the 01 is the output. Thus, this will let me route input 2 to output 1, but what I’d like to do is use templates inside of the command to determine the inputs and outputs dynamically using something like a drop down menu in HA. So it would be something like this…

extron_smx_hdmi: echo 03*{{ states("input_select.smx_input")}}*{{ states("input_select.smx_input")}}! | curl telnet://192.168.254.174

But this doesn’t work. Is there a way to do this? I’ll admit I’m not the most experienced with shell commands, so I’m hoping someone here can give me a little guidance. I see that the documentation says:

When using templates, shell_command runs in a more secure environment

I assume my problem is related to this.

My system is running Home Assistant Core 2022.8.5 in Docker on Unraid if that helps.

Thanks in advance for any help the community can provide.

See this post, the proposed solution is to create a short shell script and pass the data to the shell script as argument…

1 Like

Thank you so much! That took care of things for me!