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.

 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:
        entity_id: sensor.freenas_report_full
        friendly_name: Percent used
        value_template: {{ states.sensor.freenas_report_full.attributes["used_pct"].title() }}

Volume status

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

TrueNAS CORE version (full)

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

TrueNAS CORE version (just version number)

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

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
A portrait photo oif Liam Alexander Colman, the author, creator, and owner of Home Assistant Guide wearing a suit.

About Liam Alexander Colman

is an experienced Home Assistant user who has been utilizing the platform for a variety of projects over an extended period. His journey began with a Raspberry Pi, which quickly grew to three Raspberry Pis and eventually a full-fledged server. Liam's current operating system of choice is Unraid, with Home Assistant comfortably running in a Docker container.
With a deep understanding of the intricacies of Home Assistant, Liam has an impressive setup, consisting of various Zigbee devices, and seamless integrations with existing products such as his Android TV box. For those interested in learning more about Liam's experience with Home Assistant, he shares his insights on how he first started using the platform and his subsequent journey.

Comments

  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...