Display CPU temperature

I am trying to display the temperature of the CPU. I found discussions on this topic. One suggests adding this code to configuration.yaml:

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

That solution did not work for me because I already have the line

sensor: !include sensor.yaml

in my configuration.yaml. So I went to my sensor.yaml file and added everything but the sensor: line. I adjusted formatting to suppress complaints:

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

That code still does not work, but now the complaint is that there is a duplicated mapping key – platform, I believe. There is a platform: template in the same file. I took it out as an experiment. I reloaded scripts. I am expecting something to show up in Overview, but nothing does. Probably, I do not understand how to use this code. Furthermore, I need the other platform: entry. I hope that someone is willing to help an idiot. And while you are at it, can you explain why some lines in yaml files start with "- " and when lines need to be indented and by how much? Thanks.

i use this:

  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: "/"
      - type: memory_free
      - type: processor_use
        arg: "/"
      - type: disk_free
        arg: "/"
      - type: memory_use_percent
      - type: processor_temperature
      - type: last_boot

When I put that code in my sensor.yaml, I get “end of the stream or a document separator is expected”. I tried removing the "- " in front of platform and I moved every other line two spaces to the left. I then got “duplicated mapping key” with an up arrow seemingly pointing to “platform”. I tried putting a "- " in front of the other “platform” line in my sensor.yaml, adjusting the subsequent lines two spaces to the right, and restoring your code to its original form. I got a green light then, so I clicked Save, went to Developer Tools, clicked Check Configuration, and then clicked Scripts. Nothing new appeared in Overview. I then returned to File Editor. All of the changes I had made to sensor.yaml had vanished. I repeated all the steps. Still nothing appeared, but this time when I returned to File Editor the new code was still there. By the way, the other platform code in sensor.yaml is a template for sun azimuth and elevation. Those values do appear in Overview. Maybe your code is working now but I am looking in the wrong place for the values.

Yes, why not just use the systemmonitor integration? Bookoo information (this is from my configuration.yaml):

System Monitor Add-In

  • platform: systemmonitor
    resources:
    • type: disk_use_percent
      arg: /config
    • type: disk_use
    • type: disk_free
    • type: memory_use_percent
    • type: memory_use
    • type: memory_free
    • type: swap_use_percent
    • type: swap_use
    • type: swap_free
    • type: load_1m
    • type: load_5m
    • type: load_15m
    • type: network_in
      arg: eth0
    • type: network_out
      arg: eth0
    • type: throughput_network_in
      arg: eth0
    • type: throughput_network_out
      arg: eth0
    • type: packets_in
      arg: eth0
    • type: packets_out
      arg: eth0
    • type: ipv4_address
      arg: eth0

- type: ipv6_address

arg: eth0

  - type: processor_use
  - type: processor_temperature
  - type: last_boot

If systemmonitor integration is not working (it does not work for me), then format it like this in your sensor.yaml file.

This is for battery, however the formating should be the same for your temperatur.

- platform: command_line
  name: systemmonitor_battery0_level
  command: "cat /sys/class/power_supply/BAT0/capacity"
  unit_of_measurement: "%"

- platform: command_line
  name: systemmonitor_battery0_status
  command: "cat /sys/class/power_supply/BAT0/status"

I did not try systemmonitor, but the formatting you suggested worked. The mistake in my original attempt was not adding a "- " in front of the first platform (and two spaces in front of the remaining lines in that entry). I gather that "- " must indicate that there are multiple entries for the same key. I also realized that after clicking the save button in file editor I need to wait until I receive the acknowledgement that the contents were saved. Thanks, everyone.

I also use it
cat /sys/class/thermal/thermal_zone0/temp

It’s working fine
The problem - have zone 1 zone 2 zone 3 also

What it’s mean ?

Hi @3beezer I just added following into the configuration.yaml file and all works.

Making the PI performence Gauge

command_line:

  • sensor:
    name: CPU Temperature
    command: “cat /sys/class/thermal/thermal_zone0/temp”
    unit_of_measurement: “°C”
    value_template: “{{ value | multiply(0.001) | round(2) }}”

sensor:

  • platform: systemmonitor
    resources:
    • type: disk_use_percent
      arg: /config
    • type: disk_use
    • type: disk_free
    • type: memory_use_percent
    • type: memory_use
    • type: memory_free
    • type: swap_use_percent
    • type: swap_use
    • type: swap_free
    • type: load_1m
    • type: load_5m
    • type: load_15m
    • type: network_in
      arg: eth0
    • type: network_out
      arg: eth0
    • type: throughput_network_in
      arg: eth0
    • type: throughput_network_out
      arg: eth0
    • type: packets_in
      arg: eth0
    • type: packets_out
      arg: eth0
    • type: ipv4_address
      arg: eth0
    • type: ipv6_address
      arg: eth0
    • type: processor_use
    • type: processor_temperature
    • type: last_boot

The sensor part every line gives me the error “duplicate key” the other part works for CPU

Use this

1 Like