It is currently March 19th, 2024, 10:38 am

UsageMonitor in battery skin

Get help with creating, editing & fixing problems with skins
User avatar
SilverAzide
Rainmeter Sage
Posts: 2579
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: UsageMonitor in battery skin

Post by SilverAzide »

Yincognito wrote: January 5th, 2019, 4:01 pm I'll further investigate the issue, but in the meantime, SilverAzide, could you provide a link to your 64-bit version of your plugin, to see if it works for me? Assuming, of course, that you didn't hardcode Battery Status (with spaces) in your DLL, so that it can work with BatteryStatus (no spaces) and the other no spaces names used to query these things in my case. By the way, I tried WMIC Path Win32_Battery Get BatteryStatus /Format:List and it doesn't have charge/discharge rates available to display - are these only available programatically? O.O
Yes sir.... you can get the 32- and 64-bit plugins here from the .rmskin. Please note that the "BatChargeRate" measure type returns a positive number when charging and a negative number when discharging, so there is no need to have two measures to get the chargerate/discharge rate values as supplied by Windows. Documentation on the plugin is in the Resources folder.

Code: Select all

[MeasureBatteryInstance]
Measure=Plugin
Plugin=ActiveNet
Type=BatInstanceName
UpdateDivider=-1

[MeasureChargeRate]
Measure=Plugin
Plugin=ActiveNet
Type=BatChargeRate
Name=[MeasureBatteryInstance]

BTW, the Win32_Battery class does not include charge/discharge rates (I think that class is in the wrong "namespace"). To get those, you need to use:
wmic /Namespace:"\\root\wmi" Path BatteryStatus Get * /Format:list, or more specifically
wmic /Namespace:"\\root\wmi" Path BatteryStatus Get ChargeRate,DischargeRate /Format:list.
Or use Powershell:
gwmi -Class BatteryStatus -Namespace root\wmi, or
gwmi -Class BatteryStatus -Namespace root\wmi | Format-List -Property ChargeRate, DischargeRate :)
User avatar
Yincognito
Rainmeter Sage
Posts: 6949
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: UsageMonitor in battery skin

Post by Yincognito »

