SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2008-12-15 05:02:56

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

conky power usage script

I wrote up a power usage script for conky. I put it in the pastebin here http://crunchbanglinux.org/pastebin/23. copy the script, name it what you want and put in your scripts directory. Make sure you make it executable, then add a line similar to this to your conky config:
Power Usage: ${execi 1 /home/eric/battery.py}
replace the path with wherever you put the script.
7ea549b24f3c59c541a230dc8adc7.png

edit: oh forgot to mention it only works when your not plugged in, otherwise it says Not available.

Here is the most recent version http://crunchbanglinux.org/pastebin/246

Last edited by iggykoopa (2009-05-17 20:24:24)


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

Be excellent to each other!

#2 2008-12-15 19:41:56

corenominal
WRONG
From: Lincoln, UK
Registered: 2008-11-20
Posts: 5,054
Website

Re: conky power usage script

Nice work! I have been meaning to have a play with my Conky set-up for a while, I give this a try when I do. Thanks for sharing! smile

Offline

#3 2008-12-16 15:10:25

kestrel
Species: F. sparverius
From: Moscow, Idaho
Registered: 2008-11-29
Posts: 170
Website

Re: conky power usage script

Great idea. I want to try this out and have added it to conky. Unfortunatly I get nothing on the conky. I run the command in CLI and this is the error.

will@kestrel-eee:~/.config/conky $ /home/will/.config/conky/battery.py
Traceback (most recent call last):
  File "/home/will/.config/conky/battery.py", line 8, in <module>
    batInfo = open("/proc/acpi/battery/BAT0/state" % batteries[0])
TypeError: not all arguments converted during string formatting

Can you help me decode the error? I run #! 8.10.01 on EEE 1000
Here is the cat of /proc/acpi/battery/BAT0/state

will@kestrel-eee:/proc/acpi/battery/BAT0 $ more state
present:                 yes
capacity state:          ok
charging state:          discharging
present rate:            1135 mA
remaining capacity:      4536 mAh
present voltage:         7646 mV

Thanks


My web activities: Etsy Shop | Facebook | Blog

Offline

#4 2008-12-21 17:50:29

marf
Member
Registered: 2008-12-03
Posts: 24

Re: conky power usage script

This is annoying the crap out of me. I'm getting this error

marf@crunchbang-lappy:~/.config/CrunchBang$ ./conky_battery.py 
: No such file or directory

But, when I do cat /proc/acpi/battery/BAT0/state

here is my output

present:                 yes
capacity state:          ok
charging state:          discharging
present rate:            14695 mW
remaining capacity:      71920 mWh
present voltage:         12065 mV

so it'd definitely there.

I did chmod +x conky_batter.py
but that shouldn't give this "no file found" message.

Any Ideas?

Offline

#5 2008-12-22 04:29:15

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

Heres updated code that should fix your first problem. http://crunchbanglinux.org/pastebin/44 I forgot some parenthesis. The second problem isn't saying file not found about your battery, it's saying it can't find the script, are you sure you were in the correct directory and there were no typos ?

Last edited by iggykoopa (2008-12-22 04:38:20)


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#6 2008-12-31 18:31:30

ZeroTruths
#! Junkie
Registered: 2008-12-31
Posts: 331

Re: conky power usage script

@marf
Correct me if I'm wrong, but isn't the command suppose to be

python conky_battery.py

All in an effort to learn...
Delves deeper into code...

Offline

#7 2008-12-31 20:57:33

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

If you set it to executable you don't need the python part of the command.

Last edited by iggykoopa (2008-12-31 20:59:52)


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#8 2008-12-31 21:13:24

ZeroTruths
#! Junkie
Registered: 2008-12-31
Posts: 331

Re: conky power usage script

Oh, I did not know that


All in an effort to learn...
Delves deeper into code...

Offline

#9 2008-12-31 22:08:39

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

no problem, you just need to have this line:
#!/usr/bin/env python
at the top of a python script and if you set it executable it will work without the python in front, also the file doesn't need to end in .py it just makes it easier to tell what it is.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#10 2009-01-19 21:39:20

Mehall
#! Die Hard
From: Scotland, Cold
Registered: 2009-01-17
Posts: 850
Website

Re: conky power usage script

Can I ask, is this only for laptops? you said it said "unavailable" if plugged in, but I'd like to see power watt usage levels on my desktop.


