Skip to content

Instantly share code, notes, and snippets.

@muety
Created April 20, 2023 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muety/c35c80bb9b4ec665589c6ec5170f9b34 to your computer and use it in GitHub Desktop.
Save muety/c35c80bb9b4ec665589c6ec5170f9b34 to your computer and use it in GitHub Desktop.
Simple script to print current power draw in Watts on Linux notebooks
import time
if __name__ == '__main__':
while True:
with open('/sys/class/power_supply/BAT0/current_now', 'r') as f:
current = float(f.readline().strip())
with open('/sys/class/power_supply/BAT0/voltage_now', 'r') as f:
voltage = float(f.readline().strip())
print(f'{current * voltage / 1000000000000} W', end='\r')
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment