I need to create a switch that will interact with my Draytek router. Basically I need to log in to router using SSH or Telnet and execute some CLI command. Since operating system of router is not based on Linux kernel, but is proprietary solution, I had to rule out using key based security, only user/password is accepted. More over, since terminal session is script based, inline parameters for sshpass are not accepted, so the only solution seems to be by executing shell scripts and create command_line with. So far I have:
Command line switch:
command_line:
- switch:
name: router_rdp
command_on: "/config/scripts/draytek_on.sh"
command_off: "/config/scripts/draytek_off.sh"
command_state: "/config/scripts/draytek_status.sh"
value_template: >
{{ 'Enable' in value }}
and set of relevant scripts:
rdp_on.sh:
#!/usr/bin/expect -f
set timeout 2
spawn telnet 192.168.52.1
expect "Username:"
send "admin\r"
expect "Password:"
send "password\r"
expect ">"
send "srv nat openport 1 1 -a 1\r"
expect ">"
send "exit\r"
expect eof
rdp_off.sh:
#!/usr/bin/expect -f
set timeout 2
spawn telnet 192.168.52.1
expect "Username:"
send "admin\r"
expect "Password:"
send "password\r"
expect ">"
send "srv nat openport 1 1 -a 0\r"
expect ">"
send "exit\r"
expect eof
and rdp_stat.sh:
#!/usr/bin/expect -f
set timeout 2
spawn telnet 192.168.52.1
expect "Username:"
send "admin\r"
expect "Password:"
send "password\r"
expect ">"
send "srv nat openport 1 1 -v\r"
expect ">"
send "exit\r"
expect eof
Scripts are executable and I can manually execute them from SSH and Terminal addon and they work as expected and produce proper output. Unfortunately the switch, though created, does not work and I see relevant errors in log file:
2025-10-05 19:38:48.449 ERROR (MainThread) [homeassistant.components.command_line] Error trying to exec command: /config/scripts/draytek_on.sh
2025-10-05 19:38:48.449 ERROR (MainThread) [homeassistant.components.command_line] Command failed: /config/scripts/draytek_on.sh
2025-10-05 19:38:48.452 ERROR (MainThread) [homeassistant.components.command_line] Command failed (with return code 127): /config/scripts/draytek_status.sh
What is wrong here? I suspect that problem is related to executing these scripts from SSH & Terminal container vs. core container… but I’m not sure. Can this be fixed somehow, given the limitations I have?