Trigger off of deltaTime?

Posted on
Mon Mar 26, 2018 11:53 pm
gisplatin offline
Posts: 35
Joined: Jul 15, 2011

Trigger off of deltaTime?

I"m trying to trigger off various durations running on my irrigation system.

The duration is expressed as deltaTime, generated from a start and a finish Timestamp. using this code, which I was very happy to find here :D

Code: Select all
from datetime import datetime

startTimeVariable = indigo.variables[1632591664].value  # REPLACE '123' WITH YOUR START TIME VARIABLE ID
endTimeVariable = indigo.variables[765744602].value  # REPLACE '456' WITH YOUR END TIME VARIABLE ID

   startTime = datetime.strptime(startTimeVariable, "%b %d %H:%M:%S")
except StandardError, e:
    indigo.server.log(u"Error Converting Start Time ('%s'). Error='%s'" % (startTimeVariable, e), isError=True)   
   endTime = datetime.strptime(endTimeVariable, "%b %d %H:%M:%S")
except StandardError, e:
    indigo.server.log(u"Error Converting End Time ('%s'). Error='%s'" % (endTimeVariable, e), isError=True)   

if endTime > startTime:
    deltaTime = endTime - startTime 
    indigo.variable.updateValue(5022321, str(deltaTime))  # REPLACE '789' WITH YOUR DELTA TIME VARIABLE ID
    indigo.variable.updateValue(5022321, value="Start Time not before End Time")  # REPLACE '789' WITH YOUR DELTA TIME VARIABLE ID

This bit of python is working beautifully.. It delivers duration in H:MM:SS.

What I haven't figured out is how to trigger off of this data (greater than, less than, etc). Conditions in triggers are not responsive, no matter how I formulate the entry. After many hours trying, I've been unable to manipulate this datetime value into a more digestible, trigger-ready format.

Would anyone have a suggestion?

Posted on
Tue Mar 27, 2018 3:00 am
racarter offline
User avatar
Posts: 124
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: Trigger off of deltaTime?

The problem is that your value is a time delta object, which can't be compared directly with a different type, such as an integer.

One way to do what you want would be to convert the time difference into an integer representing minutes or seconds in your Python script, then use that value in your trigger.
Code: Select all
def time_to_num(time_str):
    hh, mm , ss = map(int, time_str.split(':'))
    return ss + 60*(mm + 60*hh)

If you were to do the comparison in Python you could set a comparison value such as:
Code: Select all
 halfAnHour = datetime.timedelta(minutes = 30)

and compare against that.

Posted on
Tue Mar 27, 2018 3:41 am
DaveL17 offline
User avatar
Posts: 3883
Joined: Aug 20, 2013

Re: Trigger off of deltaTime?

Options! In addition to @racarter:

Code: Select all
# Python 2.7
duration = delta.total_seconds()

# Python <= 2.7
duration = (delta.days * 24 * 60 * 60) + delta.seconds + float('.' + str(b.microseconds))  # lazy conversion, but probably can drop the microseconds anyway

Untested, but should be close.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Mar 27, 2018 8:37 am
Colorado4Wheeler offline
User avatar
Posts: 2403
Joined: Jul 20, 2009
Location: Colorado

Re: Trigger off of deltaTime?

If you want a non-Python method you could try Device Extensions, it has an elapsed time conversion that you could base off of the lastChanged date/time, it reports as minutes passed rather than HH:MM:SS. I also wrote similar functionality in the Room-O-Matic plugins to track HH:MM:SS of remaining time on irrigation zones.

What's the end goal of what you are trying to achieve?

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests