Using Sensors (en)

From Conky PitStop

Jump to: navigation, search


Using Sensors

 Language   English   Français   

Using Sensors in Conky - Updated HowTo from mrpeachy - added 28 Aug 2012

Three ways that I know of, but first


in a terminal you should see something like this:

 Adapter: PCI adapter
 temp1:       +24.9°C  (high = +70.0°C)

 Adapter: ISA adapter
 Vcore:       +0.99 V  (min =  +0.00 V, max =  +1.74 V)
 in1:         +0.02 V  (min =  +1.58 V, max =  +1.30 V)   ALARM
 AVCC:        +3.25 V  (min =  +2.98 V, max =  +3.63 V)
 VCC:         +3.25 V  (min =  +2.98 V, max =  +3.63 V)
 in4:         +1.87 V  (min =  +0.08 V, max =  +1.31 V)   ALARM
 in5:         +1.69 V  (min =  +1.41 V, max =  +0.52 V)   ALARM
 in6:         +1.63 V  (min =  +0.07 V, max =  +0.29 V)   ALARM
 3VSB:        +3.49 V  (min =  +2.98 V, max =  +3.63 V)
 Vbat:        +3.46 V  (min =  +2.70 V, max =  +3.30 V)   ALARM
 fan1:       2033 RPM  (min = 3125 RPM, div = 8)  ALARM
 fan2:       3183 RPM  (min = 1088 RPM, div = 8)
 fan3:          0 RPM  (min = 4218 RPM, div = 32)  ALARM
 fan5:          0 RPM  (min = 21093 RPM, div = 32)  ALARM
 temp1:       +32.0°C  (high = -112.0°C, hyst = +24.0°C)  ALARM  sensor = thermistor
 temp2:       +36.0°C  (high = +80.0°C, hyst = +75.0°C)  sensor = thermistor
 temp3:       +28.5°C  (high = +80.0°C, hyst = +75.0°C)  sensor = thermistor

Note I have 2 sets of sensor information, one from k10temp-pci-00c3 and the other from w83627dhg-isa-0290 this will be important for the 2nd and 3rd methods. Yours will be different, the methods are the same.

Added info from Sector11:

Depending on your Linux distro you may need to use:

sudo sensors-detect

and at the end:

Do you want to add these lines automatically to /etc/modules? (yes/NO)y
Monitoring programs won't work until the needed modules are
loaded. You may want to run '/etc/init.d/kmod start'
to load them.

Unloading i2c-dev... OK
Unloading cpuid... OK

  28 Aug 12 | 14:18:20 ~
         $ /etc/init.d/kmod start
[info] Loading kernel module fuse.
[info] Loading kernel module loop.
[info] Loading kernel module f71882fg.
[info] Loading kernel module f71882fg.
[info] Loading kernel module f71882fg.
[info] Loading kernel module nvidia.
[info] Loading kernel module f71882fg.
[info] Loading kernel module f71882fg.

  28 Aug 12 | 14:18:47 ~

Now to get the info into conky

METHOD 1 - grep, awk, sed, etc. (old way, some new info)

This can be perhaps the most straightforward approach, but it will be the most expensive (CPU resources) as it will use the exec (execi or execpi) commands in conky.

So, you see some info you want to display in your conky from the output of sensors

Say I want to get the temp from this line

temp1:       +32.0°C  (high = -112.0°C, hyst = +24.0°C)  ALARM  sensor = thermistor

if you look above you can see that there are 2 readings for temp1, and this makes things just a little trickier.

The first thing is to use grep to pull the line we want out of the sensors data

sensors | grep 'temp1'

this will match both lines that contain temp1, so instead you can use

sensors | grep -n 'temp1' | sed -n 2p

This matches the lines with "temp1" in them, assigns them numbers then the sed command prints (in this case with 2p) only the second match.

So now we have

3:temp1:       +25.0°C  (high = +70.0°C)

