How to show the Raspberry Pi CPU temperature?

Being a total HA noob, I’m wondering how to add a sensor showing the temperature of the CPU of a Raspberry Pi. The temperature (in millicelcius) can be read with the following shell command:

cat /sys/class/thermal/thermal_zone0/temp
1 Like

This should do it Hansen,

It will even convert it to Celsius.

10 Likes

Oh my god… It even has an example doing EXACTLY what I asked for, and I completely missed that component.

Thanks for pointing me in that direction! :slight_smile:

1 Like

No worries! You will know the website like the back of your hand before long.

Welcome to the HA Community!

1 Like

Another way of doing this (and a whole lot more monitoring) would be the Glances component.

1 Like

Old topic, but I put this in pasted directly from that page and get F instead of C. Any ideas?

Same issue here. Raspberry reports back 76000 millicelsius for example.

My yaml entry:

  - platform: command_line
    name: Raspberry C Temp
    command: "ssh [email protected] 'cat /sys/class/thermal/thermal_zone0/temp'"
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) }}'

I get back this value and wrong UOM in the badge:

On a whim, I change the YAML to this, I get the right number, but Farenheit shows as the UOM (not correct anyway.)

sensor:
  - platform: command_line
    name: Raspberry C Temp
    command: "ssh [email protected] 'cat /sys/class/thermal/thermal_zone0/temp'"
    unit_of_measurement: "°F"
    value_template: '{{ value | multiply(0.001) }}'

I use this one:

  - platform: command_line
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(2) }}'
3 Likes

I use the same on my Pine64 but. Had to remove the value_template to show the right value.

Just an note, there’s a PR for adding the Glances CPU Temp sensor to HA.

https://github.com/home-assistant/home-assistant/pull/6433

1 Like

is this possible for hass.io. anyone done it? i tried with even setting up keys and the command work from hass.io but getting an error in runtime.

I doubt very much that the Docker container has access to the hardware information.

this works in my hassio:

  - platform: command_line
    name: CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) }}'
6 Likes

Brilliant Corey. It worked :). Strange thing is, i probably tried it a while back and it dint work.

I was then trying this

'ssh "[email protected]" "sudo cat /sys/class/thermal/thermal_zone0/temp"'
this worked from hassio cli but not from within home assistant.

nonetheless, appreciated.

i thought so too. But apparently it does now.

Here are a couple of quick and dirty sensors if you’d like to convert CPU / GPU temps from Celsius to Fahrenheit:

- platform: command_line
  name: cpu_temperature
  command: "cat /sys/class/thermal/thermal_zone0/temp | awk '{print ((($1*.001) * 9 / 5))+32}'"
- platform: command_line
  name: gpu_temperature
  command: "/opt/vc/bin/vcgencmd measure_temp | cut -c 6- | head -z --bytes -3 | awk '{print (($1 * 9 / 5))+32}'"

Might be a better way to do this, but seems to be working so far!

3 Likes

That is how I do it. And if you are worried you can add a little fan pretty easily to the CPU. (I did for my HA rPi)

1 Like

Hi,

I tried your solutions, because I wanna monitoring the temperature of another raspberry.
The problem is my other raspberry has a password…
How can I integrate the password in the command ?

Thank you !!

i came across this challenge a while back and dont think it is possible. it violates the key security principle anyways putting password in plain text. you can however exchange certificates somehow (too complicated for me to remember) between the two raspberry pi’s to avoid specifying password.

i would rather just post MQTT status updates from the other raspberry pi and pick them up within home assistant.

i suppose the vcgencmd cannot work in hassio (it doesnt for me). any alternative there?