2

I'm developing an app which needs to know about the energy consumption on computers (On windows). I realized the OS has no functionalities to support this directly, so my workaround is collecting info about all the hardware devices and aggregate the amount of energy they consume, I found databases like eXtreme Power Supply Calculator but they don't have any APIs that I could use. Do you have any suggestion of how to accomplish this? any open source software?

Because my app is supposed to mainly run on laptops I was thinking of having a rough estimate based on laptop model but I could not find a database holding such a info, any ideas? Thanks

3
  • 3
    There are devices that exist which all you to plug a device into them which will indicate the amount of power those devices are drawing. I would just use one of those.
    – Ramhound
    Commented Jul 18, 2016 at 16:13
  • 1
    This is a nearly impossible task whichever way you look at it. If you go by model then you need to include all the variants of processor, hard drive, SSD, graphics card, chipset and everything else that might be attached for each variant. Otherwise you need to individually catalogue each of those parts. Then you need to know everything about those devices, their idle power draw and their full load draw and anything in between. In short: this is a nightmare.
    – Mokubai
    Commented Jul 18, 2016 at 16:53
  • 1
    As above, a single device will not draw the same amount of energy all the time, so the statistics you are collecting are probably maximum energy usages and not actual. I think you need to focus on what you're trying to achieve with your program. As Ramhound says you can get a wall plug energy meter to test different devices. Those will show the actual energy used.
    – user576053
    Commented Jul 18, 2016 at 21:02

3 Answers 3

3
+25

This would be an impossible task, power consumption can vary wildly dependent on system load and power saving settings. For instance on my workstation, when idle it uses ~300 watts, and ~900 watts under load according to my APC SmartUPS. Although a laptop would be less extreme when comparing absolute numbers, relatively it would still be significant between idle and full load.

And as proof of how pointless this is, I tried entering my system in to the eXtreme Power Supply Calculator you linked in their "Expert" mode. It underestimated the load by ~100 watts. And surprisingly it thinks my peak load will vary depending on how many hours a day I use my computer.

Power Consumption Idle Power Consumption Idle

Power Consumption Under Load (forgot to load the HDDs) enter image description here

2

Have a look at the Win32_PowerMeter WMI class located in the root\CIMV2\power namespace. This namespace has lot of other classes and events related to power management and profiles.

For an example of using this class, see the open-source pwrdrain-gadget gadget (uses an ActiveX object). For VBScript examples see this. For C# examples see this.

1
  • thanks for the answer, I've been trying to use Win32_PowerMeter but it's based on an underlying power meter, so most of fields are null on a normal computer.
    – ePezhman
    Commented Jul 21, 2016 at 21:15
1

Laptops usually provide ACPI interface to their batteries which you could use. You will be specifically interested in "Battery Status" object described in chapter 10.2.2.6 of ACPI specification:

_BST returns a package in the format below

Package { 
 Battery State                    // Integer (DWORD)
 Battery Present Rate             // Integer (DWORD)
 Battery Remaining Capacity       // Integer (DWORD)
 Battery Present Voltage          // Integer (DWORD)
}

Battery Present Rate is typically either a power value in mW or a current value in mA (which you'll have to multiply by Battery Present Voltage to get the power value). Of course, there are many more ACPI values to explore (including the current and voltage measurement from the power supply), but those may not be implemented on all systems. Install System Information Viewer and check out Machine->Battery to get a feeling of it. Or, if you happen to be a Linux user, check out /sys/class/power_supply directory.

You will need to learn how to make ACPI calls on Windows from whatever programming language and framework you're using. This MSDN article may be a good start.

2
  • I like this answer but I'm pretty sure all these values would be invalid when the laptop is plugged into its power adapter, no?
    – Jason
    Commented Jul 27, 2016 at 18:08
  • @Jason When the laptop is plugged in, _BST will report battery charging power. If you're lucky and the power drawn from the PSU is also reported, you'll be able to subtract the former from the latter and still get your power consumption estimate. Though I have seen laptops which only battery power but not PSU power. Commented Jul 28, 2016 at 7:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .