Displaying Cpu Temperature Within Home Assistant

Thanks Coolie, unfortunately I could not get the command line sensor to work, even though all the commands work when run from the shell as the homeassistant user. I did, however, get the file sensor to work!

What platform are you running HA on?

There are no sensors (lm-sensors) in a VM.

In a Raspberry Pi there is a single temp sensor on the CPU if you can get it to read via lm-sensors.

On physical desktop computers, laptops, and servers there are lots of sensors you can read with lm-sensors. I asked about a lm-sensors to mqtt in another thread but no one replied so I assumed it did not exist.

For example, in my desktop Linux box I have the following built in sensors

fam15h_power-pci-00c4
Adapter: PCI adapter
power1:       78.06 W  (crit =  94.92 W)

k10temp-pci-00c3
Adapter: PCI adapter
temp1:        +23.8°C  (high = +70.0°C)
                       (crit = +83.5°C, hyst = +80.5°C)

atk0110-acpi-0
Adapter: ACPI interface
Vcore Voltage:      +1.00 V  (min =  +0.80 V, max =  +1.60 V)
+3.3V Voltage:      +3.17 V  (min =  +2.97 V, max =  +3.63 V)
+5V Voltage:        +5.04 V  (min =  +4.50 V, max =  +5.50 V)
+12V Voltage:      +11.95 V  (min = +10.20 V, max = +13.80 V)
CPU Fan Speed:     2033 RPM  (min =  600 RPM, max = 7200 RPM)
Chassis Fan Speed: 1295 RPM  (min =  600 RPM, max = 7200 RPM)
CPU Temperature:    +40.0°C  (high = +60.0°C, crit = +95.0°C)
MB Temperature:     +34.0°C  (high = +45.0°C, crit = +75.0°C)

I’ve been working on a perl script to pull the sensor data and plug it into MQTT with auto-defined topics.

Right now I have it doing the following

Publishing "<MyHostname>.com/PCIadapter/power1" with "74.63" 
Publishing "<MyHostname>.com/PCIadapter/temp1" with "32.0"
Publishing "<MyHostname>.com/ACPIinterface/Vcore Voltage" with "1.36"
Publishing "<MyHostname>.com/ACPIinterface/+3.3V Voltage" with "3.17"
Publishing "<MyHostname>.com/ACPIinterface/+5V Voltage" with "5.07"
Publishing "<MyHostname>.com/ACPIinterface/+12V Voltage" with "11.87"
Publishing "<MyHostname>.com/ACPIinterface/CPU Fan Speed" with "1956"
Publishing "<MyHostname>.com/ACPIinterface/Chassis Fan Speed" with "1315"
Publishing "<MyHostname>.com/ACPIinterface/CPU Temperature" with "39.0"
Publishing "<MyHostname>.com/ACPIinterface/MB Temperature" with "34.0"

There is still a lot of work to do on the script but it is basically running. I have a dual xeon processor motherboard here that has 10x that number of sensors on it. It will be interesting to see when I get it up and running. lol

Personally I started it because I want to monitor the wattage draw on the units in the house. :wink:

I’m trying what you do and when I enter /usr/bin/sensors | grep 'Core 0' | cut -c17-20 I get 39.0 in the terminal. However when I use the following in my config:

  - platform: command_line
    name: Server Temp
    command: "/usr/bin/sensors | grep 'Core 0' | cut -c17-20"
    unit_of_measurement: "°C"

the sensor does not show anything. When I try the standard example where I pull the temperature like this it works:

  - platform: command_line
    name: CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    # If errors occur, remove degree symbol below
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }}'

Could it be that there is a problem with cut or grep or something?

Did you try that command from an ssh session?

Quickly off the top of my head, I would try the quotation marks.

If you change them to an exact copy of how I have them, does the sensor then work?

It’s also possible that the homeassistant user doesn’t have the permissions to run that command - so you check that by swapping over to the homeassistant user and seeing if the command still works.

You’re right with the permissions. I made a python script now which publishes on mqtt and gets triggered by a cron job.

When I added processor temperature to system monitor in config it came back and shows in Fahrenheit and wondering how to change that to Celsius. Any help would be appreciated.