The script display the current power consumption of your laptop. The initial attention was to be just Power Consumption Indicator. But now it has menu which call few tool within gnome-terminal
window. Thats are htop
, powertop
, tlp stat
. If any of the tools is not installed on the system, the script will ask you to install it.
The script works with Ubuntu 16.04 and probably the only system specific thing is the file where the value of the current power consumption is stored. In my case I found it by the help of tlp
:
$ sudo tlp stat | grep -P '\[m(W|A)\]' # Output on Lenovo ThinkPad X230 Laptop-Tablet
/sys/class/power_supply/BAT0/power_now = 11246 [mW]
$ sudo tlp stat | grep -P '\[m(W|A)\]' # Output on Dell Vostro 3350 Laptop
/sys/class/power_supply/BAT0/power_now = 6700 [mA]
Note some devices provide the current power consumption in watts, but some devices provide the current values of the voltage and the current (amps) and - we must calculate the current power. The script covers these cases.
-
Copy the script to
/usr/local/bin
to make it accessible as shell command system wide:sudo wget https://raw.githubusercontent.com/metalevel-tech/powerNow/master/powerNow.py -O /usr/local/bin/powerNow sudo chmod +x /usr/local/bin/powerNow
-
Copy the script to
~/bin
to make it accessible only for the current user:wget https://raw.githubusercontent.com/metalevel-tech/powerNow/master/powerNow.py -O $HOME/bin/powerNow chmod +x $HOME/bin/powerNow
-
Copy the desktop file to
~/Desktop
(the script is required):wget https://raw.githubusercontent.com/metalevel-tech/powerNow/master/powerNow.desktop -O $HOME/Desktop/powerNow.desktop chmod +x $HOME/Desktop/powerNow.desktop
-
Copy the desktop file to
~/.config/autostart
(the script is required):wget https://raw.githubusercontent.com/metalevel-tech/powerNow/master/powerNow.desktop -O $HOME/.config/autostart/powerNow.desktop chmod +x $HOME/.config/autostart/powerNow.desktop
Right now I'm using Kali Linux 2022 on my ThinkPad. To get the tool operational, I was needed to download and manually install the .deb package gir1.2-appindicator3-0.1_0.4.92-7_amd64.deb
cd ~/Downloads
wget http://ftp.de.debian.org/debian/pool/main/liba/libappindicator/gir1.2-appindicator3-0.1_0.4.92-7_amd64.deb
sudo apt install ./gir1.2-appindicator3-0.1_0.4.92-7_amd64.deb
Some things used in the script are deprecated, but it still works, so I will fix them in the future. Also the icons used in the desktop launcher and in the indicator itself are not available in Kali.
The application is tested on:
-
Lenovo ThinkPad X230 Laptop-Tablet with Ubuntu 16.04
-
Dell Vostro 3350 Laptop with Ubuntu 16.04
Note: This is my very first Python attempt so I've used couple of references:
- How do I get the current power consumption in the status bar? (Developing a status icon)
- AppIndicator3: Set indicator icon from file name or GdkPixbuf
- Writing indicators with Python, GIR and GTK3
- Create an Ubuntu Application Indicator in Python: step-by-step guide
- AppIndicator3 Documentation (also here)
- Unix & Linux: How to find power draw in watts? | Watts / Volts / Amps / Ohms
- Hands-on Python Tutorial » 3. More On Flow of Control » 3.1. If Statements
- TypeError: worker() takes 0 positional arguments but 1 was given
- Graphical environment in gtk+ programming
- Anjuta DevStudio
- Glade - A User Interface Designer
I can call this simple tool also my laptop power management bundle, so here are few specifics according the usage of tlp
and powertop
on my Lenovo Lenovo ThinkPad X230 Laptop-Tablet:
-
Installation and basic usage of
tlp
:-
Install the package:
sudo apt update && sudo apt install tlp
. -
If you are using
tp-smapi
the better way to install the package is:sudo add-apt-repository ppa:linrunner/tlp sudo apt-get update sudo apt-get install tlp tlp-rdw sudo apt-get install tp-smapi-dkms acpi-call-dkms
-
-
There are two services that will be installed
tlp.service
andtlp-sleep.service
. -
Use
sudo tlp stat
to check the current settings. -
Use
nano /etc/default/tlp
to tweak the configuration. -
Use
sudo tlp start
to apply the configuration.
The tool powertop
is not just a monitoring tool it has also a calibrating option: powertop -c
, and manual handling of the power management for the peripheral devices.
See also: