Send simple telnet command in HA

Please help me! I need to send for my pio av-reciever a telnet command (“apo”) and (since it is not always reacting) check the answer (“APR0”) …
1,Telnet switch via config.yaml is not good, it triggers all the time the av reciever, so it hangs up after a while
2, I have problem with Node-red either: I have my scripts/automations in yaml; when I use the Node-red button, somehow the automation stops there…

Is there an easy way to send a telnet command (and wai for the “apr0” answer, if not retry) throug Yaml script?

“telnet 192.168.188.33 23
apo”

There is an example here:

Sorry, I am quite new, I stroggled sending my post. Now I finished above…:slight_smile:

Telnet switch does not work for me; since it triggers the reciever all the time (every second) so the reciever answers every sec and hangs after a while. I can see this in a telnet shell window…

How about a shell command then?

It does not work for me:
Config.yaml:
shell_command:
send_telnet_command: ‘echo -e “apo\n” | telnet 192.168.188.33 23’

DeveloperTools/Action (YAML):
action: >-
shell_command.send_telnet_command

RESPONSE:
stdout: “”
stderr: “/bin/sh: telnet: not found”
returncode: 127

Second version:
Config.yaml:
send_vd_command: telnet 192.168.188.33 8102 <<< ‘vd’

Developertools/Action:
action: >-
shell_command.send_vd_command

Response:
stdout: “”
stderr: “/bin/sh: syntax error: unexpected redirection”
returncode: 2

You have no telnet command inside the HA container, but you have nc

1 Like

What would be the correct syntax?
This does not work::
config.yaml:
send_nc_command: “echo -e ‘apo’ | nc 192.168.188.33 23”
Developertools/Action:
action: >-
shell_command.send_vd_command
RESPONSE:
stdout: “”
stderr: “/bin/sh: syntax error: unexpected redirection”
returncode: 2

Best I achieved:
config.yaml shell_command:
send_nc_command3: nc 192.168.188.33 8102 “apo”

DEVelopersection/action:
action: >-
shell_command.send_nc_command3
Response:
stdout: “”
stderr: “BusyBox v1.36.1 (2024-06-10 07:11:47 UTC) multi-call binary.\n\nUsage: nc [OPTIONS] HOST PORT - connect\nnc [OPTIONS] -l -p PORT [HOST] [PORT] - listen\n\n\t-e PROG\tRun PROG after connect (must be last)\n\t-l\tListen mode, for inbound connects\n\t-lk\tWith -e, provides persistent server\n\t-p PORT\tLocal port\n\t-s ADDR\tLocal address\n\t-w SEC\tTimeout for connects and final net reads\n\t-i SEC\tDelay interval for lines sent\n\t-n\tDon’t do DNS resolution\n\t-u\tUDP mode\n\t-b\tAllow broadcasts\n\t-v\tVerbose\n\t-o FILE\tHex dump traffic\n\t-z\tZero-I/O mode (scanning)”
returncode: 1

Pipes in shell_command are problematic, iirc.
Try to wrap the command in a shell script and use bash /config/the_script.sh in the shell_command.

Do I need to run the following command to ensure the script is executable (via Terminal)?

chmod +x /homeassistant/send_nc_command.sh

It is not working…nothing sent
Timed out running command: bash /config/send_nc_command.sh, after: 60 seconds

bash /config/send_nc_command.sh file content is:
echo -n ‘vd’ | nc 192.168.188.33 8102

Did you try the nc command in, i.e., the terminal addon, first?

yes, it can listen, but I can not send any data eg “vd” =volume down
If I send on a different pc-telnet session “Vd”, it shows up with the reaction; but if I type in the terminal nothing happens

HOwever if I usde -v -v option; it states the typed data is sent; but it is not true

2024-11-22_165142

Big step forward: HUrrraaaa

in Temrinal both works (“\r” was missed):
printf “vd\r” | nc 192.168.188.33 8102
echo “VD\r” | nc 192.168.188.33 8102

BUT there is not seeable any answer
Using the following code, I can see answers, but codes typed [and hit enter] are not accepted
nc 192.168.188.33 8102

One step better again:
in terminal; the code works and the answer is also seeable…

(echo “apo\r”; sleep 1) | nc 192.168.188.33 8102

Now I need a way to use this in HA script. Send “APO”; check the answer; if it is APR0 then switch a switch to “on”; if the answer does not contain “APR0” then try again sending “apo/r”