Conky Show Fahrenheit instead of Celcius

Forum rules
Before you post please read how to get help
Post Reply
briant97
Level 1
Level 1
Posts: 6
Joined: Tue Dec 11, 2012 5:41 pm

Conky Show Fahrenheit instead of Celcius

Post by briant97 » Thu May 10, 2018 3:54 pm


User avatar
zcot
Level 2
Level 2
Posts: 70
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky Show Fahrenheit instead of Celcius

Post by zcot » Thu May 10, 2018 11:12 pm

the interested line is:

Code: Select all

${color6}Cpu Temp ${alignr}${color6}${execi 10 sensors | grep 'Core 0' | awk {'print $3'}}${color}
strip the conky markup and in a terminal we can run directly:

Code: Select all

sensors | grep 'Core 0' | awk {'print $3'}
But, that output isn't too useful alone to be able to make a conversion. We can't do math on it directly and of course it already has the C there.. and there's the other extra characters.

I get no output and if I just check sensors command I do see I could grep for line 'temp1', But also, the actual temp is in the second position so I end up with:

Code: Select all

sensors | grep 'temp1' | awk {'print $2'}
Anyway, but we do know that this output is very predictable. We should know the temp will never come out as a single digit going below 10 degrees(or 3 character ie. 9.5). So we can safely assume in this case that the output will always be 7 characters total. That's the + sign, then 4 characters making up the numeric temperature(54.2), then the degree sign and C. So, use cut. ( check on terminal: cut --help )

continue the processing with:

Code: Select all

