CPU temperature sensor

Hi!
I have a temperature sensor for the Raspberry Pi4 CPU and sometimes it becomes unavailable, its entity simply does not exist anymore. After the restart it reappears and sometimes disappears again. The sensor is in the sensors.yaml file.

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

Your sensor is exactly the example shown in Command Line - Home Assistant

Mind that the command_line format and options you use are now deprecated. Try re-typing it as the new format and let’s see.

PD: In my case i also have a RPi4 but instead I use the System Monitor - Home Assistant integration to retrive temperature (and others) and had zero issues in years.

1 Like

Where can I find the new command line format? I’m not very good at programming so any information would help me a lot.

Just check in the integration page for command_line how it looks like the same example now.

Also related: Move yaml configuration to integration key for command_line by gjohansson-ST · Pull Request #92824 · home-assistant/core · GitHub

I got it in the new format, but I get “unavailable”… what could be wrong?

command_line:
  - sensor:
      name: 'proxmox_cpu_temp2'
      unique_id: temperature_cpu_prox2
      command: "ssh -i /home/user/.ssh/id_rsa -o StrictHostKeyChecking=no [email protected] -t 'cat /sys/class/thermal/thermal_zone1/temp'"
      unit_of_measurement: "°C"
      scan_interval: 300
      value_template: '{{ (value | multiply(0.001)) | round(0) }}'

When I run the ssh command from within Homeassistant terminal, I get the temps, so I guess I got the acces bit right.

Please advise!
Thanks!

P.S.
I think I got it… I’m running HA supervised on top of Debian… probably I must put the key in some of the docker containers of HA

Try casting the value to a float first , before the multiply, as I’m not sure the command_line sensor by default parses any retrieved value as a numerical time but rather as a ‘generic’ string.
If that doesn’t work either, try retrieving the ‘value’ first, then working from there in the template.

Good luck!

Why is different temperature in
“sensor.processor_temperature”
and
Glances “cpu_thermal 0”

I don’t use glances so you might need to collect how it checks both integrations.
Assuming is not a delay thing, my bet is that it might be related with one being the ‘Core’ temperature and another being the ‘package’ temperature. I see multiple temperature sensors as well available when using Libre Hardware Monitor on my PC.