You are not logged in.

#1 2018-09-15 08:41:26

cds60601
Member
From: Chicago
Registered: 2018-08-09
Posts: 31

[SOLVED] i3 temperature module - Change from Cel. to Far.

Not sure if this is the appropriate sub for this - I am using the above mentioned module but I can't make out from the script, how to change that from Cel. to Far.
Not sure how that would be called from the sensor since if you call the sensor from CLI, you can use the -F flag. I tried that within the Temperature module but it will not work.  Guidance would be greatly appreciated.

Cheers
Chris

Last edited by cds60601 (2018-09-15 20:59:19)


Yeah, 220, 221. Whatever it takes.
Server: Debian 9 (Stretch)   Workstation: ArchLabs (i3-gaps)

Offline

#2 2018-09-15 14:35:01

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

@cds60601, I don't know what sensor your i3 has but mine has none, if you mean the function in the 'i3status.conf', you can't.

Have a look at 'man i3status*EXTERNAL SCRIPTS/PROGRAMS WITH I3STATUS', you need an external script to do that it seems.

But, is if that is what you're at. Be more clear and (always) name the files you need help with. wink

qinohe

Offline

#3 2018-09-15 15:04:19

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

If you are talking about using i3status in i3 bar, and are adding  a CPU temperature version, you may be out of luck.  Sort of.

That program uses the contents of the pseudo file /sys/devices/platform/coretemp.0/hwmon/hwmon1/temp1_input.  That file is generated by the kernel and, fortunately, the kernel is pretty much hard wired for Celsius (or, sometimes K).
If you are talking about CPU temperature, even in scientifically backwards countries such as the US, temperatures of integrated circuits are expressed in C; converting to F is really of little value, but I digress.

It may be possible to do what you are trying to do by using the status_command extension to the bar.  You could write a script to create what you want and insert it into the line from that script.

If we are talking about ambient temperatures, the same approach using status_command would work.  See:
https://i3wm.org/docs/userguide.html#_i3bar_command and
https://i3wm.org/docs/userguide.html#status_command


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2018-09-15 16:01:31

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

Yup, and if you did what has been suggested and stick something like the next in your status script
it shows an average of 4 cores in Fahrenheit , '/4 * 9/5 + 32' takes care of that.

var1=$(awk '{printf "%3.0f\n", $1/1000}' /sys/class/hwmon/hwmon1/temp2_input)
var2=$(awk '{printf "%3.0f\n", $1/1000}' /sys/class/hwmon/hwmon1/temp3_input)
var3=$(awk '{printf "%3.0f\n", $1/1000}' /sys/class/hwmon/hwmon1/temp4_input)
var4=$(awk '{printf "%3.0f\n", $1/1000}' /sys/class/hwmon/hwmon1/temp5_input)

var5=$(( var1 + var2 + var3 + var4 ))

printf "%s\\n" "$( bc -q <<< "scale=1; $var5 / 4 * 9/5 + 32" )"°F

exit 0

edit:I had to look up this script I made a while ago , you can put the next piece of code in you .zshrc and call it as 'temp'
It enumerates all cores there are and shows their temperature in Celsius and Fahrenheit.

temp() {
count=0
for heat in $(awk '{printf "%3.0f\n", $1/1000}' /sys/class/hwmon/hwmon1/temp*_input)
do
  printf "%s%u%s %s  %s\\n" core "$((++count))" : "$heat"°C $(( heat * 9/5 + 32 ))°F
done
}

Last edited by qinohe (2018-09-15 16:18:11)

Offline

#5 2018-09-15 16:56:54

cds60601
Member
From: Chicago
Registered: 2018-08-09
Posts: 31

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

Ah - sorry folks. I should have clarified a tad. I am using i3blocks and the module resides in /usr/lib/i3blocks
The current (or default) module appears to pull data using the sensors -u (IIRC, that is just the raw data) and I thought I could
simply add the -r that sensors allows you to use for Fahrenheit. That being said, it appears that using the -u wont allow you to toss in the -f flag.

Please forgive the missing information - was late when I posted right before bed, lol

Cheers
Chris


Yeah, 220, 221. Whatever it takes.
Server: Debian 9 (Stretch)   Workstation: ArchLabs (i3-gaps)

Offline

#6 2018-09-15 17:01:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

A single awk should do, then there's no need for the addition of bc and the many subshells.  But it does require an ugly cat ...

