Zyxel-NSA310-Home-Assistant Monitoring

Hi, I’m sharing my python script to grab data from a Zyxel NAS(NSA310) and display it in Home Assistant.
Please take a look: GitHub - floringhimie/Zyxel-NSA310-Home-Assistant

Thank you!

2 Likes

Very interesting!
I have a a zyxel 540, but your script doesn’t work properly :pensive:
I tried to login directly via URL to test initial string, but no way :man_facepalming:t3:

Can you send me some print screens?
Maybe I can help you.

thk u @fory1 !

first i tested this string:

http://192.168.1.130/r51209,/adv,/cgi-bin/weblogin.cgi?username=XXX&password=YYY

and

http://192.168.1.130/r51209,/desktop,/cgi-bin/weblogin.cgi?username=XXX&password=YYY

but the result is:

({errcode:9})

But it’s fine. Result 9 it is a success login.
Keep going with the second request.

Try it from a browser that you are already connected via web interface (active login session) http://192.168.1.130/r51209,/adv,/cgi-bin/zysh-cgi?c0=show cpu temperature&write=0&c1=show mem status&c2=storage showIVolumeInfo&c3=show cpu status

this is the answer:

Not Found
The requested URL /r51209,/adv,/cgi-bin/zysh-cgi was not found on this server.

in Chrome DevTool i sniffed this url:

http://192.168.1.130/cmd,/ck6fup6/system_main/show_sysinfo?_dc=1

and this is the result litteraly:

{"system": {"status": {"sysStatus": "healthy", "speed": 882, "temp": 41}, "storageStauts": "Healthy", "modelName": "NAS540", "users": 2, "process": [{"cpu": 32.142857142857146, "name": "python", "memory": 147181568}, {"cpu": 0.0, "name": "ifplugd", "memory": 2707456}, {"cpu": 0.0, "name": "watchdog", "memory": 2572288}, {"cpu": 0.0, "name": "ifplugd", "memory": 2707456}, {"cpu": 0.0, "name": "httpd", "memory": 22888448}, {"cpu": 0.0, "name": "smbd", "memory": 26660864}, {"cpu": 0.0, "name": "ubifs_bgt3_0", "memory": 0}, {"cpu": 0.0, "name": "hd-idle", "memory": 1794048}, {"cpu": 0.0, "name": "target_completi", "memory": 0}, {"cpu": 0.0, "name": "LIO_rd_mcp", "memory": 0}], "upsPowerLeft": "N/A", "firmware": "V5.21(AATB.7)", "backupStatus": "none", "webSessions": [{"group": [], "service": "Web", "ip": "192.168.1.200", "pid": "", "w/n": "LAN", "user": "admin", "time": ["0", "0:12:57"], "type": ["admin"], "authtok": "hM7beV41744Pf85i-GlfXTSavUi3bx0nVqb+yL85tqNPt4byJ8-Hd1WVusvZ1SV5"}, {"group": [], "service": "Web", "ip": "192.168.1.200", "pid": "", "w/n": "LAN", "user": "admin", "time": ["0", "0:07:57"], "type": ["admin"], "authtok": "OMPtTp5ORIQRd2OMMjTBY5ac7J2aQ5ZvSHmkzjjK1TV3Ph2vxOWNvscLsRlO0iBQ"}], "storageDetail": {"Available": 127598, "Misc": 42568, "Photos": 92785, "Music": 125420, "Video": 55224, "Packages": 33333}, "mac": ["5C:F4:AB:5B:E9:A6", "5C:F4:AB:5B:E9:A7"], "connSpeed": {"download": "1.4 KB/s", "upload": "0.1 KB/s"}, "memory": {"usage": "16 %", "used": "166 MB", "size": "987 MB", "time": "08:47:14"}, "serverName": "Giammy_NAS", "cpu": {"usage": "14 %", "time": "08:47:14"}}}

:face_with_monocle:

Hi, Please try this script.
https://github.com/floringhimie/Zyxel-NSA310-Home-Assistant/blob/4da6d22d04993c58566cd1e72b6a08c634cadd5b/nsa540_get_info.py
I did not test it in real node but let’s hope it will work.
The output should look like:

{ "cpu_usage": "14", "cpu_temp": "41", "mem_usage": "16", "hdd_avail": "127598", "hdd_used_misc": "42568", "hdd_used_photo": "92785", "hdd_used_music": "125420", "hdd_used_video": "55224", "hdd_used_package": "33333", "hdd_health": "healthy" }
1 Like

yes i do, as you report!
Perfect!

also the sensor woks like a char now!

THKS @fory1 !!!

Thx for sharing your work. I’ve a 540…

A small feedback to your code (if I get it right):

python3 /config/python_scripts/nsa310_get_info.py $IP $USERNAME $PASSWORD
try:
    response_login = ses.get('http://192.168.0.110/r49435,/adv,/cgi-bin/weblogin.cgi?username='+str(sys.argv[1])+'&password='+str(sys.argv[2]))

The IP Adress is fixed in your pyhton? And the Arguments will not fit?

