Needed help with shell_command

Howdy folks,

I’m trying to integrate a quirky ESP8266 based device that likes to talk via UDP, this is what the basic command looks like:

echo "RF+7201832" | nc -u -w 1 192.168.1.74 4210

The esp device reicives the command and executes it correctly.

I’ve tested it in the home assistant shell and the command is received. Now I would like to integrate this with automations, now it looks like that the best option for this kind of scenario is the “shell_command” integration, which needs to be manually added to the configuration.yaml, no problems so far.

I’ve started with a simple test comand in HA like this one:

shell_command:
  esp_send: 'echo "RF+7201832" | nc -u -w 1 192.168.1.74 4210'

This configuration creates a “shell_command.esp_send” when used, the command is once again received by the esp device and executed perfectly.

Now, since I would like to keep my configuration.yaml free and not creating hundreds of lines for each specific command I’ve decided to follow the wiki for the shell command integration.

the “states” macro is used to pull in a value from HA and I’ve tried to replicate the same structure:

shell_command:
  esp_send: 'echo "{{ states("input_text.commandbridge") }}" | nc -u -w 1 192.168.1.74 4210'

I’ve set the input_text with something that would be recognized be the esp device in this case “RF+7201832” but no command is ever sent and this is what I see in the gui:

Now, the input_text is being correctly pulled in as the correct value can be seen. But for whatever reason, the echo is intercepted by stdout and never correcly executed. I’m not a bash expert, so maybe this is just an issue with some commas, but I haven’t been able to figure this out yet, I hope that I may find my answers here.

I’m not a bash expert either, but you’ve got double quotes inside double quotes, and that kind of thing can cause weirdness…

If they are necessary, try using a multi-line quote indicator to avoid the outer-most single quotes and concatenating the double quotes with the command string inside the template delimiters.

shell_command:
  esp_send: |
    echo {{ '"'~states('input_text.commandbridge')~'"' }} | nc -u -w 1 192.168.1.74 4210

Even with your modification I’m getting the same result:

I still have no clue on why this is happening

Pipes do not work well in shell_command

try

shell_command:
  esp_send: >
    bash -c 'echo "RF+7201832" | nc -u -w 1 192.168.1.74 4210'