The Zyxel NWA50AX Pro has a command line interface available via ssh. Go to the support page for your model and download the CLI Reference Guide.
Using the Command Line integration, you can send commands using ssh e.g.
echo -e 'enable\nshow cpu status\nexit' | sshpass -p 'PASSWORD' ssh -o StrictHostKeyChecking=no -tt USER@HOST
There are a number of issues with Zyxel’s implementation of ssh, or perhaps my code.
Only interactive sessions are allowed, hence using echo to pipe the command to ssh.
I have not found a way to load ssh certificates onto the device and needed to use sshpass. See Add sshpass to the supervised / docker container to add sshpass to the HA docker container and Use apt-get commands to to install it after Home Assistant is updated.
These are the command line sensors I have:
command_line:
# nwa50axpro
- sensor:
name: nwa50axpro cpu usage
command: echo -e 'enable\nshow cpu status\nexit' | sshpass -p 'PASSWORD' ssh -tt -o StrictHostKeyChecking=no USER@HOST | awk '/CPU utilization:/ {print $3}'
unit_of_measurement: "%"
unique_id: nwa50axpro_cpu_usage
scan_interval: 60
- sensor:
name: nwa50axpro memory usage
command: echo -e 'enable\nshow mem status\nexit' | sshpass -p 'PASSWORD' ssh -tt -o StrictHostKeyChecking=no USER@HOST | awk '/usage/ {print substr($3, 1, length($3)-1)}'
unit_of_measurement: "%"
unique_id: nwa50axpro_memory_usage
scan_interval: 300
- sensor:
name: nwa50axpro storage free
command: echo -e 'enable\nshow disk\nexit' | sshpass -p 'PASSWORD' ssh -tt -o StrictHostKeyChecking=no USER@HOST | awk '/onboard flash/ {print (1 - (substr($5, 1, length($5)-1) / 100)) * $4}'
unit_of_measurement: "MiB"
unique_id: nwa50axpro_storage_free
scan_interval: 3600
- sensor:
name: nwa50axpro storage usage
command: echo -e 'enable\nshow disk \nexit' | sshpass -p 'PASSWORD' ssh -tt -o StrictHostKeyChecking=no USER@HOST | awk '/onboard flash/ {print substr($5,1,length($5)-1)}'
unit_of_measurement: "%"
unique_id: nwa50axpro_storage_usage
scan_interval: 3600
- sensor:
name: nwa50axpro uptime
command: echo -e 'enable\nshow system uptime\nexit' | sshpass -p 'PASSWORD' ssh -tt -o StrictHostKeyChecking=no USER@HOST | awk '/system uptime:/ {if ($4 =="days") print $3 ; else print "0"}'
unit_of_measurement: "days"
unique_id: nwa50axpro_uptime
scan_interval: 3600
A nice feature is the ability to upload scripts of commands to the NWA50AX Pro. I use this script to switch off all Wi-Fi the device.
# WiFi off (wifioff.zysh)
configure terminal
wlan slot1
no activate
exit
wlan slot2
no activate
exit
exit
And run it with this command:
echo -e 'enable\nrun /script/wifioff.zysh\nexit' | sshpass -p 'PASSWORD' ssh -tt -o StrictHostKeyChecking=no USER@HOST
Alternately there is the python library netmiko, a multi-vendor library to simplify CLI connections to network devices. You can use it like this:
from netmiko import ConnectHandler
connection = ConnectHandler(host='HOST', port='22', username='USER', password='PASSWORD', device_type='zyxel_os')
output = connection.send_command('show cpu status')
print(output)
print('Closing Connection')
connection.disconnect()