[SOLVED] Showing temperature in my conky

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
dollyp
Level 3
Level 3
Posts: 139
Joined: Sun Jul 24, 2011 4:50 pm

[SOLVED] Showing temperature in my conky

Post by dollyp »

I am using the following code to show the temperature of my laptop in conky:

Code: Select all

${color0}CPU Temp:${color5} $alignr${execi 10 sensors | grep 'Core 0' | awk {'print $3'}}
The result of this line shows +42.0A(degree symbol) C and the A has a small line above it (apologies to users of languages that show A s that way).

I copied the code from someone else's conky but now can't find it again.

1) How do I show the temperature as simply 42(degrees)C?
2) Is there a better way of finding the temperature?

dollyp

Mint 21.2 Cinnamon 5.8.4
Last edited by dollyp on Fri Nov 24, 2023 10:48 am, edited 1 time in total.
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Showing temperature in my conky

Post by AndyMH »

viewtopic.php?p=2305870&hilit=conky#p2305870
But the better answer is install the CPU temp applet and not do it in conky.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

I don't get it why people keep using sensors for this, while you can cat this from a file.. Running the program sensors every time for this takes way more cpu load then a cat from a file.

Save this into a file in the same folder as your conky script and call it check-cpu-temp.sh

Code: Select all

#!/bin/bash

arr=$(ls /sys/class/hwmon)

for hwmon in ${arr[@]}
do

     path="/sys/class/hwmon/$hwmon"
     name=$(cat $path/name)

     if [ "$name" = "coretemp" ]; then
       if [ -f "$path/temp1_input" ]; then

         celcius=$(echo "$(cat $path/temp1_input)/1000" | bc)
         farenheit=$(echo 1.8*$celcius+32 | bc)

         echo "$celcius °C"     # Comment out this line if you want Farenheit
#         echo "$farenheit °F"   # Comment out this line if you want Celcius

       else
         echo "No temp1 found."
       fi
     fi
done

Then in your conky change this part:
${execi 10 sensors | grep 'Core 0' | awk {'print $3'}}

into this:
${execpi 10 ./check-cpu-temp.sh}

Notice the p in execpi. That pastes the output of the bash script into your conky window.
Let me know if it worked for you.
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

And i just now learned about the hwmon object! :shock: :roll:
I knew about the platform object, but then you still had to know which hwmonX folder to use.. hwmon is so much better!
User avatar
all41
Level 19
Level 19
Posts: 9529
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Showing temperature in my conky

Post by all41 »

For my desktop conky:
{execi 2 cat /sys/devices/platform/coretemp.0/hwmon/hwmon2/temp2_input | cut -c1,2}C

Sometimes I find the temp reports in:

{execi 2 cat /sys/devices/platform/coretemp.0/hwmon/hwmon1/temp2_input | cut -c1,2}C
Everything in life was difficult before it became easy.
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

The only problem is.. when HWMON does a random shuffle at boot! And yes, that happens sometimes.. or when you add a nvme ssd or anything that adds a new hwmon folder. Then you have to change all your conky scripts! :roll: That's why i use a script like above. It goes through all hwmonX name files and checks for coretemp, or whatever chip you use and then a cat of the temp file(s).

In my case i run a script at boot time that checks all hwmon folders and output their names with path to /etc/hwmon

Bash script

Code: Select all

###########################################################
#                                                         #
#  Checks which hwmon path belongs to which chipset name  #
#                                                         #
#  Run at boot via rc.local                               #
#                                                         #
###########################################################

hwmonfile="/etc/hwmon"
sudo rm -f "$hwmonfile"

arr=$(ls /sys/class/hwmon)

for hwmon in ${arr[@]}
do

     path="/sys/class/hwmon/$hwmon"
     name=$(cat $path/name)

     # if name = nvme then find out which nvme it is!
     if [ "$name" = "nvme" ]; then
       name=$(find $path/device/ -maxdepth 1 -printf "%f\n" | grep nvme)
       name=${name:0:5}
     fi

     if [ "$1" = "silent" ]; then
      echo "$name $path" | sudo tee -a "$hwmonfile" > /dev/null
     else
      printf "SYSFS HWMON: "
      echo "$name $path" | sudo tee -a "$hwmonfile"
     fi

done


Ouput to /etc/hwmon

Code: Select all

acpitz /sys/class/hwmon/hwmon0
nvme0 /sys/class/hwmon/hwmon1
amdgpu /sys/class/hwmon/hwmon2
coretemp /sys/class/hwmon/hwmon3
nct6687 /sys/class/hwmon/hwmon4