but let's say that we just want the number. Lots of examples use the cut command to do this, I prefer awk, so i would do it like this:

awk -F'+' '{print $2}' | awk -F' ' '{print $1}'

it first looks for "+" and cuts the line at that point, printing the second piece, then it looks for " " (a space) cuts the line and prints the first piece

As I said there are many different ways to do this step.

So the whole conky line would be:

${exec sensors | grep -n 'temp1' | sed -n 2p | awk -F'+' '{print $2}' | awk -F' ' '{print $1}'}

You can make the exec an execi, perhaps with a 5 or 10 second interval (eg ${execi 10) to cut down on the CPU usage.

Using the above line I see in conky "32.0°C"

You could change the above to:

${exec sensors | grep -n 'temp1' | sed -n 2p | awk -F'+' '{print $2}' | awk -F'.' '{print $1}'}

which would just give you the number, without the decimal, i.e. "32"

2 Additional awk only methods

EDIT-ADDITIONAL: from stinkeye

Sometimes you might find that when you run sensors after a restart the sensors load in a different order k10temp-pci-00c3 may not necessarily be shown first. If this is the case the above commands will give you a different reading, as (in the example above) you are matching the first instance of temp1. To get around this, you can call each sensor individually by typing the name of the sensor after the sensors command like so:

sensors k10temp-pci-00c3

Then you can use similar grep and awk commands to get the temp number

sensors k10temp-pci-00c3 | grep 'temp1' | awk -F'+' '{print $2}' | awk -F'.' '{print $1}'

You don't need the sed commands as there will only be one temp1 for grep to match

WARNING I suspect that the loading order of the sensors will also affect the contents of the hwmon folders used in method 2 below. Note: confirmed, it does - at times (thank you VastOne).

EDIT-ADDITIONAL #2: from DK75 - another awk only

sensors -f | awk '/Core0 Temp/ {gsub(/\+/,"",$3); gsub(/\..+/,"",$3); print $3}'

And the best part ... what all that means.


sensors -f

sensors in fahrenheit. The default unit is celsius.

/Core0 Temp/

match the line with 'Core0 Temp' in it.


removes "+" sign from substring $3 - it replaces regexp match "/\+/" ("+" sign is escaped with "\", as it is a special character in regexps), with string "" (empty) in a substring $3 ($1 = "Core0", $2="Temp")

With $3 equalling "+122.0°F", it removes "+" from it making $3 equal "122.0°F" after the change.


replaces regexp "/\..+/" with string "" in substring $3 (again - why not? since it is already processed by one "gsub"...)

in match "/\..+/" there are few special characters:

'\.' - escaped dot (dot in regexp means "any one character", escaped "dot" means just "dot")
'.+' - "dot plus" means "any one character repeated at least once" ("+" character is "repeat at least once" in regexp)

Combined, it is "dot and at least one character after".

Since $3 is now "122.0°F", see above, it removes ".0°F" from it, making $3 = "122"

METHOD 2 - hwmon

I had 2 sets of sensor information, which means I will have 2 hwmon folders... found here


the important stuff is found in the /device folder found within both /hwmon0 and /hwmon1 (or /hwmon3, etc. depending on the number of CPU's).

For me it looks like this:

Mrpeachy-HowTo GetSensorsInConky 0.png

Look back at my sensors output, it is usually the case that /hwmon0 contains the info from the first set of sensor info (k10temp-pci-00c3) and /hwmon1 the second set (w83627dhg-isa-0290). Which is why /hwmon1 contains a lot more info than /hwmon0.

All the files in the hwmon folders relate directly to the information you see when you run sensors

The good thing about hwmon is that it is built into conky, and will be much cheaper to run (CPU resources) ... here is the hwmon command from this page: [URL][/URL]

hwmon (dev) type n (factor offset) Hwmon sensor from sysfs (Linux 2.6). Parameter dev may be omitted if you have only one hwmon device. Parameter type is either 'in' or 'vol' meaning voltage; 'fan' meaning fan; 'temp' meaning temperature. Parameter n is number of the sensor. See /sys/class/hwmon/ on your local computer. The optional arguments 'factor' and 'offset' allow precalculation of the raw input, which is being modified as follows: 'input = input * factor + offset'. Note that they have to be given as decimal values (i.e. contain at least one decimal place)

So first you type ${hwmon then you need to put the folder number (in my case 0 or 1) then you need to put in what info you want, either a voltage (in or vol), a fan speed (fan) or a temperature (temp).

So lets get the same temp1 info as we did with METHOD 1

It should be simply:

${hwmon 1 temp 1}

make sure you keep the spaces as above the output is just the numerical part and nothing else, so in conky I see only "32"

You'll need to add the °C/F if you want it:

${hwmon 1 temp 1}°F

METHOD 3 - platform - preferred IMHO

This is very similar to hwmon and is again built into conky.

you will find the relevant files in


this is what I have in my platform folder (using "ls /sys/devices/platform" in a terminal)

Fixed MDIO bus.0

looking at those you can see the last one matches the second of the sensors when you run sensors in a terminal.

However, I don't have the info from the first sensor

Adapter: PCI adapter
temp1:       +24.0°C  (high = +70.0°C)

available using this method.

Mrpeachy-HowTo GetSensorsInConky 1.png
However, looking in the folder named "w83627ehf.656" I see this info very much like in my hwmon1 folder in conky you get it out like this ..."platform" followed by the correct folder name followed by what info you want
${platform w83627ehf.656 temp 1}

again, keep the spaces just like hwmon since you only get the number.

And again add the °C/F if you wish:

${platform w83627ehf.656 temp 1}°C

INXI - the bash script - check the "-s" option

Some people (me included) get confused when they see a very busy "sensors" output like mrpeachy posted. What belongs to what?

This is where the bash script inxi comes is handy with it's sensors option "-s"

 21 Jun 13 | 13:02:05 ~
    $ inxi -s
Sensors:   System Temperatures: cpu: 39.0C mobo: 34.0C gpu: 43C 
           Fan Speeds (in rpm): cpu: 2121 fan-2: 0 fan-3: 0 
 21 Jun 13 | 13:11:43 ~

run sensors && inxi -s and you see them both together.

 21 Jun 13 | 13:38:49 ~
    $ sensors && inxi -s
Adapter: Virtual device
temp1:        +30.0°C  (crit = +110.0°C)

Adapter: PCI adapter
temp1:        +29.5°C  (high = +70.0°C)

Adapter: ISA adapter
+3.3V:        +3.44 V  
in1:          +1.35 V  
in2:          +1.51 V  
in3:          +0.85 V  
in4:          +0.00 V  
in5:          +0.00 V  
in6:          +0.00 V  
3VSB:         +3.41 V  
Vbat:         +2.86 V  
fan1:        2018 RPM
fan2:           0 RPM  ALARM
fan3:           0 RPM  ALARM
temp1:        +38.0°C  (high = +85.0°C, hyst = +81.0°C)
                       (crit = +70.0°C, hyst = +66.0°C)  sensor = transistor
temp2:        +34.0°C  (high = +85.0°C, hyst = +81.0°C)
                       (crit = +100.0°C, hyst = +96.0°C)  sensor = thermistor
temp3:       +127.0°C  (high = +70.0°C, hyst = +68.0°C)  ALARM (CRIT)
                       (crit = +85.0°C, hyst = +83.0°C)  sensor = transistor

Sensors:   System Temperatures: cpu: 38.0C mobo: 34.0C gpu: 43C 
           Fan Speeds (in rpm): cpu: 2018 fan-2: 0 fan-3: 0 
 21 Jun 13 | 13:39:08 ~

Now we know what "sensor" belongs to what piece of hardware by matching the outputs.

Personal tools