I’m new to HA. Is it possilbe to use secrets.yaml?

python3 /config/python_scripts/nsa310_get_info.py !secret IP !secret UN !secret PW

Ah and it’s a “Network Attached Storage” = NAS :yum:

NSA is someone else :rofl: :rofl: :rofl: :rofl:

Hi! Yes my bad, initially was design with 3 arguments ip+user+pass but after one update in GitHub I miss the first argument.
I fix the cod in GitHub.
For your NSA540 it is a dedicated Python file also, and yes you can use the secrets in python command.

Tx!

Well,
so far i understand the script (well I changed naming from nsa310 to nas542), but somehow I’m not getting data:

If I call the url “/cmd,/ck6fup6/system_main/show_sysinfo?_dc=1” manually I’ll get the jason data:

According to the Server Logs of my NAS the Login is fine.

Is here a possibility to write debug messages from the python file to the log file? I’m using Home Assistant Blue HW

Hi,
I can help you with this one.
First of all let me tell you how you can test your script without restarting HA and getting all the errors.
Install the ssh add-on from the library and then access the add-on page and type the command like this: python3 /config/python_scripts/nsa542_get_info.py $IP $USERNAME $PASSWORD


Then try to change the script and print the request output by adding print(response_login.text) on line 13 and print(response.text)
on line 16.
If the login is OK the print will display 9.
The second print should print the JSON that you get from the inspect page.

If yes(letter 9 is printed and the JSON also) then remove the print(response_login.text) and print(response.text) and we can analyze the output and adjust the parsing logic.
If no, please tell me what is the output that you get.

Thank you!

Ok, thanks for your support. Well, I guess I have a basic understanding problem how HA is working :flushed:

If I open the terminal I can’t run python:

After “installing” python I can run the script but it fails:

I also have the VSCode AddOn installed: If i use the python debugger the response is: {}

After rebooting the host system, the python installation is gone. So it’s a Supervisor / Docker thing?

Just quite new to HA. Is there a good tutorial about this?

Well, still trying to monitor my Zyxel NAS. I had some findings:

  • python script can’t import librariies

therefore i try HACS with pyscript, seems to be possible, but still struggling with this.

BUT:
would it be possible to use REST?

So far, it should be possible to login and parse jason just useing a rest sensor?

Can someone assist. Would be great!

THX

hello, I have a NAS-310 and I turn it on remotely with a switch (switch in configuration.yaml)

switches:
## https://www.home-assistant.io/components/switch.wake_on_lan/
   - platform: wake_on_lan
     name: NAS Zyxel
     mac: 50:67:F0:XX:XX:XX
     guest: 192.168.50.182

My question is how to set it to turn off? I know that it has that option in the web interface.
Thank you

Hello.
I want to ask for help. I do not speak English well.
I have a Zyxel NSA 325v2 NAS that I would like to monitor in HA.
With this: http://192.168.65.11/r51009,/adv,/cgi-bin/zysh-cgi?c0=show cpu temperature&write=0&c1=show mem status&c2=storage showIVolumeInfo&c3=show cpu status I can retrieve some data. I get this back: ({
zyshdata0: [
{’_CPU_temperature’:’+46.00 C’}
],
errno0:0,
errmsg0:‘OK’,
zyshdata1: [
{’_memory_size’:‘498MB’,’_memory_used’:‘68MB’,’_memory_usage’:‘13%’}
],
errno1:0,
errmsg1:‘OK’,
zyshdata2: [
{’_VolName’:‘Disk’,’_Devnode’:’/dev/md0’,’_VolType’:‘raid1’,’_VolState’:‘healthy’,’_TotalSpace’:‘960925088’,’_Unit’:‘KB ‘,’_UsedSpace’:‘357700056’,’_Unit’:‘KB’,’_FilesystemType’:‘ext4’,’_DiskNames’:‘disk1 disk2’,’_Mountpath’:’/i-data/5ef68e83’}
],
errno2:0,
errmsg2:‘OK’,
zyshdata3: [
{’_CPU_utilization’:‘0 %’}
],
errno3:0,
errmsg3:‘OK’
}) Unfortunately, the sensors are still in an unknown state.
How should it work?

Hello,
I can use some help too, I can’t get sensors for NSA310 working.
In ssh I figured out that the import requests wasn’t working and am not able to do the pip install for it is not allowed as root.
I have tried to run the NSA310 python script and can see the the values of my NSA310.
I am also struggling with the command_line options since recent changes.
So I have now:
/config/python_scripts/nsa542_get_info.py as described

a command_line.yaml with:
sensor:
name: nsa310
json_attributes:
- cpu_usage
- cpu_temp
- mem_usage
- hdd_usage
- hdd_health
command: python3 /config/python_scripts/nsa310_get_info.py 192.168… user password
value_template: ‘{{ value_json.cpu_usage }}’
unit_of_measurement: “%”
scan_interval: 60
and in /config/configuration.yaml command_line: !include command_line.yaml

Can anybody help me to sort this out ?

Error is: No module named ‘requests’.
Don’t know type of installation you using, but ‘import requests’ not working because module not installed in python.