Getting HDD smart data from disk when running in a container, and a workaround using a command line or file sensor... help!

My actual ask:

I have an old windows machine running HA inside virtualbox. Attached to it are some USB external hard drives that can get a bit warm without a fan running on them.

So I’m looking for a way to get the SMART temperature value of those drives, into somewhere HA can read and then act on a smart plug to turn on or off the fan.

So far the route I’ve taken is to use the windows version of smartctl from here:

https://www.smartmontools.org/wiki/Download

And a windows scheduled task to dump out the smart data to a file every 5 minutes, and put it in an SMB share that HA can get hold of to read that data. All this works.

However, when trying to create a sensor to read the file, the configuration appears correct, but when I restart HA, I just don’t get those named sensors turning up when I search for them using the dev tools section.

These are my two different sensor attempts to read the file:

So in my config.yaml I have:

sensor: !include sensors.yaml  

And in that sensors file I have:

- platform: file
  name: 10tb_hdd_temperature
  file_path: external/smarthddinfo.txt


- platform: command_line
  name: main_hdd_temperature
  command: 'cat /config/external/smarthddinfo.txt'
  scan_interval: 300

I’m pretty sure the filepath in the file sensor is right, otherwise dev tools complains it can’t find the file, and in the command line sensor version, if I run that in the terminal, it outputs the contents of the file I want.
Any thoughts on why neither show up in dev tools after a restart ?
Or is there a better way to get my HDD temps given that I’m running HA in virtualbox ?

Typically the logs appear to show me the problems…

The command line sensor has this issue:

homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.main_hdd_temperature. State max length is 255 characters.

And for the file sensor the error is:

‘external/smarthddinfo.txt’ is not an allowed directory

So I’ll work through the latter and see if I can get it to work.

You can try this repo. You have in it scrutiny addon that has S.M.A.R.T metrics.

Looked really promising, but doesn’t display any SMART info. I think this is because I’m running inside virtualbox, and I suspect the USB pass through in the VM doesn’t provide this data.

All I get is a blank screen:

This does work, but problem is somewhere in your setup. Maybe you have to set up vm to get data. I don’t know as I dont use virtualbox.

The VM is passing through the USB disks to virtualbox because I can see them in the hardware section of HA:

So you are able to get the SMART data from the disks, even though your HA is running inside a VM ?

I run ha inside docker container. I didn’t set up scrutiny in container, but I was running this on my debian supervised installation and it worked without any issues.

Ahh. I’m running scrutiny as an addon inside the VM. If there was a windows version of it I could use the rest interface to grab the data.

This is exactly the approach that

https://openhardwaremonitor.org/

Uses, and its available for windows… but the software currently only finds the smart data for internal drives, and doesn’t work on USB disks.

I also noticed ironically, that scrutiny actually uses smartctl (the command line tool I am using), it just puts a web interface and some nice visuals over the top.

Taking the thought of using a web interface to collect the data from smartctl, I came across:-

Its a tiny light weight web server that I can use to serve files to home assistant via a web interface. This makes it super easy to transfer data between the host running HA (and its hardware), and HA inside the VM.

In this case, I just use smartctl to post log files to a folder that rebex web server can server, then use HA’s restful/scraper/multiscrape interface to grab the data I need.