TCP Commands From HA To Audio Matrix


I’m trying to send tcp commands to a remote matrix but doesnt works.

I have tested my connection with the matrix and i can send commands from a windows tool as a tcp client.
The command which i send now is #|M001|F001|SV01|40|U|\r\n and works.
From HA i have tryed all possible combinations with no success.

My configuration.yaml has the below switch for tesing only.

  - platform: command_line
        command_on: 'echo -ne "#|M001|F001|SV01|60|U|\r\n" | nc 5001'
        command_off: 'echo -ne "#|M001|F001|SV01|60|U|\r\n" | nc 5001' 

Could you be more precise, please.

So your “remote matrix” insists on having commands sent with windows CRLF?


Below the tcp client.
The matrix use crlf as can you see below.

Can anyone help me with this? I work lot of time udp commands without problem but now with
tcp netcat doesn’t work.

Those 2 are identical. Is it meant to be?
Besides, did you try those “echo | nc” from a non HA environment, first?

The changed value is the 60 from 0 - 100. I have put a static value to established the connection first and see if it is works then i will put an automation with input_number from helper to send the desired values. How to check the echo command from non-ha environment? I’m asking to make this right.

 command_on: 'echo -ne "#|M001|F001|SV01|60|U|\r\n" | nc 5001'
 command_off: 'echo -ne "#|M001|F001|SV01|60|U|\r\n" | nc 5001' 

You could start by ssh into HASS and trying that command from the shell.

I have tried it from the shell and the command is executed, I have no error in the Logs but nothing changes in the matrix. Doesn’t work!

Can anyone help me?

I have tryed and the below configuration but nothing. I dont have errors and the commands doesnt make any change at remote device.With the windows tool using i’m using (i have attached screenshot) works fine.

  - platform: command_line
        command_on: >-
            bash -c 'echo "#|M001|F001|SV01|60|U|\r\n" | nc 5001'
        command_off: >-
            bash -c 'echo "#|M001|F001|SV01|40|U|\r\n" | nc 5001'

I do not think the YAML is correct. I would do something like this (untested, just looking at other samples I have done):

  matrix_on: >
      echo -ne "#|M001|F001|SV01|60|U|\r\n" | nc 5001
  matrix_off: >
      echo -ne "#|M001|F001|SV01|60|U|\r\n" | nc 5001

called then in a script or automation as:

    - service: shell_command.matrix_on

Then you can pass in variables (in data) when calling it like the command could be:

echo -ne "#|M001|F001|SV01|60|U|\r\n" | nc {{host}} {{port}}

As in:

    - service: shell_command.matrix_on
         port: 5001

I would also be surprised that the command EOL is not just “\r” and not “\r\n” and you would need to be sure the “homeassistant” user has permissions to run “nc”.

For additional inspiration, you may wish to look at this integration GitHub - rsnodgrass/hass-xantech: Xantech Multi-Zone Matrix Audio for Home Assistant and how it works. I added the Dayton Audio DAX 88 server commands to it and it works flawlessly in my setup.

I dont understand why to pass the host and port as action and not direct?
Also if i run only the shell_command on/off why doesnt work?
Can you explain this?

Thank you for your reply!

You do not have to pass the host and port as data, that was only an example. You stated you wanted to pass in things to run them, I only showed you how to pass in things using “data”.

Also if i run only the shell_command on/off why doesnt work?

Who knows? Turn on debugging for that command and see what it says. Could be as I said, the homeassistant user has no permissions to run that command … or the command is wrong … or … ??

No one can debug your own personal installation. Only you can.

Like this for instance is one command I have:

vizio_directv: >
    curl -k -H "Content-Type: application/json" -H "AUTH: {{auth}}" -X PUT -d '{"REQUEST": "MODIFY","VALUE": "hdmi1","HASHVAL": 2023834057}' https://{{ip}}:{{port}}/menu_native/dynamic/tv_settings/devices/current_input

Works perfect. executes curl to send a JSON package to all my televisions to set the input. The auth code, IP and Port are different for each TV so they are parameters.

I would not expect that anyone could “debug” this unless they have the exact same TVs as me.

I understand that.
I want to know only if the below commands are fine to execute for TCP remote device and then i will debug what is going wrong.Now with the below command i don’t have any errors and this is worst because its difficult to find the issue.

  - platform: command_line
        command_on: 'echo -ne "#|M001|F001|SV01|40|U|\r\n" | nc 5001'
        command_off: 'echo -ne "#|M001|F001|SV01|60|U|\r\n" | nc 5001'

How i can debug this command and where can i see the result?
It makes sense το see the verbose from the tcp command and where can i see the debug result?

Can’t you see what’s coming into your “matrix”?

No, I can’t see the command if reaches the matrix. I understand if the command works from the result.

I have created a TCP sensor for the matrix and i see the answers of the matrix.I understand that the command doesn’t leave the HA with the appropriate way or doesn’t go away at all because i don’t take the expected answer.

With the below i can send commands. The difference from the tool is that you have to click connect (The socket stays open until you close it manual from the disconnect button) and then to send the value which is “#|M001|F001|SV02|0|U|\r\n”. I dont understand why it doesnt works frtom HA. I have worked before with udp commands and works immediately and now with tcp doesnt work at all.
Can anyone give me some help for this issue?
Below some information from the matrix Manual.

The TCP/IP port accepts the commands at port 5001.
All TCP/IP answers returned by the M2 are followed with 0x00.
Command overview
Example: Set volume M001 zone 1 to -30dB
ASCII #|M001|F001|SV1|30|55b8|return
HEX 237C4D3030317C463030317C5356317C33307C363338307C0D0A
- Return = 0x0d 0x0a
The ‘return’ at the end of a command is always a carriage return followed by a line feed.
In hexadecimal representation this is ‘0x0D 0x0A’ (0x0d is carriage return, 0x0A is line
feed). When sending the commands in ASCII, this should be sent as a <CR> <LF>.

Maybe something line this? Depends on what namespace you are using:

  default: error
    homeassistant.components.switch: debug
    homeassistant.components.command_line: debug

Since you are creating template switches, do they even show up developer tools?
I think you are combining two things into one. Read here:

There is no such thing as command_on (there is turn_on).
And it’s an action … so you call a script, you don;t put the actually command there.

What I do is to create a shell_command.
Then I create a script and test it and look at the traces in the script tool.
Then (if needed) I create a switch whose turn_on and turn_off are in the script that calls the shell_command.