SilverAzide wrote: January 5th, 2019, 8:05 pmYes sir.... you can get the 32- and 64-bit plugins here from the .rmskin. Documentation on the plugin is in the Resources folder.
Oh thanks - but that's a plugin I know and already have in my "plugin database" since a couple of years back, if I remember correctly. :D I'll see if it's a newer version than what I already have, and update if necessary. I'll test things with it (most likely tomorrow) and let you know the results (although I don't expect 'unpleasant' surprises, so it will probably be merely a confirmation that it works).
SilverAzide wrote: January 5th, 2019, 8:05 pmPlease note that the "BatChargeRate" measure type returns a positive number when charging and a negative number when discharging, so there is no need to have two measures to get the chargerate/discharge rate values as supplied by Windows.
That's fine, as it's exactly the same way I display these rates in my skin, for space conservation purposes. :rofl: I'll have to replace the regular minus with its longer unicode version that I use for proper negative value alignment in tooltips and do an Abs() in the detailed display (where I don't use the minus), but that's perfectly cool.
SilverAzide wrote: January 5th, 2019, 8:05 pmBTW, the Win32_Battery class does not include charge/discharge rates (I think that class is in the wrong "namespace"). To get those, you need to use:
wmic /Namespace:"\\root\wmi" Path BatteryStatus Get * /Format:list, or more specifically
wmic /Namespace:"\\root\wmi" Path BatteryStatus Get ChargeRate,DischargeRate /Format:list.
Or use Powershell:
gwmi -Class BatteryStatus -Namespace root\wmi, or
gwmi -Class BatteryStatus -Namespace root\wmi | Format-List -Property ChargeRate, DischargeRate :)
Many thanks for this, I'll consider using it if I decide to move the rates to be displayed only in tooltips, and not in the actual skin (where I could leave just the Critical/Low/High/etc. statuses). I might be mistaken, but I think the class you mentioned (aka BatteryStatus) is called a "superclass" - I read about such things when looking for solutions to my problem, and I think this was the "superclass" they talked about.
☆☆☆
In the meantime, I kind of gave up finding a proper solution to this and just ran Rainmeter elevated with Task Scheduler at startup/logon, like jsmorley mentioned in another topic a couple of weeks ago. I don't like it, as it's just a workaround and not an actual solution to the matter, but for now it will do. Running WMIC on a mouseover tooltip is an alternative though, considering that in my case (and probably others as well), the rates only update once every 10+ seconds anyway (so launching WMIC at this interval would not be abusive, people don't keep tooltips visible for huge amounts of time)...
User avatar
Yincognito
Rainmeter Sage
Posts: 6949
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: UsageMonitor in battery skin

Post by Yincognito »

SilverAzide wrote: January 5th, 2019, 8:05 pmYes sir.... you can get the 32- and 64-bit plugins here from the .rmskin.
Beautiful skin suite - just tested it, and, as expected and promised, I can confirm that battery data is available in your skins. You even display the rates in watts, and not the default milliwatts, just like I changed my skin to do a couple of weeks ago. :D

I guess I'll go the WMI route with this, updating once every 10+ seconds or never, depending on whether the rates (tooltips) are displayed or not... ;-)
User avatar
SilverAzide
Rainmeter Sage
Posts: 2579
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: UsageMonitor in battery skin

Post by SilverAzide »

Yincognito wrote: January 6th, 2019, 7:23 pm Beautiful skin suite - just tested it, and, as expected and promised, I can confirm that battery data is available in your skins. You even display the rates in watts, and not the default milliwatts, just like I changed my skin to do a couple of weeks ago. :D
Thank you! Glad all is working for you! :great:

Perhaps the RM devs (tjhrulz?) can shed some light on why UsageMonitor (and all the rest) don't work with BatteryStatus? All these workarounds should not be needed... :confused:
User avatar
Yincognito
Rainmeter Sage
Posts: 6949
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: UsageMonitor in battery skin

Post by Yincognito »

SilverAzide wrote: January 6th, 2019, 8:15 pm Thank you! Glad all is working for you! :great:

Perhaps the RM devs (tjhrulz?) can shed some light on why UsageMonitor (and all the rest) don't work with BatteryStatus? All these workarounds should not be needed... :confused:
They shouldn't be needed, true, but I doubt they'll shed light on it, since if they had an idea, they would have probably mentioned it by now. Just a curiosity however: wmic displays info about all the batteries in the system, right? And if it does, the WMI's ACPI\PNP0C0A\1_0 is generally the instance that Rainmeter shows info about when using the Power plugin? I'm thinking of properly correlating the WMI info with the instance that's used by the Power plugin...
User avatar
SilverAzide
Rainmeter Sage
Posts: 2579
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: UsageMonitor in battery skin

Post by SilverAzide »

Yincognito wrote: January 6th, 2019, 8:49 pm They shouldn't be needed, true, but I doubt they'll shed light on it, since if they had an idea, they would have probably mentioned it by now. Just a curiosity however: wmic displays info about all the batteries in the system, right? And if it does, the WMI's ACPI\PNP0C0A\1_0 is generally the instance that Rainmeter shows info about when using the Power plugin? I'm thinking of properly correlating the WMI info with the instance that's used by the Power plugin...
Well, I can't speak for everyone, but in my case when I had a laptop with two batteries, the instance names were ACPI\PNP0C0A\0_0 and ACPI\PNP0C0A\1_0. (The main battery was the "1_0" one, which seems weird to me... but who knows the mysteries of Windows enumeration logic, (if any) LOL.)

And yes, WMI queries will list both if they are present, so you will need to use a clause to filter the results for the instance name of interest to prevent multiple rows of data in the output. If you don't use a filter and assume instead that the first row of data is the right one, it might not be (it was not in my case). Oh, and the "0_0" instance showed up in the output even when no battery at all was present (it was a Dell Precision workstation laptop with a bay where you could swap out the CD/DVD drive for a second battery).
User avatar
Yincognito
Rainmeter Sage
Posts: 6949
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: UsageMonitor in battery skin

Post by Yincognito »

SilverAzide wrote: January 6th, 2019, 11:41 pm Well, I can't speak for everyone, but in my case when I had a laptop with two batteries, the instance names were ACPI\PNP0C0A\0_0 and ACPI\PNP0C0A\1_0. (The main battery was the "1_0" one, which seems weird to me... but who knows the mysteries of Windows enumeration logic, (if any) LOL.)

And yes, WMI queries will list both if they are present, so you will need to use a clause to filter the results for the instance name of interest to prevent multiple rows of data in the output. If you don't use a filter and assume instead that the first row of data is the right one, it might not be (it was not in my case). Oh, and the "0_0" instance showed up in the output even when no battery at all was present (it was a Dell Precision workstation laptop with a bay where you could swap out the CD/DVD drive for a second battery).
Good to know. I'm going to do just like I did for the other WMI queries: display them all, without instance filtering (I'm already displaying multiple rows in the other WMIC outputs, so this is not an issue). Where I would filter (if I do filter, I'll weigh on it) is on the Active= and PowerOnline= WMIC output. Do you by any chance remember if one or both of these two fields were TRUE when it displayed your 0_0 instance? Because it seems logical to me to test for a FALSE in one of these fields (don't know which one though, and I have no way of testing, LOL, but I suspect it would be Active= field) and if so add a "Battery Slot Inactive" or something like that in a RegEx Substitute.
SilverAzide wrote: January 6th, 2019, 11:41 pm... but who knows the mysteries of Windows enumeration logic, (if any) LOL.
It seems the logic is explained here.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2579
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: UsageMonitor in battery skin