cat /sys/class/hwmon/hwmon1/temp*_input 2>/dev/null | awk '{sum+=$1; count+=1000;} END {printf "%.1f", 1.8 * sum/count + 32;}'

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2018-09-15 18:07:08

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

cds60601 wrote:

Ah - sorry folks. I should have clarified a tad. I am using i3blocks and the module resides in /usr/lib/i3blocks
The current (or default) module appears to pull data using the sensors -u (IIRC, that is just the raw data) and I thought I could
simply add the -r that sensors allows you to use for Fahrenheit. That being said, it appears that using the -u wont allow you to toss in the -f flag.

Please forgive the missing information - was late when I posted right before bed, lol

Cheers
Chris

I have no idea really I'm using i3 for years now and have never seen it, but, I don't use i3blocks either.
Show the file...

@Trilby, nice one, I use mine for tmux statusbar, I'll swap it with yours with or without 'cat' , 5 less lines and cheaper on 'time' wink

Offline

#8 2018-09-15 18:35:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

FYI, you could do without bash if you just list each file you want to use (that doesn't produce errors when read) after the awk command.  Or if you use bash (or probably zsh) you could use the notation "...temp{1,2,5,6}_input".


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#9 2018-09-15 20:43:26

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

I did already add it to a tmux script and I tested the line, it runs without error also as shell script(sh) in TTY and tmux.
Are you having errors?

Offline

#10 2018-09-15 20:57:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

With which version?  The `cat ... 2>/dev/null` silences the errors, that's the whole point of it.  Otherwise it'd be a useless use of cat as the wildcard path could be passed directly to awk.  I do get errors with awk run on the wildcarded path:

$ awk '{sum+=$1; count+=1000;} END {printf "%.1f", 1.8 * sum/count + 32;}' /sys/class/hwmon/hwmon1/temp*_input
awk: cmd. line:1: No such device or address

This is due to several 'files' existing that match the glob that aren't readable, e.g.:

$ ls /sys/class/hwmon/hwmon1/temp11_input
/sys/class/hwmon/hwmon1/temp11_input

$ cat /sys/class/hwmon/hwmon1/temp11_input
cat: read error: No such device or address

Last edited by Trilby (2018-09-15 20:58:29)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#11 2018-09-15 20:58:45

cds60601
Member
From: Chicago
Registered: 2018-08-09
Posts: 31

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

Trilby wrote:

A single awk should do, then there's no need for the addition of bc and the many subshells.  But it does require an ugly cat ...

cat /sys/class/hwmon/hwmon1/temp*_input 2>/dev/null | awk '{sum+=$1; count+=1000;} END {printf "%.1f", 1.8 * sum/count + 32;}'

This is perfect. No need to mess with the default module. just use a script with this line.
Thank you!!!


Yeah, 220, 221. Whatever it takes.
Server: Debian 9 (Stretch)   Workstation: ArchLabs (i3-gaps)

Offline

#12 2018-09-15 21:20:24

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

@Trilby, Oh that what you mean, yeah I tried that already and does result I the error, but I can live with the cat variant for now, thanks for that.

Btw. the version of what?

Last edited by qinohe (2018-09-15 21:22:22)

Offline

#13 2018-09-15 21:25:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

I was asking which version of the various commands I gave you were referring to.  Obviously you will not get errors from the one that explicitly silences the errors (neither do I).  I had only said that without the cat, it would get errors unless you either used the bashism for expanding just the filenames you wanted or explicitly listed all the filenames you wanted.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#14 2018-09-15 21:41:38

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

Yes, I use the cat version. I understand, bashisms could be used I will try and get that to work, thanks for your explanation(s).

Offline

#15 2018-11-19 18:02:31

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: [SOLVED] i3 temperature module - Change from Cel. to Far.

I know this thread is solved, but, AWK accepts a path with wildcard now too, so you can get rid of cat and pipe.
Trilby's command

awk '{sum+=$1; count+=1000;} END {printf "%.1f", sum/count;}' /sys/class/hwmon/hwmon1/temp*_input

Output

+ temp
+ awk '{sum+=$1; count+=1000;} END {printf "%.1f", sum/count}' /sys/class/hwmon/hwmon1/temp2_input /sys/class/hwmon/hwmon1/temp3_input /sys/class/hwmon/hwmon1/temp4_input /sys/class/hwmon/hwmon1/temp5_input
30.2+ exit 0

Offline

Board footer

Powered by FluxBB