In Conky i use this line to get my cpu1 temp (temp1 = cpu0 the global temp)

Code: Select all

${exec echo $(cat $(cat /etc/hwmon | grep coretemp | awk '{print $2}')/temp2_input)/1000 | bc}
If i want my fanspeed from the nct chipset i use

Code: Select all

${exec cat $(cat /etc/hwmon | grep nct6687 | awk  '{print $2}')/fan6_input}


This way i have always the correct name and path at every boot!
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Showing temperature in my conky

Post by Bleys »

Koentje wrote: Sun Nov 19, 2023 9:45 pm The only problem is.. when HWMON does a random shuffle at boot! And yes, that happens sometimes..
Why keep it simple when you can make it complicated :)
Conky offers direct access to hwmon and , surprising, with the sensor names.
Example for nvme0:
instead of ${hwmon hwmon1 temp 1 }°C just use ${hwmon nvme0 temp 1 }°C

Example for a Fan with my Sensorchip:
${hwmon nct6793 fan 2} U/min
Screen Capture_select-area_20231121180303.jpg
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

Hah.. :shock:

Edit: tested it, but does not work for me. ${hwmon nct6687 temp 1} did not produce anything. The same for ${hwmon nct6687 fan 1} or ${hwmon coretemp temp 1}. I think i'll stick with my rock solid solution! ;)
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

What version of Conky are you using?

Code: Select all

$ conky -v
conky 1.10.8 compiled Mon Mar 23 06:55:27 UTC 2020 for Linux 4.4.0-176-generic x86_64

Compiled in features:

System config file: /etc/conky/conky.conf
Package library path: /usr/lib/conky


 General:
  * math
  * hddtemp
  * portmon
  * IPv6
  * Curl
  * RSS
  * Weather (METAR)
  * Weather (XOAP)
  * wireless
  * support for IBM/Lenovo notebooks
  * nvidia
  * eve-online
  * builtin default configuration
  * old configuration syntax
  * Imlib2
  * apcupsd
  * iostats
  * ncurses
  * Internationalization support
  * PulseAudio

 Lua bindings:
  * Cairo
  * Imlib2
  * RSVG
 X11:
  * Xdamage extension
  * Xinerama extension (virtual display)
  * Xshape extension (click through)
  * XDBE (double buffer extension)
  * Xft
  * ARGB visual
  * Own window

 Music detection:
  * Audacious
  * MPD
  * MOC
  * XMMS2

 Default values:
  * Netdevice: eth0
  * Local configfile: $HOME/.conkyrc
  * Localedir: /usr/share/locale
  * Maximum netdevices: 64
  * Maximum text size: 16384
  * Size text buffer: 256
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Showing temperature in my conky

Post by Bleys »

Koentje wrote: Tue Nov 21, 2023 2:35 pm What version of Conky are you using?

Code: Select all

~$ conky -v
conky 1.12.2 compiled 2022-02-23 for Linux x86_64
hmm.. right, this does not work under 1.10. The hwmon number must be entered instead of the sensor name.
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

That explains it. I checked and it seems that 1.19 is the latest version. Maybe i should upgrade..
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

I think i'll keep my version! :roll:
To compile the new conky i need to install new cmake because ccmake doesn't work with version 3.16. But i tried to compile cmake version 3.28 and now i get loadcache() errors.. no idea why?! Spend an hour on it.
Going to timeshift my @ss back an hour!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

Man... i tried almost all versions of conky until 1.19.1 and they all have problems finding cairo or imlib modules!! And i can't seem to fix it.. :x
dollyp
Level 3
Level 3
Posts: 139
Joined: Sun Jul 24, 2011 4:50 pm

Re: Showing temperature in my conky

Post by dollyp »

Koentje wrote: Sun Nov 19, 2023 8:49 pm Then in your conky change this part:
${execi 10 sensors | grep 'Core 0' | awk {'print $3'}}

into this:
${execpi 10 ./check-cpu-temp.sh}

Notice the p in execpi. That pastes the output of the bash script into your conky window.
Let me know if it worked for you.
Thanks for all the replies. I can't say I followed all of the discussion. I am first of all trying to get the first solution from Koentje working. I created the text file as shown, chmod 755 then added this line to my conky ${execpi 10 .conky/check-cpu-temp.sh}( only difference being that I think it is in .conky/). If I understand the code this should at least have produced some output even "No temp1 found".