Ex-KDE user.
Collects old PC's (Coz he can't afford new ones =P)
Crunchbang @ Distrowatch
My Blog (updated infrequently, and on the #! Planet too.)

Offline

#11 2009-01-20 00:21:31

fhsm
#! Junkie
From: New Hampshire, USA
Registered: 2009-01-05
Posts: 445

Re: conky power usage script

Mehall wrote:

Can I ask, is this only for laptops? you said it said "unavailable" if plugged in, but I'd like to see power watt usage levels on my desktop.

No idea about his conky script but I've used PowerTOP from time to time to have a look at where power is going on my desktop (also has some nice suggestion for how to cut use).  This won't give you any a watt / volt sort of look, more of a distribution picture:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install cpufrequtils
sudo apt-get install powertop

To see what's using your power:

sudo powertop

To check out your processor

sudo cpufreq-info

I know that's a bit off topic but maybe it will help you.
To set your CPU freq, steps etc (caution I *never* do this #! seems to step my processor quite nicely)

 sudo cpufreq-set

Offline

#12 2009-01-20 00:25:05

Mehall
#! Die Hard
From: Scotland, Cold
Registered: 2009-01-17
Posts: 850
Website

Re: conky power usage script

fhsm wrote:
Mehall wrote:

Can I ask, is this only for laptops? you said it said "unavailable" if plugged in, but I'd like to see power watt usage levels on my desktop.

No idea about his conky script but I've used PowerTOP from time to time to have a look at where power is going on my desktop (also has some nice suggestion for how to cut use).  This won't give you any a watt / volt sort of look, more of a distribution picture:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install cpufrequtils
sudo apt-get install powertop

To see what's using your power:

sudo powertop

To check out your processor

sudo cpufreq-info

I know that's a bit off topic but maybe it will help you.
To set your CPU freq, steps etc (caution I *never* do this #! seems to step my processor quite nicely)

 sudo cpufreq-set

Cheers dude, I'll try that one out.

And an overal distrobution would be great, coz I'm using an older computer currently, mostly for ICS, and I'm gonna try and install it on a REALLY old comuter, so minimising electricity usage would be nice so I can justify it to my dad =P


Ex-KDE user.
Collects old PC's (Coz he can't afford new ones =P)
Crunchbang @ Distrowatch
My Blog (updated infrequently, and on the #! Planet too.)

Offline

#13 2009-01-20 00:30:05

Mehall
#! Die Hard
From: Scotland, Cold
Registered: 2009-01-17
Posts: 850
Website

Re: conky power usage script

mehall@crunchbang-desktop:~$ sudo cpufreq-info
cpufrequtils 002: cpufreq-info (C) Dominik Brodowski 2004-2006
Report errors and bugs to linux@brodo.de, please.
analyzing CPU 0:
  no or unknown cpufreq driver is active on this CPU


=/

Last edited by Mehall (2009-01-20 00:30:15)


Ex-KDE user.
Collects old PC's (Coz he can't afford new ones =P)
Crunchbang @ Distrowatch
My Blog (updated infrequently, and on the #! Planet too.)

Offline

#14 2009-01-20 03:06:11

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

the script is actually taken from powertop and just converted to python, so if powertop works this will as well. As far as I know it wont work on a desktop though(it pulls info from the battery to find power usage). Also the first pastebin of it is gone now and it looks like I cut part of it off in the second so I'm gonna have to fix it again, I'll post when its good.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#15 2009-01-20 03:28:11

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

ok fixed it again new paste here http://crunchbanglinux.org/pastebin/98 .


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#16 2009-01-20 06:32:13

1esproc
Member
Registered: 2009-01-16
Posts: 15

Re: conky power usage script

Posted a C version here: http://crunchbanglinux.org/pastebin/101 tongue

Average times on my Dell Mini 9:
Python: Real 0.135s
C: Real 0.072s

lol

Make and "install" with:
gcc -o batt battery.c
sudo cp batt /usr/bin/

Last edited by 1esproc (2009-01-20 06:36:24)

Offline

#17 2009-01-20 14:09:39

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

cool guess I need to pick up C now too big_smile. Is it working correctly on your mini? mine isn't reporting power draw correctly, it just shows present rate as 0 mA.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#18 2009-01-20 15:16:09

1esproc
Member
Registered: 2009-01-16
Posts: 15

Re: conky power usage script

iggykoopa wrote:

cool guess I need to pick up C now too big_smile. Is it working correctly on your mini? mine isn't reporting power draw correctly, it just shows present rate as 0 mA.

Nope, doesn't work properly on the Mini because of that, but I didn't have anything else with a battery in it to realistically test the time. Not sure if there's some other way to determine it neutral

Offline

#19 2009-01-20 15:56:46

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

the only other way I can think of is to measure the remaining capacity over time and calculate the rate yourself. I may give it a try tonight when I get home.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#20 2009-01-21 05:01:58

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

Got a version working now for machines that don't report rate(like the mini 9). Two issues with it though, one it doesn't seem like acpi updates remaining capacity very frequently so it won't update very often(about every 2 minutes it seems) and it depends a lot on the accuracy of conky running it every second so I can't vouch for it's accuracy. If you want a rough idea of your power usage over time with it though here it is http://crunchbanglinux.org/pastebin/105 . Download the script to /home/yourname/scripts/powerusage.py and chmod +x it, then add ${execi 1 /home/username/scripts/powerusage.py} to your conky config.


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#21 2009-01-21 15:53:26

GuruX
#! Die Hard
Registered: 2009-01-18
Posts: 527

Re: conky power usage script

On my Eee 900, it reports 0.0

gustav@gustav-eee:~$ python .conky_battery.py
0.0
gustav@gustav-eee:~$ 

Offline

#22 2009-01-21 15:59:52

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

you have to let it run for a while, the first number reported will not be accurate because it takes your remaining capacity and stores it, then when the capacity changes it uses the difference divided by how long it took to change to figure out your power consumption. The battery, or acpi not sure which, only updates the remaining capacity every 2 minutes or so. You'll have to wait a minute or two from when you unplug it to get a reading.

edit: just noticed your running on a eee, thought you meant dell, they should report rate correctly, whats do you get from:

cat /proc/acpi/battery/BAT(it'll be 0 or 1 probably)/state

when it's unplugged.

Last edited by iggykoopa (2009-01-21 16:01:55)


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

#23 2009-01-23 14:46:13

GuruX
#! Die Hard
Registered: 2009-01-18
Posts: 527

Re: conky power usage script

cat /proc/acpi/battery/BAT0/state reports

gustav@gustav-eee:~$ cat /proc/acpi/battery/BAT0/state
present:                 yes
capacity state:          ok
charging state:          discharging
present rate:            unknown
remaining capacity:      60 mAh
present voltage:         7498 mV

I hade my update rate set to 10s in conky, changed it to 1s instead, but it still seems to report 0.0.
Is there some kind of debug I can make?

Offline

#24 2009-01-23 15:09:26

iggykoopa
Script Master
Registered: 2008-12-13
Posts: 1,485

Re: conky power usage script

Ok it looks like the eee doesn't report rate correctly either so it will have the slower reporting time(if rate is reported correctly it updates about every second). Was your battery almost dead when you ran that command? It's showing 60 mAh which is almost depleted, if it was supposed to be charged that may be part of the problem. If it was almost depleted then the script is working as designed, it has to gather the information on remaining capacity right after you unplug it, then the next time acpi updates the remaining capacity it makes some calculations from that, so it may take up to 2 minutes to update accurately. Heres an updated version that tells you if it's gathering data instead of just reporting 0.0 http://crunchbanglinux.org/pastebin/109 .

edit: I'm at work so couldn't test it, but it should run fine, if you get any errors let me know.

Last edited by iggykoopa (2009-01-23 15:10:35)


I say never be complete, I say stop being perfect, I say lets evolve, let the chips fall where they may.

Offline

Be excellent to each other!

#25 2009-01-23 19:47:28

Liu Anshan
New Member
Registered: 2009-01-22
Posts: 9

Re: conky power usage script

So if I get this

luke@liuanshanzailaptop:~$ cat /proc/acpi/battery/BAT0/state
present:                 yes
capacity state:          ok
charging state:          discharging
present rate:            1703 mA
remaining capacity:      2625 mAh
present voltage:         11136 mV

which script do i use?


How do you want to come out of this experience
     how do you want to be changed because of it?
No one forces you to learn.
     You'll learn when you want to.

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo