Welcome!
Important information
-- Required MX 15/16 Repository Changes
-- Information on torrent hosting changes
-- Information on MX15/16 GPG Keys
-- Spectre and Meltdown vulnerabilities

News
-- Introducing our new Website
-- MX Linux on social media: here

Current releases
-- MX-18.3 Point Release release info here
-- Migration Information to MX-18 here
-- antiX-17.4.1 release info here

New users
-- Please read this first, and don't forget to add system and hardware information to posts!
-- Here are the Forum Rules

[SOLVED] Conky help needed

User avatar
JayM
Forum Regular
Forum Regular
Posts: 955
Joined: Tue Jan 08, 2019 4:47 am

[SOLVED] Conky help needed

#1

Post by JayM » Sat Mar 16, 2019 9:24 am

I'm attempting to nest if_match statements to accomplish the following: I want the CPU temperature displayed in green text when it's less than 40 degrees C, in yellow text when it's 40-49, and in red when it's 50 or higher. I got it to transition from green to yellow like I want, but when the temp reaches 50 the temp displays in yellow followed by the temp in red, so I get the temp twice, in yellow and red, instead of it changing from yellow to red as it did from green to yellow. So my first if/else works but my second one is (wait for it)...conky. This is starting to make me pull what's left of my hair out. Help? Thanks.

Code: Select all

color1 FFFFFF
color2 FF9616
color3 1CE3BB
color4 FFFF00 #yellow
color5 009900 #green
color6 FF0000 #red
###########################
own_window_colour 000000
TEXT

${if_match ${hwmon 0 temp 1} <40}${color5}${hwmon 0 temp 1}°C${color}${else}${if_match ${hwmon 0 temp 1} >39}${color4}${hwmon 0 temp 1}°C${color}${else}${if_match ${hwmon 0 temp 1} >50}${color6}${hwmon 0 temp 1}°C${color}${endif}

Last edited by JayM on Mon Mar 18, 2019 3:11 am, edited 3 times in total.
New users: Please read this first, and don't forget to add system and hardware information (Quick System Info) to posts!

jonnken
Forum Novice
Forum  Novice
Posts: 36
Joined: Thu Mar 14, 2019 12:22 pm

Re: Conky help needed

#2

Post by jonnken » Sat Mar 16, 2019 10:18 am

wonder what happens if the temperature is 39.5? Both the first two arguments would be true, no? There are also two true arguments, when the temp is >50. Can one use >= signs in this coding?

I'm not experienced in the coding your doing. But in spreadsheet logic functions, one can include AND arguments within an IF function. Such that =IF(AND(temp>=40, temp<=50),"then this result", "if false this result"). This AND functioning would only be necessary for the middle temperature between 40 and 50.

Also in the spreadsheet world...the correct sequencing of un-nested arguments can achieve good chart results. One posting gets pasted over a previous one. So when the temperature is >50, both >40 and >50 results would display...but the >50 RED result would display and cover the >40 YELLOW. Maybe three separate un-nested arguments?
Regards, jonnken
MX-18.1_386 Continuum(32 bit)...Kernel: 4.19.0-1-686-pae...since Feb 2019
Dell Latitude D630.....Intel Core2 Duo T7700...BIOS A19(June 2013)...Memory: 4G Ram 55G SSD

User avatar
fehlix
Forum Veteran
Forum Veteran
Posts: 3930
Joined: Wed Apr 11, 2018 5:09 pm

Re: Conky help needed

#3

Post by fehlix » Sat Mar 16, 2019 11:17 am

JayM wrote:
Sat Mar 16, 2019 9:24 am

Code: Select all

${if_match ${hwmon 0 temp 1} <40}${color5}${hwmon 0 temp 1}°C${color}${else}${if_match ${hwmon 0 temp 1} >39}${color4}${hwmon 0 temp 1}°C${color}${else}${if_match ${hwmon 0 temp 1} >50}${color6}${hwmon 0 temp 1}°C${color}${endif}
In the code above you have 3 if_match's but only one endif.
Suggest this instead - shown here a bit structured:

Code: Select all

${if_match ${hwmon 0 temp 1} <40}
  ${color5}${hwmon 0 temp 1}°C${color}
${else}
  ${if_match ${hwmon 0 temp 1} >50}
    ${color6}${hwmon 0 temp 1}°C${color}
  ${else}
    ${color4}${hwmon 0 temp 1}°C${color}
  ${endif}
${endif}
and here the same in one line:

Code: Select all

