I did a bunch of research online but sadly, can't quite figure out how to do time math. I've read up on datetime and timedelta, but I can't get the basics down. It has occurred to me that I don't really need to put the Off time into a variable. When the unit goes off, I can just subtract the On time from the current time, and that should give me the result I'm looking for. But I've also come to understand that storing the On time in a variable, means I have to recall it for the math, and it needs to appear as time data, not just a series of numbers for the calculation.

This script does put the time into the Off Variable, but it also add 6 decimal places, which, of course, I don't need. I have a similar script for the On Trigger

- Code: Select all
`from datetime import time`

from datetime import datetime

from datetime import timedelta

OffTime = datetime.time(datetime.now())

indigo.variable.updateValue(254766893, value=unicode(OffTime)) #puts off time in variable

I was hoping that this line would get rid of the fractions of a second, but it doesn't, at least not as scripted

- Code: Select all
`OffTime = datetime.time(datetime.now(%H:%M:%S))`

But aside from the decimal issue, I need to recall the data from the ON variable, have it appear as time, subtract the Off time from the On time, and then store it in a variable. I'm also going to need to make this a cumulative number, but I think I can probably figure out how to do that if I can get just the basic run time calculated. With any examples of how to do the basic time math, I can probably figure out how to do the rest of this project, but for the moment... I'm stuck..

As always... THANKS in advance!

- Code: Select all
`from datetime import time`

from datetime import datetime

from datetime import timedelta

on = indigo.variables[1506159459] #acOntime

off = indigo.variables[254766893] #acOffTime

total = indigo.variables[985437501] #cummAcTotal

OffTime = datetime.time(datetime.now())

indigo.variable.updateValue(254766893, value=unicode(OffTime)) #puts off time in variable

t1 = time delta(datetime.time)(off)-(datetime.time)(on)+(total) #this is obviously the problem line

indigo.variable.updateValue(985437501, value=datetime.time(t1))