Basic Trigger "condition" Question?

Posted on
Tue Jul 14, 2015 5:35 pm
thomasw offline
Posts: 135
Joined: Feb 13, 2011

Basic Trigger "condition" Question?

Hi all,
I want to setup a Trigger that will turn "on" an appliancelinc, but ONLY after it receives
at least 3 or more open/close (any signal) signals from a specific Triggerlinc (door sensor) within
a 5 minute time period.
Thanks
-Tom

Posted on
Wed Jul 15, 2015 7:35 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Basic Trigger "condition" Question?

Here's just a quick solution that would work, it took about 5 minutes to write and I didn't do much to pretty it up but it's functional:

2 Variables - DoorLastReset and DoorSignals
2 Triggers + 1 Script (screenshots and code to follow)

When you get your door signal you run this trigger:
Screen Shot 2015-07-15 at 7.32.00 AM.png
Screen Shot 2015-07-15 at 7.32.00 AM.png (75.34 KiB) Viewed 1585 times


When door signals is more than 2 you have another trigger that fires:
Screen Shot 2015-07-15 at 7.33.19 AM.png
Screen Shot 2015-07-15 at 7.33.19 AM.png (79.81 KiB) Viewed 1585 times


The 2nd trigger action is a python script that checks for 5 minutes passed and if so then it turns on the appliance link, changes the time stamp to now and resets the door signal count:
Code: Select all
import datetime
import time

Now = datetime.datetime.now()

doAction = False
lastReset = indigo.variables["DoorLastReset"]

if lastReset.value == '':
   doAction = True

if doAction == False:
   Last = datetime.datetime.strptime(lastReset.value, "%Y-%m-%d %H:%M:%S")
   d = divmod(time.mktime(Now.timetuple()) - time.mktime(Last.timetuple()),86400)  # days
   h = divmod(d[1],3600)  # hours
   m = divmod(h[1],60)  # minutes
   s = m[1]  # seconds
   
   if m[0] > 5:
      doAction = True
 
if doAction == True:
   indigo.variable.updateValue(lastReset, Now.strftime("%Y-%m-%d ") + Now.strftime("%H:%M:%S"))
   indigo.variable.updateValue("DoorSignals", "0")
   indigo.device.turnOn(848833485)


You could also easily do this in just one trigger that executes the script each time a device change has occurred with the door sensor. You could increment the value and run the script in the same script and only turn on the light if the value is over 2, or you could always reset the date stamp every 5 minutes - any number of things you can do once the basic framework is put into place.

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

Posted on
Thu Jul 23, 2015 11:37 am
thomasw offline
Posts: 135
Joined: Feb 13, 2011

Re: Basic Trigger "condition" Question?

Thanks Colorado4Wheeler,

I will give this a try when I get a chance. It looks like a good solution.

-Tom

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests