Psutil fan speed sensor

The System Monitor integration uses psutil so I figured I could use this command line sensor to obtain the CPU fan rpm:

- platform: command_line
  name: CPU Fan RPM
  command: "psutil.sensors_fans()"
  unit_of_measurement: "RPM"

Of course that would be far too easy. It failed with:

ERROR (SyncWorker_4) [homeassistant.components.command_line] Command failed: psutil.sensors_fans()

Is there any way to get this information?

HA OS Generic x86 install.

Ok so as Tinkerer pointed out on Discord, I am trying to run a python function at the command line. :man_facepalming:

That looks more like a library function call, not a shell command.

SSH in and see if it works from command line?

It does not. It returns function>

See my facepalm above.

So I guess I do this?

  - platform: command_line
    name: Fan Speed
    scan_interval: 60
    command_timeout: 30
    unit_of_measurement: "RPM"
    command: "python3 /config/python_scripts/fan-speed.py"

/config/python_scripts/fan-speed.py

import psutil
print(psutil.sensors_fans())

I may not even need the import as psutil is included in System Monitor integration which I use?

Without the import it fails.

With the import:

What am I doing wrong?

You’ll need the import.

Yep that’s what I said:

However it does not work with the import either:

Step 1 is to get the python program working.

Just because psutil can report fan speed, it doesn’t mean you have the hardware in place to monitor the fan speed. Are you able to see evidence of the fan speed being reported anywhere else?

Try the program with something you know works - like CPU - that you are currently getting via the integration. If this doesn’t work then you may be using the api incorrectly. If it does, then it becomes more likely your hardware doesn’t know the fan speed.

First I removed the unit of measurement as I though it may be a non numeric result.

No change, still got the empty dictionary {}

Then I tried with psutil.sensors_temperatures() which returned:

{'acpitz': [shwtemp(label='', current=-263.2, high=None, critical=None), shwtemp(label='', current=29.0, high=119.0, critical=119.0)], 'iwlwifi_1': [shwtemp(label='', current=32.0, high=None, critical=None)]}

So I guess the issue is that I don’t have a fan speed sensor.