${if_match ${hwmon 0 temp 1} <40}${color5}${hwmon 0 temp 1}°C${color}${else}${if_match ${hwmon 0 temp 1} >50}${color6}${hwmon 0 temp 1}°C${color}${else}${color4}${hwmon 0 temp 1}°C${color}${endif}${endif}
HTH
:puppy:
Gigabyte Z77M-D3H, Intel Xeon E3-1240 V2 (Quad core), 32GB RAM,
GeForce GTX 770, Samsung SSD 850 EVO 500GB, Seagate Barracuda 4TB

jonnken
Forum Novice
Forum  Novice
Posts: 36
Joined: Thu Mar 14, 2019 12:22 pm

Re: Conky help needed

#4

Post by jonnken » Sat Mar 16, 2019 11:36 am

an elegant solution...two IF arguments for the out-liers (<40, >50)...and the middle temp range as the default color
Regards, jonnken
MX-18.1_386 Continuum(32 bit)...Kernel: 4.19.0-1-686-pae...since Feb 2019
Dell Latitude D630.....Intel Core2 Duo T7700...BIOS A19(June 2013)...Memory: 4G Ram 55G SSD

User avatar
JayM
Forum Regular
Forum Regular
Posts: 955
Joined: Tue Jan 08, 2019 4:47 am

Re: Conky help needed

#5

Post by JayM » Sat Mar 16, 2019 9:35 pm

jonnken wrote:
Sat Mar 16, 2019 10:18 am
wonder what happens if the temperature is 39.5? Both the first two arguments would be true, no? There are also two true arguments, when the temp is >50. Can one use >= signs in this coding?

I'm not experienced in the coding your doing. But in spreadsheet logic functions, one can include AND arguments within an IF function. Such that =IF(AND(temp>=40, temp<=50),"then this result", "if false this result"). This AND functioning would only be necessary for the middle temperature between 40 and 50.

Also in the spreadsheet world...the correct sequencing of un-nested arguments can achieve good chart results. One posting gets pasted over a previous one. So when the temperature is >50, both >40 and >50 results would display...but the >50 RED result would display and cover the >40 YELLOW. Maybe three separate un-nested arguments?
Supported operands are: '>', '<', '>=', '<=', '==', '!='. I had tried it using some of them earlier but my conky wouldn't even run.

There aren't any AND statements allowed in conkys, but supposedly you can emulate one using nested if statements:

Code: Select all

${if_match ${something} >10} ${if_match ${something} <20}Something is between 10 and 20${endif}${endif}
New users: Please read this first, and don't forget to add system and hardware information (Quick System Info) to posts!

User avatar
JayM
Forum Regular
Forum Regular
Posts: 955
Joined: Tue Jan 08, 2019 4:47 am

Re: Conky help needed

#6

Post by JayM » Sat Mar 16, 2019 9:41 pm

fehlix wrote:
Sat Mar 16, 2019 11:17 am
JayM wrote:
Sat Mar 16, 2019 9:24 am

Code: Select all

${if_match ${hwmon 0 temp 1} <40}${color5}${hwmon 0 temp 1}°C${color}${else}${if_match ${hwmon 0 temp 1} >39}${color4}${hwmon 0 temp 1}°C${color}${else}${if_match ${hwmon 0 temp 1} >50}${color6}${hwmon 0 temp 1}°C${color}${endif}
In the code above you have 3 if_match's but only one endif.
Suggest this instead - shown here a bit structured:

Code: Select all

${if_match ${hwmon 0 temp 1} <40}
  ${color5}${hwmon 0 temp 1}°C${color}
${else}
  ${if_match ${hwmon 0 temp 1} >50}
    ${color6}${hwmon 0 temp 1}°C${color}
  ${else}
    ${color4}${hwmon 0 temp 1}°C${color}
  ${endif}
${endif}
and here the same in one line:

Code: Select all

${if_match ${hwmon 0 temp 1} <40}${color5}${hwmon 0 temp 1}°C${color}${else}${if_match ${hwmon 0 temp 1} >50}${color6}${hwmon 0 temp 1}°C${color}${else}${color4}${hwmon 0 temp 1}°C${color}${endif}${endif}
HTH
:puppy:
Thank you, sir. That does indeed work. I didn't merely copy/paste it either, I edited my own code to follow the logic pattern of yours to ensure that I understood what it was doing: If the temp is less than 40 use green text, if it's greater than 50 use red text, otherwise just use yellow for everything else that doesn't match those conditions. (No need to use a third "if" statement to satisfy the midrange temp conditions as I was doing.)
New users: Please read this first, and don't forget to add system and hardware information (Quick System Info) to posts!

