Zyxel-NSA310-Home-Assistant Monitoring

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.

I understand but this is what I get and refuses to install requests as root

You should provide HA installation type. It’s hard to guess.

Home assistant OS direct on sdcard as instructed on de has site on PI 4

You can try following How to import from package not installed on hassio

Thanks for your patience and reply but i have little knowledge of python and the only thing i understand is to create the package folder and to put the nsa310 py script into it. The rest is a mystery for me.

As I see from screenshots:

  1. it must be python3 not python when running python scripts.
  2. IP address, username and password should be in in python script, but not in command_line.yaml.

I finaly managed to get it working.
The copied Yaml code didn’t work but with try and error and some modification it suddenly worked.
Thanks for the reply !

This solved my problem:
#sensors.yaml

  • platform: template
    sensors:
    cpu_temp:
    friendly_name: ‘NSA310 CPU Temp’
    value_template: ‘{{ states.sensor.nsa310.attributes.cpu_temp }}’
    unit_of_measurement: “°C”
    mem_usage:
    friendly_name: ‘NSA310 Memory Usage’
    value_template: ‘{{ states.sensor.nsa310.attributes.mem_usage }}’
    unit_of_measurement: “%”
    hdd_usage:
    friendly_name: ‘NSA310 HDD Usage’
    value_template: ‘{{ states.sensor.nsa310.attributes.hdd_usage }}’
    unit_of_measurement: “%”
    hdd_health:
    friendly_name: ‘NSA310 HDD Health’
    value_template: ‘{{ states.sensor.nsa310.attributes.hdd_health }}’

#command_line.yaml
sensor:
name: nsa310
json_attributes:
- cpu_usage
- cpu_temp
- mem_usage
- hdd_usage
- hdd_health
command: python3 /config/python_scripts/nsa310_get_info.py $ip $user $password
value_template: ‘{{ value_json.cpu_usage }}’
unit_of_measurement: “%”
scan_interval: 60
and the python yaml as instructed.

Hi, on my 540 with Firmware V5.21(AATB.11) (r51266) none of the cgi´s (show_sysinfo/zysh-cgi) works for me. Has someone a solution? or can someone describe how to discover the right cgi-string ?

My 540 NAS working no issues.

nas

nas1

OK Thanks, for your answer, the CGI via Browser ist now working but the sensors gettting no data, what i see is this:
[core-ssh homeassistant]$ cat home-assistant.log | grep 540
2024-03-01 09:39:43.692 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: ‘None’ has no attribute ‘attributes’ when rendering ‘{{ states.sensor.nas540.attributes.cpu_temp }}’

any suggestions `?

How you obtain info from NAS540?
I’m using python script to get all info.
Based on output you provided sensor.nas540 doesn’t have any attributes.

Hi,
i have created and edited the Pyhton script: python_scripts/nsa540_get_infp.py

#!/usr/bin/python3
import requests
import re
import math
import time
import json 
import sys

ses = requests.session()
try:
    response_login = ses.get('http://'+str(sys.argv[1])+'/r51266,/adv,/cgi-bin/weblogin.cgi?username='+str(sys.argv[2])+'&password='+str(sys.argv[3]))
    parse_login= response_login.text.split(':')[1].replace('}', '').replace(')', '')
    
    if parse_login == '9':
        response = ses.get('http://'+str(sys.argv[1])+'/cmd,/ck6fup6/system_main/show_sysinfo?_dc=1')
        
        parse_json = json.loads(response.text)
        cpu_usage = str(parse_json["system"]["cpu"]["usage"].replace('%', '')).strip()
        cpu_temp = str(parse_json["system"]["status"]["temp"]).strip()
        mem_usage = str(parse_json["system"]["memory"]["usage"].replace('%', '')).strip()
        hdd_avail = str(parse_json["system"]["storageDetail"]["Available"]).strip()
        hdd_used_misc = str(parse_json["system"]["storageDetail"]["Misc"]).strip()
        hdd_used_photo = str(parse_json["system"]["storageDetail"]["Photos"]).strip()
        hdd_used_music = str(parse_json["system"]["storageDetail"]["Music"]).strip()
        hdd_used_video = str(parse_json["system"]["storageDetail"]["Video"]).strip()
        hdd_used_package = str(parse_json["system"]["storageDetail"]["Packages"]).strip()
        hdd_health = str(parse_json["system"]["status"]["sysStatus"]).strip()
            
    print('{ "cpu_usage": "'+cpu_usage+'", "cpu_temp": "'+cpu_temp+'", "mem_usage": "'+mem_usage+'", "hdd_avail": "'+hdd_avail+'", "hdd_used_misc": "'+hdd_used_misc+'", "hdd_used_photo": "'+hdd_used_photo+'", "hdd_used_music": "'+hdd_used_music+'", "hdd_used_video": "'+hdd_used_video+'", "hdd_used_package": "'+hdd_used_package+'", "hdd_health": "'+hdd_health+'" }')

    headers = {
        'Content-Type': "application/x-www-form-urlencoded"
        }
    payload_data = "perform=logout"
    response_logout = ses.post('http://'+str(sys.argv[1])+'/r51266,/adv,/cgi-bin/setuser.cgi', data=payload_data, headers=headers)
except:
    print('{}')

i have created an edited an sensors.yaml:

- platform: command_line
  name: nas540
  json_attributes:
    - cpu_usage
    - cpu_temp
    - mem_usage
    - hdd_usage
    - hdd_health
  command: python3 /config/python_scripts/nsa540_get_info.py 192.168.xx.xx0 userx passwordx
  value_template: '{{ value_json.cpu_usage }}'
  unit_of_measurement: "%"
  scan_interval: 60
  
- platform: template  
  sensors:
    cpu_temp:
      friendly_name: 'NAS540 CPU Temp' 
      value_template: '{{ states.sensor.nas540.attributes.cpu_temp }}'
      unit_of_measurement: "°C"
    mem_usage:
      friendly_name: 'NAS540 Memory Usage' 
      value_template: '{{ states.sensor.nas540.attributes.mem_usage }}'
      unit_of_measurement: "%"
    hdd_usage:
      friendly_name: 'NAS540 HDD Usage' 
      value_template: '{{ states.sensor.nas540.attributes.hdd_usage }}'
      unit_of_measurement: "%"  
    hdd_health:
      friendly_name: 'NAS540 HDD Health' 
      value_template: '{{ states.sensor.nas540.attributes.hdd_health }}'

and finaly an command_line.yaml:

sensor:
name: nas540
json_attributes:
- cpu_usage
- cpu_temp
- mem_usage
- hdd_usage
- hdd_health
command: python3 /config/python_scripts/nsa540_get_info.py $ip $user $password
value_template: ‘{{ value_json.cpu_usage }}’
unit_of_measurement: “%”
scan_interval: 60

Add

      cpu_usage:
        friendly_name: 'CPU Usage' 
        value_template: '{{ states.sensor.nas540.attributes.cpu_usage }}'
        unit_of_measurement: "%"
      hdd_avail:
        friendly_name: 'HDD Usage' 
        value_template: '{{ states.sensor.nas540.attributes.hdd_avail }}'
        unit_of_measurement: "%"  

Add - hdd_avail to - platform: command_line

Use:
sensor.cpu_temp
sensor.cpu_usage
sensor.hdd_avail

Also

   - hdd_usage

exist only on your sensor, but not in python script, - platform: command_line and - platform: template