Collecting Unraid CPU Temperature in Home Assistant

Overview

I recently upgraded my home lab server to a Dell PowerEdge R730xd sporting 2x Intel Xeon E5-2660 v4 processors, which seem to run a lot hotter than my previous server when under load (even after replacing the thermal paste).

To cool the server, I bought a cheap box fan, that I want to automatically turn on when the server breaches a predefined temperature threshold, then have it turn back off when the temperatures drop to something acceptable again.

To accomplish this, I planned to make use of a Kasa Smart Wi-Fi Plug Lite (HS103P2) via the Home Assistant TP-Link Smart Home integration.

After some Googling, I was disappointed to see that there is no native Unraid integrations for Home Assistant that would allow me to import the temperature information.

However, I stumbled across a GitHub repository called hass-unraid that seemed to do what I wanted, albeit through a much more roundabout manner.

Below is a breakdown of how such a simple task was completed in the most roundabout manner, in hopes that someone may find this useful.

hass-unraid container

The first thing we will need to do is deploy the hass-unraid container somewhere. The simplest solution here was to use my Unraid server to do this as there is a community application for this already.

Once the container is deployed you will need to create a config.yaml file in it’s /data directory (normally this is under /mnt/user/appdata/hass-unraid), with the following configuration as per the official documentation.

My configuration looks something like this:

unraid:
  - name: NAS
    host: 192.168.0.60
    port: 80
    ssl: false
    username: root
    password: pass
    scan_interval: 30

mqtt:
  host: 192.168.0.60
  port: 1883
  username: hass
  password: pass

With everything configured you should be able to start the container.

Defining Temperature Information

I make use of the Dynamix System Temperature Unraid plugin to collect my CPU temperature information on my server.

I am in an odd situation as my server has 2 processors, and the plugin only allows the selection of a single processor to provide temperature information about.

To address this within the constraints of the plugin, I simply assigned CPU1 as the processor temperature, and CPU2 as the motherboard temperature. I do loose the ability to monitor the motherboard this way, but for what I am wanting to do this is fine.

Unraid is now able to see my processor temperatures.

Home Assistant Discovery

With hass-unraid running and publishing data to your MQTT sever, Home Assistant should automatically discover a new MQTT device for you Unraid server.

To avoid confusion in the future I renamed the exposed motherboard temperature to CPU2 and disabled collected information for values I don’t care about, leaving me with the following.

Once I had my CPU temperatures coming into Home Assistant it’s just a matter of setting up the automations for the fan.

Fan Automations

Turn fan ON when CPU is over 50 °C

This is done using a Numeric State trigger monitoring CPU2 on my server (as it seems to run a bit hotter than CPU1) set to a value above 49.5 degrees for 10 seconds or more.

When this threshold is hit, check the state of the fans smart plug to see if it needs to be turn it on, turn on if required.

And in yaml it looks something like this:

alias: Server Rack Fan - Turn On (CPU2 >= 50)
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.nas_mainboard_temperature
    for:
      hours: 0
      minutes: 0
      seconds: 10
    above: 49.5
conditions:
  - condition: state
    entity_id: switch.server_rack_fan
    state: "off"
actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.server_rack_fan
mode: single

Turn fan OFF when CPU is below 50 °C

The off case is pretty much the invers of the on case. When the servers CPU is reporting a temperature, I deem good, and the fan is currently running, turn it off.

And in yaml it looks something like this:

alias: Server Rack Fan - Turn Off (CPU2 <= 50)
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.nas_mainboard_temperature
    for:
      hours: 0
      minutes: 0
      seconds: 30
    below: 50
conditions:
  - condition: state
    entity_id: switch.server_rack_fan
    state: "on"
actions:
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.server_rack_fan
mode: single

Tweaking

You may want to play around with the threshold temperatures to something that makes sense for your setup should you find that the fan is cycling too often, or if you only want to run the fan at a higher temperature.

For me, the selected values work well with the fan only turning on when the server is under load. During normal operations the fan is off (which is most of the day).

Running a couple of test using the stress Unraid container the automations work as expected.

The fan turns on when the server breaches 50, then back off when the server is below 50.

Final Thoughts

Hopefully someone found this article helpful, and I wish there was better first party support for Unraid in Home Assistant.

Please feel free to drop me a comment if you have any questions or suggestions.