Unraid API - Connect and control Unraid servers through Home Assistant via MQTT

So when you install a docker it essentially runs as a small virtual machine in your machine with some paths mapped to your drives. In the config page for the docker you should see where the config path is mapped to.

Currently there is nothing for UPS power, I will add it to my to-do list. I don’t have much experience with it myself so not sure what to suggest in the meantime sorry.

1 Like

It’s actually not needed i can monitor the UPS with the “NUT” plugin. Which lets Unraid broadcast the UPS status, and HA has a “NUT” component :slight_smile:


Mqtt is running here, but i dont know what to do next…
I need to connect the unraid API to this broker, but how?
The same for my HA instance running on pi
I’m new to this broker
launching gui from this MQTT, just gives me an info page

Okay that’s great, your mqtt broker should have an IP address and port, as well as a username and password.

For HA you want to go to configure > integrations > mqtt and add the details there.

For unraid API you need to send them in as environment variables, the details of which are available here:

Finally for auto discovery you need the discovery topic in HA and the base topic in the API to be the same

not sure about the mqtt ip addres and port and username and password
if i click the webgui it goes to http://mqtt.org/
For HA, i have the choice, add details to integration or use the discovery?

If you managed to configure that config file that should contain the user and password

By default the IP will be the same as your unraid server and the port 1883

ok that ip and port is unreachable
i’ll look back into config

ok tried to connect to the broker by using http://www.hivemq.com/demos/websocket-client/
and filling in user and password

succeeded connection

i will look into ha now

mm not really working

i entered in my config file

  broker: !secret broker_ip
  password: !secret broker_password

but where do i enter my username?
can you tell me how you filled it in?
(dont wanna use discovery)

That’s fair enough, you just need an extra tag username
Full list available here: https://www.home-assistant.io/docs/mqtt/broker/

If you’re not using discovery you can manually configure sensors and switches, details are here: https://github.com/ElectricBrainUK/UnraidAPI/wiki/Home-Assistant-Integration

i entered this in my config file

  broker: !secret broker_ip
  username: !secret broker_user
  password: !secret broker_password
  discovery: true   

I dont get errors now, but i dont see sensors either,
what do i miss?
i entered the variables in the api for unraid too
not sure about the port
if i try the test http://www.hivemq.com/demos/websocket-client/
and fill in port 9001
then test succeeds
if i fill in port 1883 or 8883 it fails
not sure about client id there, is standard clientId-PI2Ukpl7FK

is this ok:

Ahh okay so it seems the port on yours is different so try changing the MQTTPort variable to the other value.

i will but not sure thats the problem
when i look in the mqtt docker i find this

so that mentions also port 1883
trying 9001 now

Damn still nothing

not sure where the problem is…
Is it in the broker?
Is it the unraid api?
Or is it in home assistant?

Broker mosquitto settings

Unraid api settings

This in config HA

  port: 9001
  username: user x
  password: paswoord x
  discovery: true   
  discovery_prefix: homeassistant

ok so yesterday it suddenly worked after i launched it
i now have entities like switches for dockers and a sensor…
i do have other questions though.

  • al those entitities are in ha saying they are unavailable, is that normal?
  • if i shutdown the broker on the unraid machine, will the attributes of the machine still be visible in the broker for the raspberry pi(ha) to read from?
  • i have the broker now on the unraid machine, and ha on my raspberry pi, since i shutdown my unraid (and not the pi) shouldnt it be wiser to set up the broker on the pi?
  • you have these sensors, how do i get them? they arent made by the discovery
                    - key: binary_sensor.unraid_server.cpu                      
                    - key: binary_sensor.unraid_server.memory
                    - key: binary_sensor.unraid_server.motherboard
                    - key: binary_sensor.unraid_server.arrayStatus
                    - key: binary_sensor.unraid_server.diskSpace
                    - key: binary_sensor.unraid_server.arrayProtection  

Thx for your support here!

Electric, thanks for this awesome solution to monitoring and controlling Unraid. It works great on my end, and I’m hosting Hass in a docker container within Unraid.

One thing I’d like to display is the disk space percentage used for the entire array as an int. The binary sensor is reporting ‘diskSpace: 4.83 TB used of 7 TB (69.0 %)’ as an attribute, so I know I need to make a template sensor to isolate the percentage. Any idea where I can start trying to get that formatted? Thanks a ton!

Also, I have glances installed and working, but the ‘sensor.glances_disk_used_percent’ is reflecting my container’s space remaning, not my array. I don’t have a sensor for the array disk percentage used / remaining etc.


Well, that really wasn’t all that bad. Here’s my solution:

      value_template: >
        {% set temp = states('sensor.server_diskspace').split(' ') %}
        {% set new = temp[6].split('(') %}
        {{ new[1] | float }}

This gives me a float sensor value I can use with the gauge card. Super rad. Thanks again for this awesome utility!

1 Like

Skank, no worries for the support I’m glad you’re getting use out of it!
I know I have replied to this to you elsewhere but replying here as well in case anyone else comes across it.

  • The unavailable thing is normal if the Home Assistant has just restarted or has just been configured, every hour (by default, configured by the MQTTCacheTime variable for more details: https://github.com/ElectricBrainUK/UnraidAPI/wiki/Docker-installation) the API will refresh all states, in between that time it only shows changes
  • No, so I recommend having the broker and API (coming soon as an addon) running on the pi to monitor the server status even while it is down.
  • Yes exactly
  • All of the sensors can be configure as templates using this: https://www.home-assistant.io/integrations/template for example the motherboard name sensor would be as follows:
- platform: template 
     value_template: "{{ state_attr('binary_sensor.server', 'motherboard') }}"
1 Like

Thats great Im glad youre getting use out of it!

Ahh that is great Im glad you managed to find a solution but I admit that isnt as easy as it shouldve been so maybe Ill add another sensor that just reports the percentage

1 Like

That could be helpful for sure. In my use case, I’m also interested in the actual amounts being reported on their own. So not just the percentage, but the space used and the space free as well. I can accomplish that with templates at this point, but if you felt froggy while you were in there, disk free and disk used could be helpful.

Another feature request if you didn’t mind poking around with it, is determining the space of the individual drives as well. Not just the entire array, but disk free, used, percentage for sda, sdb, etc etc. I could list my individual drives in bar cards, then have a “total” card under all my drives. Could be cool, and especially helpful in determining if I want to use Unbalance or not.