TCP Commands From HA To Audio Matrix

I think that you are wrong here. As told you i have worked with udp before and i have a installation with 400 udp commands.
Below the syntax of the udp commands which works like a charm.

switch:
  - platform: command_line
    switches:
      player:
        command_on: 'echo -n -e "\xA5\xAB\x00\x02\x01\x00\x00\x03" | nc -u -w1 192.168.168.202 5062'
        command_off: 'echo -n -e "\xA5\xAB\x00\x02\x02\x00\x00\x04" | nc -u -w1 192.168.168.202 5062'

Also i managed these commands via template switches.
The issue here is why HA doesn’t send the command or to have an error to know how to solve it.
Now i cant understand where is the problem.
I use terminal for test commands and i have done lots of different combinations with the same result. Doesn’t do nothing.

Can anyone help me?

I have created and a tcp sensor with raw data,as you can see below. I don’t undrestand why i can’t send tcp commands.If i change the ip of the remote device with one which doesn’t exist the command run normally without error. At udp commands when the the remote device doesnt exist the command returns error asap.

image

sensor:
  - platform: tcp
    host: 192.168.168.202
    port: 5001
    payload: raw

I don;t know. Although I would never use the -e flag and add \r\n which to me would send the raw “\r\n” as the output from echo and add a newline (because of the -e flag).

Have you tried printf instead? Of omitting the “\r\n” as I would think that -e does the same thing?

Every suggestion I make is met with what you tried and not what I suggested without any explanation of what happened. So I give up … there are many audio matrix integrations like monoprice and xantach which I pointed to which are doing the same without fail, just with different code (python versus simple echo commands). I would think the minute you get to on/off you are going to need to think through inputs, balance control, trebel, bass, volume up/down. I would think that modifying other code that uses TCP or RS232 via TCP would be much better than reinventing.

Hello,

Thank you for your reply!
I have tryed printf but can you make an example to check if i’m doing something wrong?
I check the monoprice which i dont understand how to config in my case. Also xantach i saw that use serial at their example.
Can you help me build an example for my matrix?

Sorry for my manner, just because I work with udp for a long time, I thought it would work like this easily, but maybe I was wrong.

I have use an other windows programm to send test commands ASCII and works very well with matrix.
From HA i don’t have errors and still i can’t send commands. Very weird!

Hello,

I’m trying very hard to find a solution to send tcp commands from HA. Can anyone who have accomplished that help me with the command syntax which i have to send?
With the tools works just fine as you can see.
I have use printf and echo and bash with no result.

these were mine that i used before when working witn nc

#screens_open: echo -e "\xED\x43\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xAF\xAF\x53\x10\x01" | nc 192.168.0.10 1001
#screens_close: echo -e "\xED\x43\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xAF\xAF\x53\x11\x01" | nc 192.168.0.10 1001
#screens_stop: echo -e "\xED\x43\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xAF\xAF\x53\x1B\x01" | nc 192.168.0.10 1001

Its possible not all arguments are supported by the NC in alpine, its not the same version in debian
So i suggest to drop the -n , -u , -w1

To test if the commad works, you need to enter the HA container itself , the place where the commabd is actuallly fired, not the SSL addon, that one is different

als try to remove the first ’ and the last ’ quote, so you only quote the message itself… Its possible the quotes are giving issues too, you can always use " for the message and the command, and then backslah them, like:

command_on: echo -n -e "\xA5\xAB\x00\x02\x01\x00\x00\x03" | nc -u -w1 192.168.168.202 5062
or
command_on: "echo -n -e \"\xA5\xAB\x00\x02\x01\x00\x00\x03\" | nc -u -w1 192.168.168.202 5062"

Best to first SSH in to the SSH addon, turn off protection mode
from there, execure command below to enter the HA container , then try there the NC command

docker exec -it homeassistant /bin/bash

Hello,

I thank you for your reply
I run the commands at 2 instances for testing purposes.
One at Raspberry PI and the other from VMware.
At Raspberry i managed 400 commands udp with netcat without problems.
I will do later the changes you propose but at your example you use udp not tcp. With tcp we have to do something else except from delete the -u argument? My Command is at at ASCII format is there a problem with that? After disable protection mode i will run the command via terminal can you clarify this? Sorry for my questions but i want to do exactly what you said to me.

Well, all commands like shellcommand, template switch, they all run in the HA container, in order to test NC there, cause HA is using the Alpine version, you need to simulate it in that container… You can access that container using the SSH addon , from that you can use the docker command to access HA container…

Then do there the NC command, as I said, the NC version on Alpine is different then then the one from RPI, maybe the attributes are different…

Well,
At my ssh addon as you can see i dont see anywhere the protection mode
image

Also if i run the command which you send me doesnt work from HASSos or From VMware
image

As you can see when i execute the command from terminal runs without error. Also doesn’t return answer from the device.
image

Hi, there is another ssh addon, called , advanced ssh & web terminal, use that one instead, it has the protection mode

HI,
Thank you for your patient.

I have disable the proteciont mode and i execute the commands. Still the same. I have make different commands to be sure.

The above is from VMware installation and the below is from raspberry.The same result.
image

Hmm, if the command gives an error , it should be there, not sure why your she’ll command doesnt work :frowning:

The weird is that run the same commands to different HA installations to be sure. I take an error -1 and that the command can’t run only with argument -q1 but I don’t think that this is something to help us. Any ideas ?

I believe indeed the -q argument doesn’t work

You need to try and see if nc actually works and stop trying only with echo.

nc -z 192.168.168.202 5001

You keep trying to do everything at once, start from the lowest level and go up.

If you do not get “succeeded” from that, you have bigger problems.

If that works, then try:

echo "QUIT" | 192.168.168.202 5001

Report those back to us as when we suggest things you never respond back.
We are here to help you, but unless you give us information other than “I have done this 200 times with UDP”, we can’t help you.