[SOLVED] Conky help needed

Message
Author
User avatar
JayM
Qualified MX Guide
Posts: 6793
Joined: Tue Jan 08, 2019 4:47 am

[SOLVED] Conky help needed

#1 Post by JayM »

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.
Please read the Forum Rules, How To Ask For Help, How to Break Your System and Don't Break Debian. Always include your full Quick System Info (QSI) with each and every new help request.

jonnken
Posts: 120
Joined: Thu Mar 14, 2019 12:22 pm

Re: Conky help needed

#2 Post by jonnken »

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...since Feb 2019
Dell Latitude E6440...Intel Core i5-4310M...240G SSD...MX-19.4_x64
Dell Optiplex 755...Intel Core2 Duo E8500...300G HD...MX-19.4_x64

User avatar
fehlix
Developer
Posts: 10375
Joined: Wed Apr 11, 2018 5:09 pm

Re: Conky help needed

#3 Post by fehlix »

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
Posts: 120
Joined: Thu Mar 14, 2019 12:22 pm

Re: Conky help needed

#4 Post by jonnken »

an elegant solution...two IF arguments for the out-liers (<40, >50)...and the middle temp range as the default color
Regards, jonnken...since Feb 2019
Dell Latitude E6440...Intel Core i5-4310M...240G SSD...MX-19.4_x64
Dell Optiplex 755...Intel Core2 Duo E8500...300G HD...MX-19.4_x64

User avatar
JayM
Qualified MX Guide
Posts: 6793
Joined: Tue Jan 08, 2019 4:47 am

Re: Conky help needed

#5 Post by JayM »

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}
Please read the Forum Rules, How To Ask For Help, How to Break Your System and Don't Break Debian. Always include your full Quick System Info (QSI) with each and every new help request.

User avatar
JayM
Qualified MX Guide
Posts: 6793
Joined: Tue Jan 08, 2019 4:47 am

Re: Conky help needed

#6 Post by JayM »

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.)
Please read the Forum Rules, How To Ask For Help, How to Break Your System and Don't Break Debian. Always include your full Quick System Info (QSI) with each and every new help request.

jonnken
Posts: 120
Joined: Thu Mar 14, 2019 12:22 pm

Re: Conky help needed

#7 Post by jonnken »

noob question....where in your terminal/or otherwise...do you enter this code?
Regards, jonnken...since Feb 2019
Dell Latitude E6440...Intel Core i5-4310M...240G SSD...MX-19.4_x64
Dell Optiplex 755...Intel Core2 Duo E8500...300G HD...MX-19.4_x64

User avatar
JayM
Qualified MX Guide
Posts: 6793
Joined: Tue Jan 08, 2019 4:47 am

Re: Conky help needed

#8 Post by JayM »

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.
Please read the Forum Rules, How To Ask For Help, How to Break Your System and Don't Break Debian. Always include your full Quick System Info (QSI) with each and every new help request.

User avatar
JayM
Qualified MX Guide
Posts: 6793
Joined: Tue Jan 08, 2019 4:47 am

Re: Conky help needed

#9 Post by JayM »

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
Please read the Forum Rules, How To Ask For Help, How to Break Your System and Don't Break Debian. Always include your full Quick System Info (QSI) with each and every new help request.

jonnken
Posts: 120
Joined: Thu Mar 14, 2019 12:22 pm

Re: Conky help needed

#10 Post by jonnken »

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...since Feb 2019
Dell Latitude E6440...Intel Core i5-4310M...240G SSD...MX-19.4_x64
Dell Optiplex 755...Intel Core2 Duo E8500...300G HD...MX-19.4_x64

Post Reply

Return to “XFCE Desktop Environment”