I have found at least a dozen posts on trying to pass data to shell_command using a service call, and it seems to be a common problem to get all of the delimiters right. Unfortunately, the documentation is not very extensive on this, and one post points out that Developers’ Tools use a routine slightly different from automations to implement this, which causes confusion. I have also experimented a ton, but cannot figure it out.
The problem is not that complicated. I am sending CLI to another computer using ssh. I have figured out the problems of generating keys, adding the HA key to the other computer, getting around the allowed hosts bit, etc. It works from the shell on on HassOS, and from Developers Tools. Here is what works from the shell:
ssh -i /config/id_rsa -o UserKnownHostsFile=/dev/null -o 'StrictHostKeyChecking=no' [email protected] 'espeak "Just a test."'
I set up a shell_command
like this:
shell_command:
robot_speak: ssh -i /config/id_rsa -o UserKnownHostsFile=/dev/null -o 'StrictHostKeyChecking=no' [email protected] 'espeak {{ text }}'
and then test it with the DT like this:
service: shell_command.robot_speak
data:
text: '{{"Just a test"}}'
Yay! That works, too. However, if I try to do something similar in automation it does not work. For example, I test it with a button card in lovelace and nothing happens, and nothing shows up in the logs (maybe I need to set logs to debug?).
type: button
entity: some.entity
tap_action:
action: call-service
service: shell_command.robot_speak
data:
text: '{{"Just a test"}}'
But this does not work. I have tried dozens of different things to fix it, mostly surrounding the delimiters. Using “’’” or ", etc. One of these things did get the first word alone to be passed, but I can’t even reproduce that. I have also tried using data_template
, but without luck.
Has anyone ever cracked the code for getting data passed reliably to shell_command
. This is really my first attempt at it. Since it works from cli in the shell, and with DT, I assume it has something to do with the service call and shell command bits.