cut -c2-5
(sidenote: there is the possibility that the output could come out as 100 degrees C which adds another character, but in this case it's not so bad it would only change the math by cutting off the decimal place... well 100C is just really bad anyway so who cares whether conky works or not during a fire)


try it on terminal:

Code: Select all

sensors | grep 'Core 0' | awk {'print $3'} | cut -c2-5

I think the math functions we want, and to be able to get good formatting, need to receive a variable, so we make the whole chunk into a variable. -talking about bc:

Code: Select all

CTMP=$(sensors | grep 'Core 0' | awk {'print $3'} | cut -c2-5)
can echo to check:

Code: Select all

CTMP=$(sensors | grep 'Core 0' | awk {'print $3'} | cut -c2-5); echo $CTMP;

Honestly I don't know how to do any of this stuff, but I just go searching the internet tubes and doing some tests and more searching and using <command> --help and/or man <command>.

now it's ready to convert: celcius_temp * 9 / 5 + 32

Code: Select all

CTMP=$(sensors | grep 'Core 0' | awk {'print $3'} | cut -c2-5); echo "scale=1; ${CTMP} * 9 / 5 + 32" | bc
..because bc wants a formulated string piped into it. That's what all the example I found said.

So, now, that should work for the most part. But it should really be dressed back up with at least a degree marker so it's obvious what it is specifying. ;)

the new incomplete line looks like this:

Code: Select all

${color6}Cpu Temp ${alignr}${color6}${execi 10 CTMP=$(sensors | grep 'Core 0' | awk {'print $3'} | cut -c2-5); echo "scale=1; ${CTMP} * 9 / 5 + 32" | bc}${color}

briant97
Level 1
Level 1
Posts: 6
Joined: Tue Dec 11, 2012 5:41 pm

Re: Conky Show Fahrenheit instead of Celcius

Post by briant97 » Thu May 10, 2018 11:40 pm

That last line worked only thing not displaying is the Farenheit temp sign. How would I make it display that.

Image

User avatar
zcot
Level 2
Level 2
Posts: 70
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky Show Fahrenheit instead of Celcius

Post by zcot » Fri May 11, 2018 12:56 am

I would use °F for sure. :D

It's just text, so you just observe the typical scheming there depending on which color or whatever. If you want a different color go to the end of the line and encapsulate it in some color markers. Or you could use the exising color and keep it inside the existing markers.

User avatar
Flemur
Level 16
Level 16
Posts: 6187
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Conky Show Fahrenheit instead of Celcius

Post by Flemur » Fri May 11, 2018 9:26 am

Code: Select all

Up  : $uptime
DNUP: ${color green}${downspeedf wlx74da383b4124} ${upspeedf wlx74da383b4124}KiB : ${color yellow}/SDA:${diskio sda} ${color}
CPU%: ${cpu cpu1}% ${cpu cpu2}% : CPUf: ${freq cpu1} ${freq cpu2}
CTMP: ${exec sensors -f | grep 'Core 0' | cut -c15-21 } ${exec sensors -f | grep 'Core 1' | cut -c15-21 }F
RAM : $mem/$memmax - $memperc% ${membar 6}
SWP : $swap/$swapmax - $swapperc% ${swapbar 6}
conky.jpg
conky.jpg (15.16 KiB) Viewed 668 times
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Mint 18.3 Xfce/fluxbox/pulse-less
Xubuntu 17.10/fluxbox/pulse-less

User avatar
zcot
Level 2
Level 2
Posts: 70
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky Show Fahrenheit instead of Celcius

Post by zcot » Fri May 11, 2018 10:04 am

Flemur wrote:
Fri May 11, 2018 9:26 am

Code: Select all

CTMP: ${exec sensors -f | grep 'Core 0' | cut -c15-21 } ${exec sensors -f | grep 'Core 1' | cut -c15-21 }F
lol.. :shock:

sensors -f. Who'da thunk it. And why not just cut the temp right out of it since it's always predictable output. :roll:

good stuff. :D

asinoro
Level 4
Level 4
Posts: 246
Joined: Mon Feb 12, 2018 11:43 am

Re: Conky Show Fahrenheit instead of Celcius

Post by asinoro » Fri May 11, 2018 10:22 am

cpu.png
cpu.png (20.93 KiB) Viewed 662 times

Code: Select all

${color Tan1}CPU Usage:${color9}$alignr${cpubar 8,145} ${color9}$cpu%@${freq_g cpu}GHz
${color1}CPU 0 ${offset 9}${color9}${cpu cpu0}% (${execi 8 sensors | grep -A 1 'temp1' | cut -c16-19 | sed '/^$/d'}°C)   
${color1}CPU 1 ${offset 9}${color9}${cpu cpu1}% (${execi 8 sensors | grep -A 1 'temp1' | cut -c16-19 | sed '/^$/d'}°C)

User avatar
zcot
Level 2
Level 2
Posts: 70
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky Show Fahrenheit instead of Celcius

Post by zcot » Sat May 12, 2018 12:43 am

asinoro wrote:
Fri May 11, 2018 10:22 am

Code: Select all

${color1}CPU 0 ${offset 9}${color9}${cpu cpu0}% (${execi 8 sensors | grep -A 1 'temp1' | cut -c16-19 | sed '/^$/d'}°C)   
so in grep -A 1 gives an extra line after it finds the 'temp1' line, then cut brings the right data from the correct line, but then sed removes the rest and the extra line? Is that correct?

from grep:
-A, --after-context=NUM print NUM lines of trailing context
is it the same thing:

Code: Select all

${color1}CPU 0 ${offset 9}${color9}${cpu cpu0}% (${execi 8 sensors | grep 'temp1' | cut -c16-19}°C)
so then:

Code: Select all

${color1}CPU 0 ${offset 9}${color9}${cpu cpu0}% (${execi 8 CTMP=$(sensors | grep 'temp1' | cut -c16-19); echo -n ${CTMP}"°C / "; echo "scale=1; ${CTMP} * 9 / 5 + 32" | bc}°F)
:P

SRW
Level 1
Level 1
Posts: 2
Joined: Tue May 15, 2018 4:27 pm

Re: Conky Show Fahrenheit instead of Celcius

Post by SRW » Tue May 15, 2018 4:34 pm

Just curious here...why use ${exec sensors ... } instead of using ${hwmon} or ${platform} for cpu temp?

User avatar
zcot
Level 2
Level 2
Posts: 70
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky Show Fahrenheit instead of Celcius

Post by zcot » Wed May 16, 2018 4:00 pm

SRW wrote:
Tue May 15, 2018 4:34 pm
Just curious here...why use ${exec sensors ... } instead of using ${hwmon} or ${platform} for cpu temp?
I've always used hwmon, as that's how I first saw it, and exec seemed like something for advanced things.

I would think hwmon would be a more efficient approach, although the data is potentially different on each system so each person has to know what to go looking for(or just randomly test devices 0, 1, etc. and for each possible sensor 0, 1, 2), to tweak each config. Maybe it seems easier just looking at the sensors output then finding how to grep it for the situation?

but, for that matter, the output from sensors is equally different on any system too, and you still end up tweaking the values.

The conky variables doc does say,
"exec: Executes a shell command and displays the output in conky. warning: this takes a lot more resources than other variables. I'd recommend coding wanted behaviour in C and posting a patch."

So, it's a good point, and in these cases it would also eliminate the grep, cut, and more, even aside from the more resources of using exec.

SRW
Level 1
Level 1
Posts: 2
Joined: Tue May 15, 2018 4:27 pm

Re: Conky Show Fahrenheit instead of Celcius

Post by SRW » Wed May 16, 2018 9:13 pm

zcot wrote:
Wed May 16, 2018 4:00 pm
SRW wrote:
Tue May 15, 2018 4:34 pm
Just curious here...why use ${exec sensors ... } instead of using ${hwmon} or ${platform} for cpu temp?
I've always used hwmon, as that's how I first saw it, and exec seemed like something for advanced things.

I would think hwmon would be a more efficient approach, although the data is potentially different on each system so each person has to know what to go looking for(or just randomly test devices 0, 1, etc. and for each possible sensor 0, 1, 2), to tweak each config. Maybe it seems easier just looking at the sensors output then finding how to grep it for the situation?

but, for that matter, the output from sensors is equally different on any system too, and you still end up tweaking the values.

The conky variables doc does say,
"exec: Executes a shell command and displays the output in conky. warning: this takes a lot more resources than other variables. I'd recommend coding wanted behaviour in C and posting a patch."

So, it's a good point, and in these cases it would also eliminate the grep, cut, and more, even aside from the more resources of using exec.
Makes sense, thankfully I have yet to run into a situation where hwmon or platform didn't work for me. Using exec sensors for something as simple as CPU temp seems to add complexity to a simple task, but whatever works, works...(hopefully) :)

Post Reply

Return to “Compiz, Conky, Docks, & Widgets”