I have had a chance to look at this and i still cant see how this is going to send a command to one of the amps? Any chance of a example please? Thank you for any help or direction.
Now you need to customize that line in order for it to work with your system.
Replace 192.168.1.100 with your NetAmp’s IP address.
Optionally replace set_1src1 with whatever you prefer to call this shell_command.
Restart Home Assistant in order for it to load the new shell_command.
Testing the new shell_command
Go to Settings → Developer tools → Actions
Select shell_command.set_1src1 from the list and click the “Perform Action” button.
If the command executed properly, the Response will look like this:
stdout: ""
stderr: ""
returncode: 0
If the command failed, the Response will contain error information.
Assuming no errors, confirm the NetAmp performed the desired action.
If the test confirmed shell_command.set_1src1 worked properly, you can now use it in a Button’s tap_action (like tom_l suggested).
NOTE
nc is an abbreviation for the netcat command. Among other things, it can transmit text to a desired IP address and port.
echo is used to send text to nc. Normally it doesn’t append a carriage return to the end of the text, only a newline (line-feed). However, the PDF file you linked says the command must terminate with carriage return and line-feed. So we use echo -e and append \r\n to the text which instructs echo to include a carriage return \r and a newline \n.
Just another quick question. Can i create a device (For Example) with the IP address and port then list all the commands under that device then link buttons to the commands.
For example:
Net Amp 1:
IP address: 192.168.1.*
Port: 9760
Commands Zone 1
$S1SRC1\r\n
$S1FAV1\r\n
etc.
Commands Zone 2
$S2SRC1\r\n
$S2FAV1\r\n
etc.
Or is there a device that is similar that i could reverse engineer ? (Yikes, shhhhhh)
Just so you know, my end goal is to have a touch panel in each room of the house which will enable me to control, Audio. CCTV, Heating, Lighting and much more.
Device (and Entities) have specific meanings in Home Assistant.
It is certainly possible to develop a new integration for HA which may expose your amp as a set of Entities and Devices, however the level of effort in creating such an integration depends upon your experience with software development, assuming for a moment you have a engineering background, you can either do:
A python integration - which would load directly into HA.
An MQTT integration - which allows you to code in any language.
If you don’t have a software background, you may want to start with something simpler such as using a script, you can stuff all the details of the commands into the script - basically one big choose block with an option for each command.
Then whenever you want to send a command you just invoke the script and pass in the command your want to send.
If that sounds … adventurous … I might suggest starting with the Lighting as that will get you more familiar with HA - once you are comfortable with the basics then loop back to this job.
Did you try what I suggested 3 days ago? Did it work?
A shell_command is the easiest way of transmitting a payload via TCP/IP. Make several and use them with various Button cards, or similar cards, for a touchscreen UI.
Not yet, its on my list to try this weekend, What you suggested looked like i had to put the IP address and port number before each command, I was just thinking there my be away of listing the commands then linking to them.
Home Assistant offers only one easy way to transmit a command via TCP/IP and it’s via a shell_command.
Each shell_command is configured via YAML. The documentation indicates you can use templates in a shell_command in order to make its configuration dynamic (i.e. portions of the shell_command can be based on other information in Home Assistant).
However, as always, the devil is in the details. Restrictions come into play if templates are employed. One of those restrictions affects the use of the command I suggested. From the documentation:
The commands can be dynamic, using templates to insert values for arguments. When using templates, shell_command runs in a more secure environment which doesn’t allow any shell helpers like automatically expanding the home directory character (~), using pipe symbols (|) to run multiple commands
The easiest way to avoid this restriction is to simply predefine each NetAmp command as a separate shell_command.
The alternative is to create a shell script that accepts a variable. This will circumvent the restriction mentioned above.
The shell script contains the command I posted above except the part containing $s1src1 is changed to accept a passed variable.
You define a single shell_command that calls the shell script and passes it whatever NetAmp command you dynamically assign it.
If all of this is gibberish, but you still want to pursue it, then you will need to learn about creating shell scripts.
Anyways, first step is to perform the test I suggested in my first post to confirm the shell_command works properly.
Yeah im not a expert at code, but can usually work it out via trial and error. Looks like it will be predefined commands. All the net amps have static IP addresses so this wont be a issue.
Thank you for your help. I will hopefully get to test all of this this weekend. Will let you know how it goes.
Okay had 5 mins to at lesst find the configuration.yaml file using SAMBA but there is not much text in the file so im not sure i am looking at the correct one. All i see is:
Okay so i bit the bullet and went for it any way. As suggested i added:
set_1src1: “echo -e ‘$s1src1\r\n’ | nc 192.168.1.251 9760”
The comand executed correctly and i got the response as you suggested:
stdout: “”
stderr: “”
returncode: 0
However the NetAmp did nothing still on standby. I will check the commands later using putty and update.
Although these are sent over the network, presume its the same process for RS232 then and you might be suggesting it needs to be converted into some sort of Hex format looking at UART?
Anyway, have now confirmed that the commands work with Putty perfectly and i get responses from the NetAmp after each command is sent. So something i am doing is not right. Tried it without a CR/LF just incase, still nothing from the NetAmp.