Post by SilverAzide »

Yincognito wrote: January 6th, 2019, 11:58 pm Where I would filter (if I do filter, I'll weigh on it) is on the Active= and PowerOnline= WMIC output. Do you by any chance remember if one or both of these two fields were TRUE when it displayed your 0_0 instance? Because it seems logical to me to test for a FALSE in one of these fields (don't know which one though, and I have no way of testing, LOL, but I suspect it would be Active= field) and if so add a "Battery Slot Inactive" or something like that in a RegEx Substitute.
Arrgh, I don't recall exactly, sorry. I think PowerOnline is true only when the machine is plugged in/charging. Active I'm not sure about; I think I found it to be unreliable.

I just discovered something else today... my laptop docking station is acting like it has a battery (it doesn't). When querying with WMIC, the ID is ACPI\PNP0C0A\2_0 (if it matters). Active is TRUE (always) and PowerOnline is TRUE or FALSE depending on if the dock is plugged in or not (the dock will run unplugged, I assume pulling power from the laptop battery). Powershell and the Win32_Battery class (i.e., "gwmi Win32_Battery") shows only the one "real" battery and the Availability attribute tells you all sorts of things (my values are "2" when plugged in and "3" when running on battery). The BatteryStatus attribute is as expected ("2" is on-line, "1" is discharging, etc.).

The one trick I use to determine which battery is the active one (which I use in my plugin) is to look at the Voltage attribute. Only one battery will have a value >0 if the system is running on battery, and that will be the active one. If all battery voltages are zero, you're on AC.
User avatar
Yincognito
Rainmeter Sage
Posts: 6949
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: UsageMonitor in battery skin

Post by Yincognito »

SilverAzide wrote: January 7th, 2019, 12:18 pm Arrgh, I don't recall exactly, sorry. I think PowerOnline is true only when the machine is plugged in/charging. Active I'm not sure about; I think I found it to be unreliable.

I just discovered something else today... my laptop docking station is acting like it has a battery (it doesn't). When querying with WMIC, the ID is ACPI\PNP0C0A\2_0 (if it matters). Active is TRUE (always) and PowerOnline is TRUE or FALSE depending on if the dock is plugged in or not (the dock will run unplugged, I assume pulling power from the laptop battery). Powershell and the Win32_Battery class (i.e., "gwmi Win32_Battery") shows only the one "real" battery and the Availability attribute tells you all sorts of things (my values are "2" when plugged in and "3" when running on battery). The BatteryStatus attribute is as expected ("2" is on-line, "1" is discharging, etc.).

The one trick I use to determine which battery is the active one (which I use in my plugin) is to look at the Voltage attribute. Only one battery will have a value >0 if the system is running on battery, and that will be the active one. If all battery voltages are zero, you're on AC.
So, what you're saying is that you found no way of telling whether batteries are physically in their "slot", but you use the Voltage property to find out if a battery is the "active" (i.e. "in use") one - am I getting this right? Well, that changes a little bit things for me, but not too much - I could just replace the Active property with the Voltage one to display the "in use" message to the user, but... I don't know if you are entirely correct in your assumptions at the end of your reply:
On AC Power.jpg
On Battery.jpg
The first screenshot is on AC power, the second is on battery (there were about 4 Win32_Battery properties that didn't fit in the screenshots, but they were either "" or the default values, so the images are relevant as they are). At the top are my skins, with the battery one showing the tooltip with the active status and the charge/discharge rate (or the lack of it). As you can see, the Voltage property is greater than 0 whether the laptop is on AC power (with the battery in the slot) or battery power. I don't know where this leads us, but I just thought you should know what happens in my case, maybe you'll find it useful.

Me, I could just leave things as they are now (nice WMIC data shown on demand, aka mouseover, refreshed every 20 seconds, which is about the frequency of charge/discharge rates anyway, in my case), or try to figure out with you what property we can use to get the "in use" status of a battery (if the Voltage property will turn out to be a 'false prophet' on this, that is).

P.S. Oh, and one more thing: I'm not sure I can correlate the WMIC's BatteryStatus instances with the Win32_Battery ones, since they display different battery IDs (InstanceName for BatteryStatus, and DeviceID/Name for Win32_Battery).
Post Reply