TCP Commands From HA To Audio Matrix

Hello,
Thank you for your support.
I run the commands.
I don’t have any error at the log.
Below the terminal.
image
Also I try to see the answers from matrix as you can see below.
image

If you have a command working, but not working from shellcommand, you can always put it in a bash file and run the bash instead? Or maybe a python script

Can you show my how to do it with a python script. But I have to manage lots of commands, it will be more difficult with script and more complex ?
Otherwise with shell command and switches on/off we don’t have any hope ?

All my lights and plugs are based on NC commands, I have all of them configured as template light/switches… They just use 1 single Bash script, but I use variables for the turn on/off command…

I can post later, not at home right now

Hello,
Can you send me an example with python script to send my commands to understand how to this works. I don’t how I can use the script. I work only with shell commands so far.

I’ll try to send later today, on vacation, so limited time :slight_smile:

Hey, here is my old config, i have template lights, that send 3 variables, yiu can see the $1 , $2, $3 in the sh script

    keukeneiland:
      friendly_name: "Keuken Eiland"
      value_template: "{{ state_attr('sensor.nc', '4104') == '01' }}"
      turn_on:
        - service: shell_command.nc
          data_template:
            module: 41
            id: 04
            power: 01
      turn_off:
        - service: shell_command.nc
          data_template:
            module: 41
            id: 04
            power: 00

This is the shell command in HA:

nc: bash /config/nc.sh {{module}} {{id}} {{power}}

place the nc.sh file in the config folder, below is the content of the nc.sh file where i use at the end of the echo the 3 variables

#!/bin/bash
echo -e "\xED\x43\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xAF\xAF\x"$1"\x"$2"\x"$3"" | nc 192.168.0.10 1001

Thank you very much.
Can you make an example with my 2 commands to make a test because i don’t have used before script. And tell me the steps where to to what?
Sorry about at but i want to bee 100% sure that i will not make mistakes at the configuration.

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

Hi, I gave my example, just copy paste it, and just use 1 variable, for example the “power” for $1. The content for you will be “40” or “60” for $1

Try it and paste your code, I have limited access to my laptop

How to use this template without sensor?
Where to put the below command ,this is the correct syntax? Sorry for my questions but as i said to you i don’t have worked again with this logic.

nc: bash /config/nc.sh {{module}} {{id}} {{power}}

That command is the shell command… Instead of firing the command directly, you run a script (bash) file, the command is in the content of that file

The sensor you mean for value template? You don’t need it, just skip it…

Try to write it, I can help later if you don’t succeed

Well,

I have save the nc.sh at config/ folder.
Inside i have the below command

#!/bin/bash
echo -e "#|M001|F001|SV01|"$1"|U|\r\n"  | nc 192.168.168.202 5001

At configuration.yaml i have the below template and shell command.

shell_command:
  nc: bash /config/nc.sh {{volume}}

 


  - platform: template
    switches:
       test1:
        friendly_name: "test1"
        turn_on:
          - service: shell_command.nc
            data_template:
                volume: 0
        turn_off:
          - service: shell_command.nc
            data_template:
                volume: 50

I turn off and on the switch but nothing happens.
The bellow error i think is creatyed because i run the shell_command without value. From the template switch nothing happens.

Logger: homeassistant.helpers.template
Source: helpers/template.py:563
First occurred: 6:49:27 PM (1 occurrences)
Last logged: 6:49:27 PM
Template variable warning: 'volume' is undefined when rendering '/config/nc.sh {{volume}}'

Your sh file , looks correct, test that first from an SSH terminal
then do:

bash /config/nc.sh 50

or what ever volume you want

for your switch:
also think its best to quote the volume like “50”
maybe also the make the value template to "false, not sure if its mandatory

your command looked good, maybe it was failing cause you were sending 0 without quotes
not sure

- platform: template
  switches:
   test1:
     value_template: "false"
     turn_on:
       - service: shell_command.nc
         data_template:
           volume: "0"
     turn_off:
       - service: shell_command.nc
         data_template:
           volume: "50"

I make the changes.
Doesnt happen anything.
Without the value_template:“false”
The button goes from on to off without any result, when i add the value false. When i turn on the button auto goes to off position.
I dont’ have any error at the log.
Any suggestion please?

The value $1 is correct at echo?
And how the system knows that the {{volume}}=$1?

It’s an argument

Have you tried the command from ssh like I asked? That needs to work first

I didn’t make it work from ssh add on as you can see at my older posts.

Then I don’t know :frowning:

Hello,

Thank you for your support.
If anyone else have an idea about why this happens only with TCP please to reply!
It’s very important for me to accomplish this task!