In my last post, I have reviewed an Oittm USB-C/2xUSB-A charger (feel free to take a look, spoiler alert: I like it), I measured the charger’s performance with Tasker.  The total charging time project does just this. Shows you how long it took it to charge a device and displays multiple results of your tests. The project is rather simple but I thought I would share it for the benefit of the new Tasker users.

Tasker total charging time project

I want to avoid discharging the battery completely, instead, I starting the measurements at 10%. Regardless of the percentage used, the results should be consistent for each charger. I take the %TIMES (time in seconds) of when the charging starts, until the 100% charge.

While entire Tasker total charging time project can be written in the vanilla Tasker – I will use AutoTools to display the information and do the calculations. Otherwise, you are facing a small subroutine to get the %TIMES to Xh:YYmin value. I recommend you do the same!

Getting the total charge time

TASKER PROFILE - Start Charge
Profile: Start Charge
	State: Power [ Source:AC ]
	State: Battery Level [ From:10 To:10 ]
Enter: Charging 
	A1: Variable Set [ Name:%ChargeStart To:%TIMES 
            Recurse Variables:Off Do Maths:Off Append:Off ] 
	A2: Profile Status [ Name:Stop Charge Set:On ] 

I think the 10% is good enough. It’s low enough that gives you a reasonable idea how long the entire charge takes, and it is high enough not to mess up your battery. If you set the trigger from 10% to 10% it will start measuring only when the battery reaches 10% (and cable is connected). This will automatically cover the scenarios when you plugged the cable too late (at 5%) and it won’t bother measuring if it’s just a quick charge to top up your phone before you go out.




The profile responsible for stopping the battery is disabled by default. I keep this turned off, otherwise, it will produce some data when the test is not running.

TASKER PROFILE - Stop Charge
Profile: Stop Charge 
	Event: Battery Full
Enter: Charge Completed 
	A1: Variable Set [ Name:%ChargeStop To:%TIMES 
            Recurse Variables:Off Do Maths:Off Append:Off ] 
	A2: Profile Status [ Name:Stop Charge Set:Off ] 
	A3: Variable Set [ Name:%array To:%ChargeStop-%ChargeStart 
            Recurse Variables:Off Do Maths:On Append:Off ] 
	A4: AutoTools Time [ Configuration:Convert Time Span: %array
            Use Seconds: true
            Output Variable: time Timeout (Seconds):30 ] 
	A5: Array Push [ Variable Array:%Charging_times  
            Position:1 Value:%timehours h: %timeminutes min 
            Fill Spaces:On ] 
	A6: Notify [ Title:Battery Charged 
            Text:Time taken: %timehours h: %timeminutes min 
            Icon:mw_device_battery_charging_full 
            Number:0 Permanent:On Priority:3 Actions:(1) ] 

Once I have the start and stop time in seconds, a simple maths calculation provides me with the time span in seconds.

%array set to: %ChargeStop-%ChargeStart

You can either convert it with Tasker, which will take you few actions or use AutoTools Time action to get neatly formatted time as:

%timehours h: %timeminutes min

Please note, that I changed the default output variable to ‘time’. I know this test will be run more than once, therefore I will either use pen and paper to note the results down, or use Tasker. Since you are here to learn Tasker, let’s push the value to an array and get the notification to tell us that the charge has been completed.Tasker total charging time

Organizing the results

It’s time to display all this. I want to note the charger’s name and the charging conditions (like: I’m charging solo or 2 devices at the same time). I will need two more arrays storing these values. Since I have used the AutoTools already I can use it again to ask for the device name and other info.