jonnken
Forum Novice
Forum  Novice
Posts: 36
Joined: Thu Mar 14, 2019 12:22 pm

Re: Conky help needed

#7

Post by jonnken » Sat Mar 16, 2019 10:22 pm

noob question....where in your terminal/or otherwise...do you enter this code?
Regards, jonnken
MX-18.1_386 Continuum(32 bit)...Kernel: 4.19.0-1-686-pae...since Feb 2019
Dell Latitude D630.....Intel Core2 Duo T7700...BIOS A19(June 2013)...Memory: 4G Ram 55G SSD

User avatar
JayM
Forum Regular
Forum Regular
Posts: 955
Joined: Tue Jan 08, 2019 4:47 am

Re: Conky help needed

#8

Post by JayM » Sun Mar 17, 2019 1:02 am

jonnken wrote:
Sat Mar 16, 2019 10:22 pm
noob question....where in your terminal/or otherwise...do you enter this code?
In MX Conky click Conky Manager, select your Conky then click the Edit button. Or just go to ./conky in your home directory and edit directly in Featherpad or Geany.
Last edited by JayM on Sun Mar 17, 2019 7:45 am, edited 1 time in total.
New users: Please read this first, and don't forget to add system and hardware information (Quick System Info) to posts!

User avatar
JayM
Forum Regular
Forum Regular
Posts: 955
Joined: Tue Jan 08, 2019 4:47 am

Re: Conky help needed

#9

Post by JayM » Sun Mar 17, 2019 4:46 am

I "unsolved" this because now my hard drive temperatures aren't behaving and I'm not seeing what the problem is. Maybe an extra pair of eyes will see what I'm missing. My drive sdb is currently at 41 degrees but its temp is still showing as green, not yellow. The CPU temp is working OK. Temperatures for these three devices are being displayed, it's just the change in font color according to temperature that isn't working as expected/desired for the hard drive(s).

Code: Select all

(stuff omitted for brevity)
color4 FFFF00 #yellow
color5 009900 #green
color6 FF0000 #red
###########################
own_window_colour 000000
TEXT

${if_match ${hwmon 0 temp 1} <40}${color5}${hwmon 0 temp 1}°C${color}
	${else}
${if_match ${hwmon 0 temp 1} >50} ${color6}${hwmon 0 temp 1}°C${color}
	${else}
${color4}${hwmon 0 temp 1}°C${color}
${endif}
${endif}

${if_match ${exec /usr/sbin/hddtemp /dev/sda | awk '{print $3}'} <40}${color5}${exec /usr/sbin/hddtemp /dev/sda | awk '{print $3}'}${color}
	${else}
${if_match ${exec /usr/sbin/hddtemp /dev/sda | awk '{print $3}'} >50}${color6}${exec /usr/sbin/hddtemp /dev/sda | awk '{print $3}'}${color}
	${else}  
${color4}${exec /usr/sbin/hddtemp /dev/sda | awk '{print $3}'}${color}
${endif}
${endif}
		
${if_match ${exec /usr/sbin/hddtemp /dev/sdb | awk '{print $4}'} <40}${color5}${exec /usr/sbin/hddtemp /dev/sdb | awk '{print $4}'}${color}
	${else}
${if_match ${exec /usr/sbin/hddtemp /dev/sdb | awk '{print $4}'} >50}${color6}${exec /usr/sbin/hddtemp /dev/sdb | awk '{print $4}'}${color}
	${else}  
${color4}${exec /usr/sbin/hddtemp /dev/sdb | awk '{print $4}'}${color}
${endif}
${endif}
Image
New users: Please read this first, and don't forget to add system and hardware information (Quick System Info) to posts!

jonnken
Forum Novice
Forum  Novice
Posts: 36
Joined: Thu Mar 14, 2019 12:22 pm

Re: Conky help needed

#10

Post by jonnken » Sun Mar 17, 2019 7:39 am

In Spreadsheet grammar, an IF bracket encapsulates the AND logic result. So if two IF's are used to generate the AND true/false result...then wouldn't a third IF be needed to REDIRECT the AND result of the first two IF's?
Regards, jonnken
MX-18.1_386 Continuum(32 bit)...Kernel: 4.19.0-1-686-pae...since Feb 2019
Dell Latitude D630.....Intel Core2 Duo T7700...BIOS A19(June 2013)...Memory: 4G Ram 55G SSD

Post Reply

Return to “Desktop Environment”