Koentje, your amplified solution of reading hwmon settings at start seems the best way since it will, I presume, lead to a conky that will work universally (?). Unfortunately my linux knowledge is not advanced enough to know what this means:

Code: Select all

In my case i run a script at boot time that checks all hwmon folders and output their names with path to /etc/hwmon

Bash script

Code: Select all

###########################################################
#                                                         #
#  Checks which hwmon path belongs to which chipset name  #
#                                                         #
#  Run at boot via rc.local                               #
#                                                         #
Script I can manage but where to put it, how it should be chmodded and what does run at boot via rc.local mean? Perhaps this is a step too far.

My installed conky is conky 1.12.2 compiled 2022-02-23 for Linux x86_64.

dollyp

LinuxMint 21.2 Cinnamon 5.8.4
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

If you have conky version 1.12 then this should work in your conky script and you don't need my bash scripts.
${hwmon coretemp temp 1}
or if you want the global temp of all cpu's then use this one
${hwmon coretemp temp 0}
User avatar
all41
Level 19
Level 19
Posts: 9529
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: Showing temperature in my conky

Post by all41 »

Koentje wrote: Sun Nov 19, 2023 9:45 pm The only problem is.. when HWMON does a random shuffle at boot! And yes, that happens sometimes.. or when you add a nvme ssd or anything that adds a new hwmon folder.

This way i have always the correct name and path at every boot!
I haven't had to cross this bridge after initially setting the hwmon directories.
If you have conky version 1.12 then this should work in your conky script and you don't need my bash scripts.
${hwmon coretemp temp 1}
or if you want the global temp of all cpu's then use this one
${hwmon coretemp temp 0}
But I will try your method. conky versions are the same.
Everything in life was difficult before it became easy.
dollyp
Level 3
Level 3
Posts: 139
Joined: Sun Jul 24, 2011 4:50 pm

Re: Showing temperature in my conky

Post by dollyp »

Koentje wrote: Wed Nov 22, 2023 1:05 pm If you have conky version 1.12 then this should work in your conky script and you don't need my bash scripts.
${hwmon coretemp temp 1}
or if you want the global temp of all cpu's then use this one
${hwmon coretemp temp 0}
${hwmon coretemp temp 1} works but ${hwmon coretemp temp 0} produces no output. Since I use a laptop I guess that the temp of the first core is probably good enough to represent the whole cpu.

I'm now only left with the issue of how to show the degree symbol without having the accented capital A. I wonder whether this is a result of the location setting, but I can live without it.

dollyp
Mint 21.2 Cinnamon 5.8.4
User avatar
AndyMH
Level 21
Level 21
Posts: 13759
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Showing temperature in my conky

Post by AndyMH »

dollyp wrote: Thu Nov 23, 2023 11:21 am I'm now only left with the issue of how to show the degree symbol without having the accented capital A. I wonder whether this is a result of the location setting, but I can live without it.
If you had read through the link I posted you would have seen the answer:

Code: Select all

NVME: ${goto 50}${hwmon 1 temp 8}${iconv_start UTF-8 ISO_8859-1}°C
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Showing temperature in my conky

Post by Koentje »

dollyp wrote: Thu Nov 23, 2023 11:21 am ${hwmon coretemp temp 1} works but ${hwmon coretemp temp 0} produces no output.
My bad.. there is no temp0 :oops:
Temp1 = global (Package id 0) and all the temp# after that are the cpu's seperate temps.
I'm now only left with the issue of how to show the degree symbol without having the accented capital A. I wonder whether this is a result of the location setting, but I can live without it.
If Andy's solution works, then that may be the case. Give it a try!
dollyp
Level 3
Level 3
Posts: 139
Joined: Sun Jul 24, 2011 4:50 pm

Re: Showing temperature in my conky

Post by dollyp »

AndyMH wrote: Thu Nov 23, 2023 1:42 pm If you had read through the link I posted you would have seen the answer:

Code: Select all

NVME: ${goto 50}${hwmon 1 temp 8}${iconv_start UTF-8 ISO_8859-1}°C
Apologies AndyMH, was following several of the other threads and didn't get back to yours. Anyway it is the solution I was looking for.
My bad.. there is no temp0 :oops:
Temp1 = global (Package id 0) and all the temp# after that are the cpu's seperate temps.
They don't half make it difficult. As a past database user/coder I always had difficulty remembering that item 0 is the first item. Here core 2 is the first core :roll:

Anyway, problem solved and thanks to all
dollyp
Post Reply

Return to “Compiz, Conky, Docks & Widgets”