Charting WMI battery value as replacement for old 'BATTERY' option

Forums Desktop Info Charting WMI battery value as replacement for old 'BATTERY' option

This topic contains 4 replies, has 2 voices, and was last updated by Avatar Ian 2 weeks, 4 days ago.

  • Author
    Posts
  • #2120 Reply
    Avatar
    Ian

    Hi, I used to use the ‘BATTERY’ option with a chart to visually show the charge percentage of the laptop battery:

    BATTERY=active:1,interval:30,set:battery,display:%3: %1%,chart:bar linear 100 1 -10

    Since the battery option in the latest version is deprecated, I’ve gone with the example listed in ‘useful WMI Queries’:

    set=key:battery1,value:Disconnected
    set=key:battery2,value:Connected
    WMI=active:1,interval:60,text:Battery,namespace:root\
    cimv2,query:Win32_Battery,display:%EstimatedChargeRemaining%%
    (%battery%BatteryStatus%%)

    This works great as a numeric percentage, however for the life of me I cannot get it to chart the WMI value of %EstimatedChargeRemaining% as a horizontal bar (like the deprecated BATTERY option would) – I’ve looked at other examples where a WMI value is charted, but all I can get to chart is a simple ‘1’ (with a chart I imagine is showing 1% full). I’m obviously missing something, could anyone help me out?

    Thanks!

    0
  • #2121 Reply
    Glenn
    Glenn
    Keymaster

    The critical piece of information you’re missing is the return value number. EstimatedChargeRemaining is not the first property in the class. What you need to do is look up the specs for the Win32_Battery wmi class to find out what number the EstimatedChargeRemaining property is.

    The fastest way is type the class name into google and find the first result from docs.microsoft.com. In this case you’ll end up at

    https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-battery

    This page lists all the properties returned by the class. Now just count them off until you get to the property in question and you’ll find that EstimatedChargeRemaining is 15. Put this number into the chart definition as the series number.

    chart:bar linear 100 15 -10

    0
    • #2123 Reply
      Avatar
      Ian

      Thanks Glenn for the tip. I’m still missing something. I used:

      WMI=active:1,interval:10,text:Battery,namespace:root\cimv2,query:Win32_Battery,chart:bar linear 100 15 -10

      but still I just see ‘Battery 1’ in Desktop Info. I tried it on both my laptop computers. I can see, as you said, that item 15 is the estimatedchargeremaining item, and strangely, if I use the wrong ‘chart:bar linear 100 1 -10’, I get the outline of a box that would store the chart, but if I use 15 for the series, I don’t even get an outline. Aargh! Any chance of a little further help? Thanks again for a great tool.

      0
      • #2124 Reply
        Glenn
        Glenn
        Keymaster

        you have to add the display template option:

        ,display:%EstimatedChargeRemaining%% (%battery%BatteryStatus%%)

        this is the complete item

        WMI=active:1,interval:10,text:Battery,namespace:root\cimv2,query:Win32_Battery,chart:bar linear 100 15 -10,display:%EstimatedChargeRemaining%% (%battery%BatteryStatus%%)

        1+
  • #2125 Reply
    Avatar
    Ian

    Worked a charm. Thanks! I was trying to run the percentage as a number on one line, and then the chart as a bar on its own by repeating the WMI query, not including the display template because I (wrongly) thought that would duplicate the percentage as a number. Thanks again!

    1+
Reply To: Charting WMI battery value as replacement for old 'BATTERY' option
Your information:




Do NOT follow this link or you will be banned from the site!