How to show the Raspberry Pi CPU temperature?


#1

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

#2

This should do it Hansen,

It will even convert it to Celsius.


#3

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:


#4

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

Welcome to the HA Community!


#5

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


#6

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


#7

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) }}'


#8

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) }}'

#9

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


#10

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


#11

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.


#12

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


#13

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) }}'

#14

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.


#15

i thought so too. But apparently it does now.


#16

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!


#17

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)


#18

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 !!


#19

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.


#20

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