FreeNAS Stat Monitor

Hi!

I can confirm that it works with the latest TN release

1 Like

Hi! Can somebody help me get the Free Memory from the API? I am trying to get the information based on reporting.get_data, just as with the CPU temp, but I cannot get my head around the JSON part of it.

I guess I should extract the ā€œmemoryā€ graph which returns

  • memory-wired_value
  • memory-inactive_value
  • memory-laundry_value
  • memory-active_value
  • memory-free_value

But I am not able to get the values (or the aggregations) into the sensor.

Thanks!

With TrueNAS, a free memory report is pointless. The software is designed to use almost all of the installed memory.

1 Like

Hi there,

I have been following along with posts in this thread and I have found my self stuck on monitoring pool status. What I currently have is below. I am also quite confused on what /id/0 means I canā€™t seam to find out how to know what id I need. I have tried 0,1,2. I only have one volume currently on my nas.
When I add to the dashboard I get sensor.nas_pool_pct_used unavailable. If I use the entity sensor.nas_pool I get a 0

#Storage percentage
  - platform: rest
    name:  nas_pool
    resource: http://host/api/v2.0/pool/id/0
    username: XXXX
    password: XXXX
    headers:
      Content-Type: application/json
      User-Agent: Home Assistant
    value_template: '{{ value_json["status"] }}'
    json_attributes_path: '$.topology.data[0].stats'
    json_attributes:
      - allocated
      - size
    scan_interval: 1800
  - platform: template
    sensors:
      nas_pool_pct_used:
        friendly_name: "% Used"
        value_template: ' {{ (state_attr("sensor.nas_pool", "allocated") / state_attr("sensor.nas_pool", "size") * 100) | round(1) }} '
        unit_of_measurement: "%"

Hi @EthanDH ,

The /id/0 part depends on the TrueNAS api. Thereā€™s no easy way to figure out what id your pool has or where you have to pull the values that you want from. The best way is to explore the api with the command line (a few posts up the thread there is some info on that).

That said, the value takes a bit to populate, up to 30min, so not seeing it right away doesnā€™t necessarily mean itā€™s not working.

Does anybody know of an issue with the CPU temp reporting in TrueNAS Scale?
Iā€™m running TrueNAS-SCALE-22.02-RC.1-2

Below is the code block to be sure I didnā€™t mess anything up:

  - platform: rest
    name: tn_cpu_temp
    resource: http://192.168.1.176/api/v2.0/reporting/get_data
    headers:
      Authorization: !secret tn_api_key
      Content-Type: application/json
      User-Agent: Home Assistant
    device_class: temperature
    unit_of_measurement: 'Ā°C'
    scan_interval: 60
    method: POST
    payload: >-
      {
          "graphs":[{"name":"cpu"},{"name":"cputemp"}],
          "reporting_query":{"unit":"HOUR","page":0,"aggregate":true}
      }
    json_attributes_path: "$.[0]"
    json_attributes:
      - aggregations
    value_template: >-
      {% set tn = namespace(temp=0, cores=4) %}
      {% for core in range(0, tn.cores) %}
      {% set tn.temp = tn.temp + value_json[1].data[358][core] %}
      {% endfor %}
      {{ "%.1f"% (tn.temp / tn.cores) }}

And below is the error:

Template variable error: dict object has no element 1 when rendering '{% set tn = namespace(temp=0, cores=4) %} {% for core in range(0, tn.cores) %} {% set tn.temp = tn.temp + value_json[1].data[358][core] %} {% endfor %} {{ "%.1f"% (tn.temp / tn.cores) }}'

Everything else is working except for the CPU temp.

Thank you!

This thread has been absolutely amazing. I was able to get very nearly everything I wanted from TrueNAS displayed in Home Assistant. Big thank you to everyone before me that figured this all out before I even knew about it.

Has anyone figured out what unit Pool Allocated/Free is displayed in? My Pool has 1,222,115,803,136 allocated ā€œunitsā€. Somehow that works out to 2.77 TiB used.

I canā€™t figure out what the units returned from TrueNAS are. 2.77 TiB would be:

24,365,177,672,048 bits
3,045,647,209,006 bytes
2,974,264,852 kibibytes
23,794,118,820 kilobits

Perhaps it has something to do with duplication? My Pool has 3x 2TB drives and is using Z1, so the Pool holds ā…” data, ā…“ parity.

Bonus points if anyone figured out how to display used/free RAM using the V.2 API?

Did you ever get this resolved? I have the same thing going on. It seems to only being seeing the data from the first disc in the pool, which in my instance seems to have about 88% filled, while the actual entire pool is only about 74% full as shown in TrueNAS GUI and verified with the data in the curl. The first disc matches the 88% but when I add all of the discs up they equal about the same as the TrueNAS GUIā€¦ but as the figures size and allocated seem to sit at the same level with next to no additional identifiers I see no total of the pool just the individual discsā€¦ I guess in theory knowing the first / biggest disc is important, but itā€™s not the full pictureā€¦

If you happen to have gotten anywhere on getting things working it would be appreciated.

In case anyone is facing issue with this code and TrueNAS Scale I resolved my issue by editing code and it seams to be working without Hard drive Temp:

sensor:
  - platform: rest
    name: tn_info
    resource: http://192.168.0.9/api/v2.0/system/info
    verify_ssl: false
    headers:
      Authorization: !secret TrueNas_API
      Content-Type: application/json
      User-Agent: Home Assistant
    scan_interval: 3600
    value_template: '{{ value_json.uptime }}'
    json_attributes:
      - uptime_seconds
      - version
      - model
      - cores

  ## template sensors that extract state_attr
  - platform: template
    sensors:
      ## NAS Uptime seconds
      tn_uptime_seconds:
        friendly_name: "Uptime seconds"
        value_template: '{{ state_attr("sensor.tn_info", "uptime_seconds") }}'
      ## NAS Uptime seconds nice
      tn_uptime:
        friendly_name: "Uptime"
        value_template: >-
          {%- set uptime  = states('sensor.tn_uptime_seconds') | round -%}
          {%- set sep     = ', ' -%}
          {%- set TIME_MAP = {
              'week': (uptime / 10080) % 10080,
               'day': (uptime / 1440) % 7,
              'hour': (uptime / 60) % 24,
            'minute': (uptime % 60)
          }
          -%}

          {%- for unit, duration in TIME_MAP.items() if duration >= 1 -%}
            {%- if not loop.first -%}
              {{ sep }}
            {%- endif -%}

            {{ (duration | string).split('.')[0] }} {{ unit }}

            {%- if duration >= 2 -%}
              s
            {%- endif -%}
          {%- endfor -%}

          {%- if uptime < 1 -%}
            just now
          {%- endif -%}
      ## NAS Version
      tn_version:
        friendly_name: "Version"
        value_template: '{{ state_attr("sensor.tn_info", "version") }}'
      ## CPU model
      tn_cpu_model:
        friendly_name: "Model"
        value_template: '{{ state_attr("sensor.tn_info", "model") }}'
      ## CPU num of cores
      tn_cpu_cores:
        friendly_name: "Cores"
        value_template: '{{ state_attr("sensor.tn_info", "cores") }}'

  ## cpu temp version 2
  ## remember - set `cores=$num` in the value_template
  - platform: rest
    name: tn_cpu_temp
    resource: http://192.168.0.9/api/v2.0/reporting/get_data
    headers:
      Authorization: !secret TrueNas_API
      Content-Type: application/json
      User-Agent: Home Assistant
    device_class: temperature
    unit_of_measurement: 'Ā°C'
    scan_interval: 60
    method: POST
    payload: >-
      {
          "graphs":[{"name":"cpu"},{"name":"cputemp"}],
          "reporting_query":{"unit":"HOUR","page":0,"aggregate":true}
      }
    json_attributes_path: "$.[0]"
    json_attributes:
      - aggregations
    value_template: >-
      {% set tn = namespace(temp=0, cores=4) %}
      {% for core in range(0, tn.cores) %}
      {% set tn.temp = tn.temp + value_json[0].data[358][core] %}
      {% endfor %}
      {{ "%.1f"% (tn.temp / tn.cores) }}

    ## Alerts. Error if response is empty.
  - platform: rest
    name: tn_alert_level
    resource: http://192.168.0.9/api/v2.0/alert/list
    verify_ssl: false
    headers:
      Authorization: !secret TrueNas_API
      Content-Type: application/json
      User-Agent: Home Assistant
    scan_interval: 300
    json_attributes:
      - level
      - formatted
    value_template: >
      {% if value_json is defined %}
        {{ value_json[0].level }}
      {% else %}
        {{ "None" }}
      {% endif %}
  - platform: template
    sensors:
      ## Alert message
      tn_alert_message:
        friendly_name: "Alert Message"
        value_template: '{{ state_attr("sensor.tn_alert_level", "formatted") }}'

  # Disk temps -< THIS PART IS NOT WORKING AT ALL!!!!!!
  - platform: rest
    name: tn_disk_temp
    method: POST
    resource: http://192.168.0.9/api/v2.0/disk/temperatures
    verify_ssl: false
    headers:
      Authorization: !secret TrueNas_API
      Content-Type: application/json
      User-Agent: Home Assistant
    scan_interval: 300
    payload: '{"names":["ada0","ada1","ada2","ada3"]}'
    json_attributes:
      - ada0
      - ada1
      - ada2
      - ada3
  - platform: template
    sensors:
      tn_ada0_temperature:
        unit_of_measurement: "Ā°C"
        value_template: '{{ state_attr("sensor.tn_disk_temp", "ada0") }}'
      tn_ada1_temperature:
        unit_of_measurement: "Ā°C"
        value_template: '{{ state_attr("sensor.tn_disk_temp", "ada1") }}'
      tn_ada2_temperature:
        unit_of_measurement: "Ā°C"
        value_template: '{{ state_attr("sensor.tn_disk_temp", "ada2") }}'
      tn_ada3_temperature:
        unit_of_measurement: "Ā°C"
        value_template: '{{ state_attr("sensor.tn_disk_temp", "ada3") }}'
#####################

  # Storage percentage
  - platform: rest
    name: TN pool
    resource: http://192.168.0.9/api/v2.0/pool/id/1
    verify_ssl: false
    headers:
      Authorization: !secret TrueNas_API
      Content-Type: application/json
      User-Agent: Home Assistant
    value_template: '{{ value_json["status"] }}'
    json_attributes_path: "$.topology.data[0].stats"
    json_attributes:
      - allocated
      - size
    scan_interval: 1800
  - platform: template
    sensors:
      tn_pool_pct_used:
        friendly_name: "% Used"
        value_template: ' {{ (state_attr("sensor.tn_pool", "allocated") / state_attr("sensor.tn_pool", "size") * 100) | round(1) }} '
        unit_of_measurement: "%"```

Thanks for your code. Iā€™ve got the temperature part working by using drive name instead. For example, this is my code
payload: '{"names":["sda","sdb"]}'