TASKER TASK - Add Name
Add Name 
	A1: Notify Cancel [ Title:Battery Charged Warn Not Exist:Off ] 
	A2: Status Bar [ Set:Collapsed ] 
	A3: AutoTools Dialog [ Configuration:Dialog Type: Input
		Title: Charger name
		Title Alignment: Left
		Text Size: 20
		Input Type: Text
		Input Text: %Last_charger
		Output Variable: Charger_name
		Dim Background: true
		Top Margin: 16
		Bottom Margin: 16
		Bottom Buttons Top Margin: 16
		Bottom Buttons Bottom Margin: 16
		Cancelable: true
		Turn Screen On: true Timeout (Seconds):60 ] 
	A4: Variable Set [ Name:%Last_charger To:%charger_name 
		Recurse Variables:Off Do Maths:Off Append:Off ] 
		If [ %charger_name Set ]
	A5: Array Push [ Variable Array:%Chargers Position:1 
		Value:%charger_name Fill Spaces:On ] If [ %charger_name Set ]
	A6: AutoTools Dialog [ Configuration:Dialog Type: Input
		Title: Charge conditions
		Title Alignment: Left
		Text Size: 20
		Input Type: Text
		Input Text: %Last_condition
		Output Variable: Charge_condition
		Dim Background: true
		Top Margin: 16
		Bottom Margin: 16
		Bottom Buttons Top Margin: 16
		Bottom Buttons Bottom Margin: 16
		Cancelable: true
		Turn Screen On: true Timeout (Seconds):60 ] 
	A7: Variable Set [ Name:%Last_condition To:%charge_condition 
		Recurse Variables:Off Do Maths:Off Append:Off ] 
		If [ %charge_condition Set ]
	A8: Array Push [ Variable Array:%Charge_conditions 
		Position:1 Value:%charge_condition Fill Spaces:On ] 
		If [ %charge_condition Set ]

This task is triggered by the notification from the Notify action A6 in TASKER PROFILE – Stop Charge (perform task action). It cancels the notification and displays 2 dialogs asking for a device name %Chargers() and charging conditions %Charge_conditions() – both are pushed to the respective arrays (position 1) if the values are assigned. To make things easier, I also set the predefined values to be the same as in the last test. I set two global variables for that %Last_charger & %Last-condition.




Displaying the results

To display the results from Tasker total charging time project I will use AutoTools once more.

TASKER TASK -Charge Results
Charge Results 
	A1: Flash [ Text:No results Long:On ] If [ %Chargers1 !Set ]
	A2: AutoTools Web Screen [ Configuration:Screen Preset: Card List
		Display Mode: Dialog
		Source: /storage/emulated/0/AutoTools/cardlist/page.html
		Toast Duration: 5000
		Width: 350
		Height: fill
		Gravity: Top
		Animation: Slide In From Top
		Show Duration: 500
		Hide Duration: 250
		Close On Command: true
		Wait For Command: true
		Title: Charge results
		Title Icon: android.resource://net.dinglisch.android.taskerm/hd_aaa_nixx_plug
		Title Buttons Icons: android.resource://net.dinglisch.android.taskerm/hl_images_rotate_left
		Title Button Commands: clearallresults
		Search Color: #ffffff
		Filter With Search: true
		Command Prefix: search
		Drawer Width: 80%
		Card Titles: %Chargers()
		Card Subtitle: %Charging_times()
		Card Subtext Right: %Charge_conditions()
		Card Commands: 1,2,3,4,5,6,7,8,9
		Commands Prefix: clipboard
		Round Card Icons: true
		Background Color: #BDBDBD
		Accent Color: #F9A825
		Max Card Widths: 95%
		Min Card Widths: 80%
		Title Text Size: 22
		Subtitle Text Size: 15
		Card Padding: 0
		Card Alignment: Top
		Item Separator: , Timeout (Seconds):30 ] If [ %Chargers1 Set ]
	A3: Array Clear [ Variable Array:%Charge_conditions ]
		If [ %atcommand ~ clearallresults ]
	A4: Array Clear [ Variable Array:%Chargers ] 
		If [ %atcommand ~ clearallresults ]
	A5: Array Clear [ Variable Array:%Charging_times ] 
		If [ %atcommand ~ clearallresults ]

AutoTools WebScreen with Cards should do this well. I use three values only:

  • %Chargers()
  • %Charge_conditions()
  • %Charging_times()

As an extra, I have added a reset button at the top. If the %atcommand = clearallresults I simply wipe all arrays involved.




Conclusion

There you have it! The project is very advanced by any means but does the job. I will continue to use Tasker total charging time project in the future reviews. Feel free to adapt it to any timed events you wish to measure, by modifying the trigger, names etc. As usual, I’m adding the ready made project file for you to download. Feel free to follow me on social media as it helps me grow, share it, and comment if you need any advice. You can also support me, and fund my projects directly.

SHARE