-3

I use a Lenovo Thinkpad and need a python program that can get me my laptop's charging percentage.

For Example: 74%, 98%, 16%

I've searched around but can't seem to find exactly what I need

Can anyone help?

2

2 Answers 2

1

You can get remaining time as follows:

import psutil as ps
batterystats = dict(ps.sensors_battery()._asdict())
print(batterystats)
timeleft = batterystats.get('secsleft')
percent = batterystats.get('percent')

print('battery percent : '+str(percent)+'%')
print('time left (secs) : '+str(timeleft)+' secs')

The answer is in seconds you can convert it though.

10
  • tell me if you need to know if the battery is charging
    – Sashank
    Jul 18, 2020 at 10:05
  • it says that batterystats has no function "get"
    – Ultra
    Jul 18, 2020 at 10:07
  • hmm , it works in python 2.7
    – Sashank
    Jul 18, 2020 at 10:08
  • not sure for 3.x
    – Sashank
    Jul 18, 2020 at 10:08
  • oh ok cz I'm using python 3x
    – Ultra
    Jul 18, 2020 at 10:09
0
import  psutil

print ("battery charge left: " + str(psutil.sensors_battery()[0]) + "%")

output

battery charge left: 95%
3
  • any way to know how many minutes of charging left?
    – Ultra
    Jul 18, 2020 at 10:05
  • just change the the zero value into 1 you will get the time left in seconds
    – Thulfiqar
    Jul 18, 2020 at 10:10
  • @Ultra ask that in a separate question.
    – Xbox One
    Sep 11, 2020 at 12:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.