I am trying to come out with a small python script to monitor the battery state of my ubuntu laptop and sound alerts if it's not charging as well as do other stuff (such as suspend etc). I really don't know where to start, and would like to know if there is any library for python i can use. Any help would be greatly appreciated. Thanks
I believe you can find the information you are looking for in
/sys/class/power_supply/BAT0
-
any ideas how i could find out if my battery is charging or not (and it's current level) from python? – SamAko May 22 '13 at 19:24
-
2never mind, figured it out, turns out there are readable files in this directory which are updated with various details about the battery. eg. cat /sys/class/power_supply/BAT0/present outputs 1 signifying that battery is present. Thanks – SamAko May 22 '13 at 19:28
-
I think you can also query battery status via dbus from gnome-power-manager. – TeTeT May 24 '13 at 14:34
Here I found a solution that might be helpful for you too. http://mantoshkumar1.blogspot.in/2012/11/monitoring-battery-status-on-linux.html
You do not need to use any module for this.
Simply you can navigate to
/sys/class/power_supply/BAT0.
Here you will find a lot of files with information about your battery. You will get current charge in charge_now file and total charge in charge_full file. Then you can calculate battery percentage by using some math.
Note:- You may need root access for this. You can use sudo nautilus command to open directories in root mode.