Using Tasker to subtract times (large numbers)

I'm trying to set up a Profile that will flash "Charging..." when I plug in the phone and flash "Charged for XXX seconds" when I unplug it.

My profile looks like this:
[Context] Power; Source=Any
[Task]
[Enter] Flash; Text="Charging"
Variable Set; Name %CHARGESTART To %TIMES
[Exit] Variable Set; Name %CHARGEEND To %TIMES
Variable Subtract; Name %CHARGEEND Value %CHARGESTART
Flash; Text="Charged for %CHARGEEND seconds"

Unfortunately when I use this, I don't see "Charged for %CHARGEEND seconds", but rather "Variable %CHARGESTART: value XXX out of range 1:60" where XXX is the last value %CHARGESTART was set to by the enter task.

Seems like Tasker can only subtract a value from another if that value to subtract is between 1 and 60. This seems very limiting.

I tried to make a workaround where there's a loop that subtracts 60 each iteration while %CHARGESTART is > 60, but this takes forever when the number is as large as it is for %TIMES.

Is there something I'm missing here? Perhaps there is an easier way I just don't know of? I would have to think this would be possible.

If nothing else, perhaps writing to a file, calling some application which does the subtraction and writes to the file again, then using those file contents as the number?
 

UncleMike

Android Expert
I just tested this and got the same error as you. I kind of look at the Variable Add and Variable Subtract actions as simplified/limited versions of Variable Set. With that in mind, here's a workaround:

Variable Set [Name: %CHARGE] [Value: %CHARGEEND - %CHARGESTART] [Do Maths: Yes]
Flash [Text: Charged for %CHARGE seconds]

I'll report the issue to the developer.
 

kernelRiot

Lurker
Thread starter
I actually had tried that before, and again just now but ran Into another problem. If you do "%CHARGEEND-%CHARGESTART" instead of "%CHARGEEND - %CHARGESTART", the do maths fails. I guess without the spaces in there, it doesn't parse the expression correctly. Doesn't seem like it should be like that, since variable names can't have happens. Can you also pass that Information along to the developer?

Once I used the spaces, things worked no problems. Thanks a lot for your help!
 

Rushey

Well-Known Member
Wouldn't minutes be a more useful display than seconds? I wouldn't have a clue how many minutes were in say 9,480 seconds just from looking, I'd need to work it out.

Rob
 

kernelRiot

Lurker
Thread starter
Using seconds was just to see if I could get the idea working. I significantly expanded the profile so that it will give the time in hours, minutes or seconds if it makes sense to. If someone's interested, I could write out the profile.

Also, I plan on expanding the functionality to also show how much battery % was gained over the course of the charge.
 

kernelRiot

Lurker
Thread starter
Wouldn't minutes be a more useful display than seconds? I wouldn't have a clue how many minutes were in say 9,480 seconds just from looking, I'd need to work it out.

Rob

For that case, my program would actually show "2.633 hours" because 9,480 seconds is both greater than 60 seconds and greater than 60 minutes. I suppose I could add in something if you charged for longer than 24 hours, but I don't think that's a normal case.
 
Using seconds was just to see if I could get the idea working. I significantly expanded the profile so that it will give the time in hours, minutes or seconds if it makes sense to. If someone's interested, I could write out the profile.

Also, I plan on expanding the functionality to also show how much battery % was gained over the course of the charge.

I'd be interested in seeing this profile written out. Sounds like a cool idea!
 
Top