1. Are you ready for the Galaxy S20? Here is everything we know so far!

Using Tasker to subtract times (large numbers)

Discussion in 'Android Apps & Games' started by kernelRiot, Aug 8, 2010.

  1. kernelRiot

    kernelRiot Lurker
    Thread Starter

    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
    [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?

  2. UncleMike

    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 likes this.
  3. kernelRiot

    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!
  4. Rushey

    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.

  5. kernelRiot

    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.
  6. kernelRiot

    kernelRiot Lurker
    Thread Starter

    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.
  7. jackattack

    jackattack Member

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

    jshugart Lurker


Share This Page