#!/usr/bin/python dir0='/sys/class/power_supply/BAT0/' dir1='/sys/class/power_supply/BAT1/' with open(dir0 + 'power_now', 'r') as f: power0 = int(f.read()) / 1000000.0 with open(dir1 + 'power_now', 'r') as f: power1 = int(f.read()) / 1000000.0 with open(dir0 + 'status', 'r') as f: status0 = f.read().rstrip() with open(dir1 + 'status', 'r') as f: status1 = f.read().rstrip() if status0 == "Discharging" or status1 == "Discharging" wattage = - power0 - power1 elif status0 == "Charging" or status0 == "Full" or status1 == "Charging" or status1 == "Full": wattage = power0 + power1 else: wattage = 0 #return wattage