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 today's digital era, seamless system management and monitoring have become essential. Building on our previous guide on remote management of TrueNAS CORE machines, this article focuses on integrating TrueNAS CORE statistics and messages into Home Assistant. This integration leverages the TrueNAS CORE API, enabling you to monitor your system effortlessly.

Contents

Importing Data from TrueNAS CORE to Home Assistant Dashboard

The TrueNAS CORE modern dashboard is a comprehensive visual tool for monitoring critical system data. However, for those who rely on the Home Assistant Dashboard as their primary interface, integrating TrueNAS CORE data directly into Home Assistant enhances accessibility and convenience. This guide will show you how to set up a sensor in Home Assistant to display essential TrueNAS CORE information, facilitating notifications or alerts about your system's status.

Utilizing TrueNAS CORE RESTful Sensors for Integration

To integrate TrueNAS CORE data into Home Assistant, we'll use RESTful sensors. A RESTful sensor in Home Assistant is a type of sensor that extracts information from an external source using REST (Representational State Transfer) API calls. REST is an architectural style for designing networked applications, and it relies on a stateless, client-server, cacheable communications protocol — typically HTTP. In the context of Home Assistant, a RESTful sensor can query external APIs to fetch data and then represent this data as state information within the Home Assistant ecosystem.

The RESTful sensor configuration allows Home Assistant to periodically make requests to an external endpoint (URL), process the returned data (usually in JSON or XML format), and display this data as attributes of the sensor. This capability is particularly useful for integrating a wide range of internet services and external devices into your Home Assistant setup, enabling you to monitor and interact with these services directly from your Home Assistant Dashboard.

This approach does not require any RESTful commands for system actions. Instead, it focuses on fetching specific variables for monitoring. You can customize which variables to monitor by adjusting the json_attributesin the configuration example provided below:

Here's an example configuration to enable these variables in Home Assistant:

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

As highlighted in our previous guide, the secrets.yaml file is used for secure credential storage.

Stylized illustration of a red safe with a shadow cast on the left, against a red background. The safe has a prominent, circular gold-coloured combination lock in the centre of its door.
Screenshot of the Home Assistant Dashboard showing system status with three columns titled 'Entity', 'State', and 'Attributes'. Under 'Entity', there is a search bar labelled 'Filter entities' and a single entry with an information icon next to a shaded bar. The 'State' column has a corresponding 'Filter states' search bar and shows the status 'HEALTHY' for the entry. The 'Attributes' column, with a checked box and a 'Filter attributes' search bar, lists details for the entry: 'name:' with a blank field, 'status: HEALTHY', 'used_pct: 83%', 'is_decrypted: true', and 'friendly_name:' with a blank field.

Creating Template Sensors for Detailed Monitoring

The initial setup provides a consolidated entity with various attributes, but it may not be practical for direct display or use in automations within Home Assistant. To display individual data points or use them in automations, create a template sensor for each attribute.

Monitoring Percent Used

For those interested in tracking how much storage is being used, the following configuration creates a sensor that displays the percentage of used storage on your TrueNAS CORE system:

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'] }}"

Volume status

To keep an eye on the health and status of your storage volume, use the configuration below. It creates a sensor that reflects the current status of your TrueNAS CORE volume, such as online, offline, or degraded:

sensor:
  - platform: template
    sensors:
      freenas_status:
        entity_id: sensor.freenas_report_full
        friendly_name: "Status"
        value_template: "{{ states.sensor.freenas_report_full.attributes['status'] }}"
Truenas Core Statistics 06

TrueNAS CORE Version Details

For comprehensive system version tracking, including both the full version string and the specific version number, use the following configurations:

Full Version:

This configuration fetches the full version information of your TrueNAS CORE system, including the build number and release details:

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

Version Number Only:

For a simplified view that only shows the version number of your TrueNAS CORE, the following template sensor configuration is ideal:

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] }}"
A screenshot of a card in the Home Assistant Dashboard titled 'Trippier' displaying system information from a TrueNAS Core system. There are three labelled items with corresponding details: 'Version' with the text 'FreeNAS-11.2-U7', 'Percent used' showing '83%', and 'Status' indicating 'Healthy'.

Conclusion

By integrating TrueNAS CORE statistics into your Home Assistant, you enable a powerful monitoring tool that enhances your system management experience. This setup not only provides critical insights into your TrueNAS CORE system but also offers flexibility for custom notifications and automations. Through straightforward configurations and creative use of template sensors, you can maintain oversight of your system's health and performance, ensuring your digital environment runs smoothly.

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