It took some time, but it is solved…I write down what I have learned (sorry if I am not fully right; but I am just a nooby in IT: but I will do my best).
Fisrt the question:
Is there an easy way to send a telnet command and wait for the “apr0” answer, if not retry)?
Telnet is not really available for that but “nc” seem to be the same effective… (Thx for koying)
The most problem caused for me the dos-Linux [enter] incompability and probable file acccess permission. So what I wrote in HA File Editor was not always acceptable for the bash script. So before running I needed to run in HA terminal: dos2unix / chmod 755 / chmod +x for the files I used.
So the concept:
1, A shell command (Thx for tom_l) (in configuration.yaml) starts a bash file (Thx for koying)
2, The bash file sends to the av-reciever nc command for power on (“po”), then waits for response (“pwr0”) and depending on the response switches the HA input.boolean to on or off
-I needed for debugging a text file (log did not work for me) (use “>>” if text should be added as a new line)
'echo “Script started” > /config/send_nc_command_debug.txt ’
-The syntax to send the power_on_code (“po”) with nc; and wait for the response (this syntax is the key; with any changes it did not work for me):
-change a HA boolean switch according to the response:
if echo "$response" | grep -q "APR0"; then
curl -X POST -H "Authorization: Bearer [deleted auth key]" \
-H "Content-Type: application/json" \
-d '{"entity_id": "input_boolean.pioapwr"}' \
http://homeassistant.local:8123/api/services/input_boolean/turn_on
else
...
III. A Yaml sintax will re-aply the script again, if it was not successfull at first run (sometimes the avreciever does not react … if there is an other telnet info running, the sent power_off or on code may be lost … so no response will come).
Sorry, I am quite new, I stroggled sending my post. Now I finished above…
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…
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
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
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”