Unraid JSON API

Introduction

This UNRAID plugin is a wrapper for reading the files used by Unraid / emhttpd for displaying various statistics, the files are read from /var/local/emhttp/*.ini and are converted to JSON for easy access by services/applications like Home Assistant

This plugin has no ‘frontend’ and is only accessible directly via http://TOWER/plugins/jsonapi/api.php?file=XXX.ini for example to get the disks.ini file you would do http://TOWER/plugins/jsonapi/api.php?file=disks.ini

currently the following files exist that can be used

  • cpuload.ini
  • devs.ini
  • diskload.ini
  • disks.ini
  • monitor.ini
  • network.ini
  • sec.ini
  • sec_afp.ini
  • sec_nfs.ini
  • shares.ini
  • users.ini
  • var.ini

Usage

Plugins > Install Plugin
https://raw.githubusercontent.com/Cyanlabs/jsonapi-unraid/master/jsonapi.plg

This is designed to be a more “plug and play” method of getting the unraid statistics compared to this Unraid System Monitor integration

Just to clarify, due to limitations afaik in the Unraid plugin system this does require basic auth when accessing the json.

NOTE: please note that this currently is a raw json output, a custom HA component would be the best way to access this data but it is possible without a custom component (HA has a 255 character REST sensor state limit)

  - platform: rest
    name: Unraid
    resource: "http://192.168.1.3/plugins/jsonapi/api.php?file=disks.ini"
    username: root
    json_attributes:
      - disk1
      - disk2
    password: !secret unraid_password
    authentication: basic
    value_template: '{{ value_json["disk1"]["status"] }}'
    headers:
      User-Agent: Home Assistant
      Content-Type: application/json

despite it not being able to do more than 255 you can work around it with the attributes, the above code will show something like this

and you can access specific values with like this

My python isn’t great but i believe this is a good starting point - https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/pvoutput/sensor.py​

Things like CPU load are easy though

sensor:
  - platform: rest
    name: Unraid CPU
    resource: "http://192.168.1.3:965/plugins/jsonapi/api.php?file=cpuload.ini"
    username: root 
    password: !secret unraid_password
    authentication: basic
    value_template: '{{ value_json["cpu"]["host"] }}'
    headers:
      User-Agent: Home Assistant
      Content-Type: application/json
4 Likes

Hey my friend, I thought posting here is better suited cause I guess it’s some hass issue.
I do get this

Error fetching data: http://192.168.1.16:965/plugins/jsonapi/api.php?file=cpuload.ini failed with HTTPConnectionPool(host='192.168.1.16', port=965): Max retries exceeded with url: /plugins/jsonapi/api.php?file=cpuload.ini (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x149ae2e1cf10>: Failed to establish a new connection: [Errno 111] Connection refused'))

relevant config

sensor:
  - platform: rest
    name: HAL CPU
    resource: "http://192.168.1.16:965/plugins/jsonapi/api.php?file=cpuload.ini"
    username: root 
    password: *redacted*
    authentication: basic
    value_template: '{{ value_json["cpu"]["host"] }}'
    headers:
      User-Agent: Home Assistant
      Content-Type: application/json

Home assistant running on the same machine as Unraid. I’ve tripled checked config. Any help is welcome :slight_smile:

Thanks again for you’re idea, this was the missing piece of my automation world :trophy: :trophy: :trophy:

Upon further inspection of the code i can see there is already work in progress code for an API in 6.8 via a plugin called unraid.net so this kinda makes my program redundant.

in the /boot/config/plugins/dynamix/dynamix.cfg file you have this

[remote]
apikey=“bbff6d7320a3cfa74964c58b5c5d3b0XXXXXXXXXXXXXXXXXXXXXXe2bc79518f2e4f0c4”
wanaccess=“no”
wanport=“0”
{
“data”: {
“vars”: {
“version”: “6.8.0”,
“port”: 965
},
“disks”: [
{
“device”: “/dev/sda”,
“type”: “HD”,
“name”: “Extreme”
},
{
“device”: “/dev/sdb”,
“type”: “SSD”,
“name”: “MTFDDAK256MAM-1K12”
},
{
“device”: “/dev/sdc”,
“type”: “SSD”,
“name”: “Crucial_CT250MX200SSD4”
},
{
“device”: “/dev/sdd”,
“type”: “HD”,
“name”: “ST2000LM007-1R8174”
},
{
“device”: “/dev/sde”,
“type”: “SSD”,
“name”: “LITEON_LCH-256V2S-HP”
},
{
“device”: “/dev/sdf”,
“type”: “HD”,
“name”: “WDC_WD5000AAKX-60U6AA0”
},
{
“device”: “/dev/sdg”,
“type”: “HD”,
“name”: “WDC_WD20EZRZ-00Z5HB0”
},
{
“device”: “/dev/sdh”,
“type”: “SSD”,
“name”: “SAMSUNG_MZ7PD256HCGM-000H7”
},
{
“device”: “/dev/sdi”,
“type”: “HD”,
“name”: “WDC_WD20EZRZ-00Z5HB0”
},
{
“device”: “/dev/sdj”,
“type”: “HD”,
“name”: “WDC_WD20EZRZ-00Z5HB0”
},
{
“device”: “/dev/sdk”,
“type”: “SSD”,
“name”: “MTFDDAK256MAM-1K12”
},
{
“device”: “/dev/sdl”,
“type”: “HD”,
“name”: “ST2000DM008-2FR102”
},
{
“device”: “/dev/nvme0n1”,
“type”: “NVMe”,
“name”: “Samsung_SSD_960_EVO_250GB”
}
]
}
}

looks like Unraid API is definitely a thing in 6.8 and therefore completely makes this quick plugin redudant.

Hi. dont use port 965, i specifically use port 965 for my own reasons and have changed unraid to run on port 965. 80 is default so no need to specify a port.

Can you link to the API development that you mention?

No, because it’s from looking at the code there is no official info yet.

EDIT:
Nevermind. I read the unraid thread regarding the problem wit basic auth and 6.8. Thanks anyhow.

Hi there,

Not sure if you’re still supporting this, but after using the MQTT Unraid System Monitor integration for some time, I really wanted to give this a shot.

Unraid plugin installed and can produce output into browser.

Completely fresh HA docker container.

Added sensor to configuration (for the sake of this attempt, I just wanted to start with the one from your post):

sensor:
  - platform: rest
    name: Unraid Disks
    resource: "http://192.168.0.2/plugins/jsonapi/api.php?file=disks.ini"
    username: root 
    password: !secret unraid_password
    authentication: basic
    json_attributes:
      - disk1
      - disk2
    value_template: '{{ value_json["disk1"]["status"] }}'
    headers:
      User-Agent: Home Assistant
      Content-Type: application/json

Restart HA and the sensor shows up, but with no attributes and an error message:

2020-04-09 22:57:33 WARNING (SyncWorker_42) [homeassistant.components.rest.sensor] REST result could not be parsed as JSON

I’m inexperienced with json, so I’m deferring to you. Hopefully you or someone else can point me the right direction.

Thanks!