Integrate TrueNAS CORE statistics with Home Assistant for effortless monitoring

Disclosure: This post contains affiliate links. If you click through and make a purchase, I will earn a commission, at no additional cost to you. Read my full disclosure here.
A digital illustration of a cyberpunk server room.

In a digital world where multitasking has become second nature, we yearn for streamlined solutions to effortlessly monitor and manage our systems. With that in mind, we will delve into integrating TrueNAS CORE statistics and messages into Home Assistant, building upon the previous guide on enabling remote starting and shutting down of a TrueNAS CORE machine. Our tool of choice? The TrueNAS CORE API.

Migrating data from the TrueNAS CORE dashboard

While the TrueNAS CORE dashboard has blossomed into a valuable visual hub for critical data, the Home Assistant Dashboard typically takes centre stage on our desktops. So, why not import and display TrueNAS CORE data into the Home Assistant Dashboard for easy access? This guide will walk you through setting up a sensor that provides a report of essential information, which can then be used for notifications or push alerts to keep you informed of your system's health.

Setting the stage with RESTful sensors

In our pursuit of integrating TrueNAS CORE data into Home Assistant, we will utilize RESTful sensors—no RESTful commands needed, as we aren't executing any system commands. To enable specific variables in the RESTful integration, simply add or remove them under the json_attributes in the configuration provided below.

status
The current status of the volume
vol_guid
The volume’s Globally Unique Identifier
name
The volume’s name
used_pct
The percentage of used storage
used_si
The amount of storage currently used
is_decrypted
Whether the volume is decrypted or not
avail_si
Available storage
total_si
The volume’s total storage
 sensor:
  - platform: rest
    name: freenas_report_full
    json_attributes:
      - name
      - status
      - used_pct
      - is_decrypted
    resource: http://IP -OF-YOUR-FREENAS/api/v1.0/storage/volume/VOLUME-NAME/?format=json
    value_template: '{{ value_json.status }}'
    username: !secret freenas_user
    password: !secret freenas_password
    authentication: basic
    headers:
      Content-Type: application/json

Our trusty secrets.yaml file will once again be used to reference the username and password, as explained in our previous guide.

Opting for template sensors

The code provided creates a new entity with desired attributes. However, it falls short in terms of practicality, as it doesn't allow you to display individual information in your Home Assistant Dashboard or easily use the values in automations. To remedy this, create a template sensor for each individual value.

A screenshot of the Home Assistant Dashboard showing a TrueNAS CORE sensor that has been integrated.

Percent used

 sensor:
  - platform: template
    sensors:
      freenas_percent_used:
        friendly_name: Percent used
        value_template: '{{ states.sensor.freenas_report_full.attributes["used_pct"].title() }}'
        entity_id: sensor.freenas_report_full

Volume status

 sensor:
  - platform: template
    sensors:
      freenas_status:
        friendly_name: Status
        value_template: '{{ states.sensor.freenas_report_full.attributes["status"].title() }}'
        entity_id: sensor.freenas_report_full

TrueNAS CORE version (full)

 sensor:
  - platform: rest
    name: fn_version_full
    scan_interval: 3600
    json_attributes: 
      - fullversion
      - name
      - version
    resource: http://192.168.1.10/api/v1.0/system/version/?format=json
    value_template: '{{ value_json.fullversion }}'
    username: !secret fn_user
    password: !secret fn_password
    authentication: basic
    headers:
      Content-Type: application/json

TrueNAS CORE version (just version number)

 sensor:
  - platform: template
    sensors:
      fn_version:
        friendly_name: Version
        value_template: '{{ states.sensor.fn_version_full.state.split(" ")[0] }}'
        entity_id: sensor.fn_version_full

Unleashing the power of TrueNAS CORE and Home Assistant

With a few lines of code and some tinkering, you can now seamlessly integrate TrueNAS CORE statistics and system information into your Home Assistant setup. This fusion unlocks a world of possibilities for automations, scripts, and notifications. Effortlessly monitor your system's performance and address potential issues, leaving you with peace of mind to focus on life's more important matters.

TrueNAS Core information displayed in the Home Assistant dashboard
An example of how you can display TrueNAS CORE information in Home Assistant

2 thoughts on “Integrate TrueNAS CORE statistics with Home Assistant for effortless monitoring”

  1. Heads up, seems you have a typo in the volume status template. Missing the sensor in “states.sensor.freenas…..”. Great blog though, love it!

    Reply

Leave a comment

Share to...