TrueNAS CORE statistics and messages in Home Assistant

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

Building on the previous guide on how to enable remote starting and shutting down of a TrueNAS CORE machine, I will now show you how to view your TrueNAS CORE statistics and messages within Home Assistant. For this guide, I am once again going to be using the TrueNAS CORE API.

Advertisement

The TrueNAS CORE dashboard has evolved into a nice little visual hub for viewing important data. However, as I have the Home Assistant Dashboard open on my desktop a lot more often than the TrueNAS CORE web interface, I wanted to import and display that data in my UI. The sensor I’ll be setting up in this guide will give me a report of the following:

The TrueNAS CORE dashboard has become a useful visual hub for viewing critical data. However, since I always have the Home Assistant Dashboard open on my desktop rather than TrueNAS CORE’s web interface, I wanted to import and display that data in the former.

Advertisement

Once you have grasped the basics, you will be able to add any of the values provided by the TrueNAS CORE API. With these values, you can also set up notifications such as a push alert if your volume becomes unhealthy.

Table of Contents

Setting up the TrueNAS CORE sensor in Home Assistant

As I am not executing any commands, such as shutting the system down, this setup will be using RESTful sensors and not RESTful commands. Any of the following variables can be enabled in using the RESTful integration (just add or remove them under the json_attributes):

Advertisement

Since I am not performing any commands, such as shutting down the system, this setup will be using only RESTful sensors and no RESTful commands. You can enable any of the following variables in the RESTful integration. To achieve this, simply add or remove them under the json_attributes in the configuration 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

To get this API call to work, I’ve once again referenced the username and password in my secrets.yaml file. For more on that topic, you can check out my previous guide here.

Advertisement

To make this API call work, I have referenced the username and password in my secrets.yaml file, as previously explained in my guide on controlling a TrueNAS Core machine. If you need additional information about that topic, you can refer to my previous guide.

 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

This code will create a new entity with the desired attributes. But, as you might find out, this isn’t very practical. With this entity, you won’t be able to embed individual information in your Lovelace UI and you can’t easily use the values in automations. What I did was create a template sensor for each individual value.

This code will create a new entity with the desired attributes. However, you may find this approach to be not very practical. With this entity, you will not be able to display individual information in your Home Assistant Dashboard. Additionally, it is difficult to use the values in automations. Instead, I suggest creating a template sensor for each individual value.

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

Template TrueNAS CORE sensors for Home Assistant

Below are several code excerpts for you to copy and use in your Home Assistant’s configuration.yaml. Depending on the changes you made, you will need to reflect them in the examples.

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

Final steps

And voilà! Your TrueNAS CORE statistics and system information can now be seamlessly integrated into your Home Assistant setup, providing endless possibilities for automations, scripts, and notifications. With this setup, you can easily monitor your system’s performance and act on any potential issues, giving you the peace of mind to focus on more important things.

An example of how you can display TrueNAS CORE information in Home Assistant

2 thoughts on “TrueNAS CORE statistics and messages in Home Assistant”

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