Command_line switch yaml setup help

Could somebody please help resolve this command entry?

I have setup ssh key and I can execute the command from within HA using the terminal program window, login to root on remote machine and this command works perfectly: ubus call poeman set ‘{“port”:“lan2”,“enable”:FALSE}’

When I add the following to yaml, it flags errors. I’m struggling with the single quotes and double quotes which I need to keep within the command section too.

ommand_line:
  - switch:
      name: TSW202_Port_8_PoE
      command_on: "ssh [email protected] -i /config/.ssh 'ubus call poeman set '{"port":"lan8","enable":TRUE}'"
      command_off: "ssh [email protected] -i /config/.ssh 'ubus call poeman set '{"port":"lan8","enable":FALSE}'"

The error: Cannot read a block mapping entry; a multiline key may not be an implicit key, unexpected end of the stream within a double quoted scaler

Many thanks in advance.

Hi, maybe this helps, it’s one of my switch commands

command_on: ssh -i /config/.ssh/id_rsa [email protected] "pct start 101"

Nick, thank you so much for the prompt response. I’m getting somewhere now. The device shows up in HA with a switch but does nothing. The entity just provides a greyed out switch.

command_line:
  - switch:
      name: TSW202_Port_8_PoE
      command_on: ssh -i /config/.ssh/id_rsa [email protected] "'ubus call poeman set '{"port":"lan8","enable":TRUE}'"
      command_off: ssh -i /config/.ssh/id_rsa [email protected] "'ubus call poeman set '{"port":"lan8","enable":FALSE}'"

Thanks.

Hi all, I need some help please. the text in the post above is what I currently have which create a device in HA. This provides a non-functional switch - it does nothing and doesnt send the command, could somebody please help correct the string to send? This will turn PoE on and off of a Teltonika TSW202 network switch.

The next step would be to query the port regularly and so some method to parse the response from this command:
ubus call poeman get ‘{“port”:“lan2”}’

Example output when no PoE device is connected:
{
“port_state”: 0,
“class”: “Unknown”,
“current”: 5,
“voltage”: 0
}
When the PoE device is connected to the switch you will see the details:
{
“port_state”: 1,
“class”: “1”,
“current”: 15,
“voltage”: 50
}

Many thanks.

First, try to do it manually over SSH to find the right syntax.
I guess the switch has direct SSH access: try it there, then from your HA console.

Hi Nick,
I have found the command won’t run from the shell (?) but if I ssh within terminal to the router - which it does seamlessly without pausing - the commands work fine. So I believe I need to execute this command (docker exec -it homeassistant bash) from within the terminal but I cannot find how to do that without errors.
I keep reading about turning off ‘protection’ but can’t find that anywhere, but I am running advanced mode for a long time, which I think might have replaced protection mode.
Thanks.

I can now run the command from Terminal - I had the incorrect terminal addon in HA with the same name.

I’m now able to run the docker exec bash command but still can’t find the right syntax for the string, probably sue to repeated single quotes in the command to send.

Using the terminal window within HA, I can enter: ssh -i /config/.ssh [email protected] and the connection is made with the device leaving a device command prompt. If I then enter this command: 'ubus call poeman set '{“port”:“lan2”,“enable”:TRUE}’
The device responds as it should, everything works. If I put the two strings together I get various responses depending on where I put double or single quotes such as "syntax error: unterminated quoted string, or just 'quote> prompt but no results.

Could anybody correct this string please?
ssh -i /config/.ssh [email protected] ‘ubus call poeman set '{“port”:“lan2”,“enable”:TRUE}’

Thanks.

Okay, you got a little further but sorry man, can’t help you.