Zyxel-NSA310-Home-Assistant Monitoring

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