FreeNAS Stat Monitor

@Dayve67

I seem to remember that you’ll get an “Unknown” if there is no message or alert level. Maybe you can set a condition that if the others were able to pull data and Alert message is null, then make it “Ok.” or something.

In order to get your UPS status, you’ll probably have to go the SNMP sensor route and create a custom SNMP sensor. I would also like to set this up for the same reason. I just haven’t gotten around to playing with SNMP yet. With the API you can access your UPS settings, but it doesn’t look like you can get the current status: http://api.freenas.org/resources/services.html#ups

I got it to work. I was missing “object” in the value_template. But in the process I forced an alert by setting the disk temp low. I have the alert showing now but it will not clear even when I reset my disk temp alert and clear it from the Freenas UI. Restarted HA and it still holds.

value_template: '{{ value_json.objects[0].message }}'

image

It could either be your scan_interval or FreeNAS could still be reporting it in the API. Try getting the message from your browser and see what FreeNAS is reporting. http://hostipaddress/api/v1.0/system/alert/?format=json

@gremblin

Well it looks to be a FreeNAS issue by this old Bug report. At least with 11.3 it looks like the feature will be there. https://redmine.ixsystems.com/issues/11117

On another note did you get the stats from pfSense working?

I installed a crazy custom API package to get stats from pfSense ([link ](https://community.home-assistant.io/t/pfsense-stat-monitor/61070)). SNMP may have been better?

pfSense is working fine for me using the ‘crazy api’ addon, I haven’t tried using SNMP.

con you share your config here?

Her you go. Its pretty easy. Just copy and paste the sensors below and paste them in your sensor.yaml file.
Replace the IP of mine that is 192.168.1.9 with the IP of your Freenas. Also put in your user name and password on each sensor.

  - platform: rest
    name: FN_disk1_report
    json_attributes:
      - name
      - status
      - used_pct
      - is_decrypted
    resource: http://192.168.1.9/api/v1.0/storage/volume/Disk1/?format=json
    value_template: '{{ value_json.status }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json

  - platform: template
    sensors:
      fn_disk1_pct_used:
        value_template: '{{ states.sensor.fn_disk1_report.attributes["used_pct"].title() }}'
        entity_id: sensor.fn_disk1_report
      
  - platform: rest
    name: FN_alert_level
    resource: http://192.168.1.9/api/v1.0/system/alert/?format=json
    value_template: '{{ value_json.objects[0].level }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json
  
  - platform: rest
    name: FN_alert_message
    resource: http://192.168.1.9/api/v1.0/system/alert/?format=json
    value_template: '{{ value_json.objects[0].message }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json
  
  - platform: rest
    name: FN_version
    json_attributes:
      - fullversion
      - name
      - version
    resource: http://192.168.1.9/api/v1.0/system/version/?format=json
    value_template: '{{ value_json.fullversion }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json

  - platform: rest
    name: FN_disk2_report
    json_attributes:
      - name
      - status
      - used_pct
      - is_decrypted
    resource: http://192.168.1.9/api/v1.0/storage/volume/Disk2/?format=json
    value_template: '{{ value_json.status }}'
    username: your_user
    password: your_password
    authentication: basic
    headers:
      Content-Type: application/json

  - platform: template
    sensors:
      fn_disk2_pct_used:
        value_template: '{{ states.sensor.fn_disk2_report.attributes["used_pct"].title() }}'
        entity_id: sensor.fn_disk2_report

Then if your using Lovelace just make a card with all the sensor entities.

Just for fun If you would like to see the API of the FreeNAS you can enter some thing like this: ```
http://192.168.1.9/api/v1.0/storage/volume/Disk1/?format=json

in your browser, It will ask for your user and password. Dont forget to change the IP to yours.

Thanks :+1:

For those who may be interested, this is my current Lovelace View for FN related data:

3 Likes

That’s awesome! Thanks for sharing! :slight_smile:

Very nice. Mine was basic compared to yours. Can you share yours with me now?

Hello Dayve67.

Please see: Home Assistant and FreeNAS.

My configuration and Lovelace view have grown since the above, but it’ll get you started. When you need more, let me know.

1 Like

HI can you explain a bit how did u you the temperature and the status of each drive?

thanks for the help!

I would also like to know, please!
Is this data coming from SNMP probe? Or is the FN11.x API providing a richer data set that includes SMART data?
I’m still on FN 9.10 (as I was too scared to upgrade after the coral debacle) and I can see that the API for disks is not returning SMART parameters.

I think that OP used a command line sensor; however, you can get the values over SNMP too.

Have a look at my post 35 above. You can extend SNMP with the result of any script that you run on the FN.

For example: in order to get temperature of each drive use (replace x with 0 or any drive that you have)
smartctl -A /dev/adax it will give you something like below. Then, to extract temperature only, use

smartctl -A /dev/ada0 | grep -i airflow_temperature | awk '{print $10}' and save this as a script on FN.

=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   083   064   006    Pre-fail  Always       -       220084509
  3 Spin_Up_Time            0x0003   094   094   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       357
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   080   060   045    Pre-fail  Always       -       103205523
  9 Power_On_Hours          0x0032   098   098   000    Old_age   Always       -       2297 (111 71 0)
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   020    Old_age   Always       -       253
183 Runtime_Bad_Block       0x0032   100   100   000    Old_age   Always       -       0
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   100   000    Old_age   Always       -       0 0 0
189 High_Fly_Writes         0x003a   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   063   052   040    Old_age   Always       -       37 (Min/Max 27/37)
191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       141
193 Load_Cycle_Count        0x0032   100   100   000    Old_age   Always       -       465
194 Temperature_Celsius     0x0022   037   048   000    Old_age   Always       -       37 (0 19 0 0 0)
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
240 Head_Flying_Hours       0x0000   100   253   000    Old_age   Offline      -       2294h+50m+51.870s
241 Total_LBAs_Written      0x0000   100   253   000    Old_age   Offline      -       4607016717
242 Total_LBAs_Read         0x0000   100   253   000    Old_age   Offline      -       49821273044
1 Like

Hey guys! Could you please share your config? I got HDD and CPU temperature sensors working, but I’m having trouble setting up other sensors, such as system load. I don’t know how to ‘ask’ that of my system over SSH. Thanks! :slight_smile:

Please see post 52.

Do you mind sharing your sensor.yaml?

You need a little more than my yaml files (such as setting up ssh). Believe me, follow the link in post 52 and you’ll see I’ve documented the approach and given code examples. Nothing was held back. I don’t want to duplicate that work, but will be happy to answer specific questions.

after a long time finally finished the FreeNAS monitor, the FreeNAS server is the back bone of my house internal services:)
here is how it looks:

and here are some of the sensor if it helps anyone:
** Just a warning: the trick is to have Hassio talk to Freenas with ssh key authentication **

t - platform: command_line
    name: 'fn CPU Temp'
    unit_of_measurement: '°C'
    scan_interval: 300
    command: ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] sysctl dev.cpu.0 | grep temperature | tr '.' ' ' | awk '{print $5"°"}'    
    
  - platform: command_line
    name: 'fn Ram'
    unit_of_measurement: 'MB'
    scan_interval: 300
    command: ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected]  top |grep -Em2 '^(Mem|Swap):' | awk '/Mem/{ print substr($8,1) }'

 - platform: command_line
    name: 'Archive Disk 0'
    scan_interval: 300
    command: ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] smartctl -A /dev/ada0 | grep -i Temperature_Celsius | awk '{print $10}'    
    unit_of_measurement: '°C'   

  - platform: command_line
    name: 'Plex Server status'
    scan_interval: 300
    command: ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] iocage get state plex
   

  - platform: command_line
    name: 'Resilio Sync status'
    scan_interval: 300
    command: ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] iocage get state rslsync
    
  - platform: rest
    name: 'Home Server'
    json_attributes:
      - state
    resource: http://192.168.1.161/api/v1.0/vm/vm/1/?format=json
    value_template: '{{ value_json.state }}'
    username: root
    password: your own pasword
    authentication: basic
    headers:
      Content-Type: application/json
    
2 Likes