It is currently March 28th, 2024, 5:04 pm

Help: Bettery lifetime countdown

Get help with creating, editing & fixing problems with skins
Post Reply
niluyao
Posts: 2
Joined: September 13th, 2020, 12:06 am

Help: Bettery lifetime countdown

Post by niluyao »

Hi,
I want to make a countdown timer for remainning bettery life
I have done some attempts but do not work well
Here is my code

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureLife]
Measure=Plugin
Plugin=PowerPlugin
PowerState=LIFETIME
Format=%H:%M:%S
Substitute="Unknown":"0:00:00"

[MeasureLife1]
Measure=Plugin
Plugin=PowerPlugin
PowerState=LIFETIME
Format=%H
Substitute="Unknown":"0"

[MeasureLife2]
Measure=Plugin
Plugin=PowerPlugin
PowerState=LIFETIME
Format=%M
Substitute="Unknown":"0"

[MeasureLife3]
Measure=Plugin
Plugin=PowerPlugin
PowerState=LIFETIME
Format=%S
Substitute="Unknown":"0"

[timeinsec]
measure=calc
formula=[MeasureLife1]*3600+[MeasureLife2]*60+[MeasureLife3]
DynamicVariables=1

[cCounter]
Measure=Calc	
Formula=(cCounter-1+([timeinsec]+1))%([timeinsec]+1)
DynamicVariables=1

[MeasureFormatSeconds]
Measure=UpTime
SecondsValue=[timeinsec]
Format="%3!i!h %2!i!m %1!i!s"
DynamicVariables=1

[MeterCountdown]
Meter=String
MeasureName=MeasureLife
MeasureName2=timeinsec
MeasureName3=cCounter
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
text=life: %1#CRLF#timeinsec: %2#CRLF#cCounter: %3
I want the timer to update everytime there is a change in PowerState=LIFETIME
If in any case the timer reaches 0:00:00, I want it to stay on that value not restart timing
Thanks
User avatar
Alex88
Posts: 92
Joined: July 18th, 2020, 1:23 am
Location: California

Re: Help: Bettery lifetime countdown

Post by Alex88 »

I'm not versed with the Power plugin at all since I've only used my desktop or Android tablets for a few years now, so I can't really test anything, but my guesses:
It seems like you should be able to connect [MeasureLife] , [MeasureLife1]:[MeasureLife2]:[MeasureLife3] or [timeinsec] into a meter to show the remaining battery life in hours, minutes and/or seconds, and not have to use a separate counter. Then if you want to do something at 0 or another number, maybe using:

Code: Select all

[MeasureBatteryZero]
 Measure=Calc
 IfCondition=(timeinsec = 0)
 ;IfCondition=(MeasureLife1 = 0) && (MeasureLife2 = 0) && (MeasureLife3 = 0)
 IfTrueAction=[!SomeAction]
 IfFalseAction=[!SomeAction]
So either placing an IfCondition on [timeinsec] or on a certain combination of [MeasureLife1]:[MeasureLife2]:[MeasureLife3]. I'm assuming any of the those four measures will return the correct number and string when on battery power.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help: Bettery lifetime countdown

Post by balala »

niluyao wrote: September 13th, 2020, 12:35 am I want the timer to update everytime there is a change in PowerState=LIFETIME
If in any case the timer reaches 0:00:00, I want it to stay on that value not restart timing
It does work, but as Alex88 said, you have to add a String meter to show up the remaining time (or even better modify the existing one). There are two things to be done:
  • Replace the SecondsValue option of the [MeasureFormatSeconds] measure with: SecondsValue=[cCounter].
  • Add a MeasureName4=MeasureFormatSeconds option to the [MeterCountdown] meter and replace its Text option with the following one: Text=life: %1#CRLF#timeinsec: %2#CRLF#cCounter: %3#CRLF#Lifetime: %4.
niluyao
Posts: 2
Joined: September 13th, 2020, 12:06 am

Re: Help: Bettery lifetime countdown

Post by niluyao »

Thanks for the help
Anyone knows if it is possible to get the time until fully charged?
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help: Bettery lifetime countdown

Post by balala »

niluyao wrote: September 18th, 2020, 9:59 am Anyone knows if it is possible to get the time until fully charged?
As far as I can tell, this is not possible. Me at least don't know a way for this.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: Help: Bettery lifetime countdown

Post by SilverAzide »

niluyao wrote: September 18th, 2020, 9:59 am Thanks for the help
Anyone knows if it is possible to get the time until fully charged?
I have not tried this, but perhaps it can be calculated. Assuming your charge rate is greater than zero (i.e., charging, not discharging or charged) then perhaps something like this could work:

((max charge in watt-hours) - (current charge in watt-hours) / (charge rate in watts)) * 3600 = should give you a time in seconds

You could then use this result in a Time measure to show some formatted result. Again, I did NOT try this, so I have no idea if it works. My guess is that is will be somewhat erratic even if it does work; i.e., the battery might not charge linearly, like it could say the time is 5 minutes remaining, and 5 minutes later it will say 3 minutes remaining. I know on my system the charge rate lowers the closer the battery gets to being fully charged.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: Help: Bettery lifetime countdown

Post by SilverAzide »

OK, so I did try it, and the results are spectacularly inaccurate. Perhaps that's why Microsoft themselves have deprecated the WMI class property (or properties) that showed the time to full charge value.
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Help: Bettery lifetime countdown

Post by Yincognito »

SilverAzide wrote: September 18th, 2020, 3:41 pm OK, so I did try it, and the results are spectacularly inaccurate. Perhaps that's why Microsoft themselves have deprecated the WMI class property (or properties) that showed the time to full charge value.
Hmm, I'm not so sure the inaccuracy is because of the formula itself (which is correct, as far as I can tell) or some WMI class values. This is the proper way by which ALL progress bars everywhere work, so it might have to do with the battery "wearing out" over time and having a gradually decreasing Max charge value...

By the way, Explorer's estimates on copy times for large data are just as innacurate, as the rates of copying change constantly, pretty much like a battery's charging or discharging rates.
Post Reply