Hi,
I’m new to Home Assistant and ran into the following problem. I got lots of google results but no one helped.
I need to send a udp command to netcat via shell_command. That works fine:
I don’t get the point. What is wrong with this code?
The udp command parser is quite simple. It is important to have the cmd exactly as shown above (space, carriage return, etc.)
Can someone help?
See if you can put your shell command into a script with parameters and then call the script instead. You can start by SSH’ing to your HA system and writing a script file that works properly (I use config/scripts for that), once it works in script then your command is just calling the script with args that does what you want.
Start with seeing if the script will everything hard coded works from SSH by itself:
led.sh:
echo -e led 2 0\r | nc -u 192.168.0.109 10000
then:
chmod 0755 led.sh
finally:
./led.sh
If that works as expected, try it with variables:
echo -e led $1 $2\r | nc -u 192.168.0.109 10000
And call with:
./led.sh 2 0
And if all that does as planned then you change your shell command to something like this:
I’ve also spend hours on this, to no avail. Tried everything from escaping double quotes to building the entire shell command line in an input string and sending it to the shell command; quite annoying that this is not working; now I have to use eight different shell commands (fully written out) to get very inflexible functionality; for each new device I have to add many more.
Pretty useless, this quick-and-dirty integration, if one has no freedom to specify a command at the higher level.
I think the alternative is to write my own python code to do this simple trick properly.
What exactly are you trying that doesn’t work? I use shell command quite a bit, from executing a local script to SSH’ing to a different computer to issue commands there - all with command line options. To say it’s useless is a blanket statement that doesn’t seem accurate to me, perhaps the problem is more in how you are trying to implement rather than how HA does its job.
Sorry, I got a bit frustrated… I finally managed to use it, once I figured out how to properly format the yaml in order to output multiple lines to the telnet of my router.
But I still have to find out if / how you can pass parameters to these lines, or how to receive any returned data.
For anyone with the same questions, this is how I send several commands to my Draytek 2927 router: