Trigger action base on a delay action

Posted on
Thu Mar 05, 2015 9:46 am
Richard offline
Posts: 68
Joined: Feb 05, 2015

Trigger action base on a delay action

Need help with a script! Here is the script that I failed miserably with.

from datatime import datatime
sensor = indigo.devices[710337117] # "Front Door Sensor"
timeDelta = datetime.now() - sensor.lastChanged
if sensor.onState and timeDelta.seconds > 15:
indigo.device.turnOn([1897472413], duration=6)

What I was trying to do is set up a trigger when my front door sensor a trigger on (open) state for 15 seconds it would notify me by turning on the light (1897472413) for 6 seconds.
Eventually I was hoping to set it up this way and notify me with the pushover notifications app as well in the future. Would this be the easy's way to achieve this type of action?

Posted on
Thu Mar 05, 2015 11:12 am
Richard offline
Posts: 68
Joined: Feb 05, 2015

Re: Trigger action base on a delay action

Fix spelling mistake :roll:
from datatime import datatime

to datetime

but still not working and trying to learn about codes.

Posted on
Thu Mar 05, 2015 11:42 am
kw123 offline
User avatar
Posts: 8374
Joined: May 12, 2013
Location: Dallas, TX

Re: Trigger action base on a delay action

Code: Select all
import datetime
sensor = indigo.devices[710337117] # "Front Door Sensor"
timeDelta = datetime.datetime.now() - sensor.lastChanged
indigo.server.log(str(timeDelta))
works.

the issue is with the import statement:
the method is: datetime.datetime.now

you could also do
Code: Select all
from datetime import datetime
sensor = indigo.devices[710337117] # "Front Door Sensor"
timeDelta = datetime.now() - sensor.lastChanged
indigo.server.log(str(timeDelta))

yes it is confusing..

The issue is that datetime is a collection of methods. ONE of them is also called datetime

took me some time to understand it.
I am now always fully spelling it out (datetime.datetime....). code is a bit longer but then there is no confusion.

Karl

Posted on
Thu Mar 05, 2015 12:04 pm
Richard offline
Posts: 68
Joined: Feb 05, 2015

Re: Trigger action base on a delay action

Thanks kw123

Code: Select all
import datetime
sensor = indigo.devices[710337117] # "Front Door Sensor"
timeDelta = datetime.datetime.now() - sensor.lastChanged
indigo.server.log(str(timeDelta))
if sensor.onState and timeDelta.seconds > 15:
indigo.device.turnOn([1934375504], duration=6)


Now I have to see why line 6 is says this
Script Error embedded script: expected an indented block
Script Error around line 6 - "indigo.device.turnOn([1934375504], duration=6)"

Posted on
Thu Mar 05, 2015 12:39 pm
kw123 offline
User avatar
Posts: 8374
Joined: May 12, 2013
Location: Dallas, TX

Re: Trigger action base on a delay action

Code: Select all
import datetime
sensor = indigo.devices[710337117] # "Front Door Sensor"
timeDelta = datetime.datetime.now() - sensor.lastChanged
indigo.server.log(str(timeDelta))
if sensor.onState and timeDelta.seconds > 15:
   indigo.device.turnOn([1934375504], duration=6)


after an IF statement you have to indent the next statement(s)- until the IF statement section ends. Here the line with "indigo.device.turnOn([1934375504], duration=6)"

This is KEY to any python programming. You need to understand the structure with indents! if that is not clear to you you need to do a python basic programming intro.

Karl

Posted on
Thu Mar 05, 2015 12:42 pm
Richard offline
Posts: 68
Joined: Feb 05, 2015

Re: Trigger action base on a delay action

Thanks :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest