#!/usr/bin/python dir='/sys/class/power_supply/BAT1/' with open(dir + 'current_now', 'r') as f: current = int(f.read()) / 1000000.0 with open(dir + 'voltage_now', 'r') as f: voltage = int(f.read()) / 1000000.0 with open(dir + 'status', 'r') as f: status = f.read().rstrip() print(status) if status == "Charging" or status == "Full": wattage = voltage * current elif status == "Discharging": wattage = -voltage * current else: wattage = 0 print('{0:.2f}V {1:.2f}A {2:.2f}W'.format(voltage, current, wattage)) print('{0:.2f}W'.format(wattage)) #return wattage