I am getting a trigger from a motion sensor and would like to turn a light on for a pre-determined amount of time. However, if the light was already turned on then I'd like to know if there is a delayed off pending, in which case I'd reset the duration. If there's no delayed off pending then the light was previously turned on elsewhere and I just want to leave it alone.
Code: Select all
lamp = indigo.devices["TV Room Front Lights"]
if lamp.states["onOffState"] == True :
#
# If there is a delayed off pending, then reset the timer here, otherwise
# don't take any action
#
indigo.server.log(lamp.name + " already on, ignoring motion.")
else :
indigo.server.log("Lower motion detected, turning " + lamp.name + " on.")
len = int(indigo.variables["motionDuration"].value)
indigo.device.turnOn(lamp, duration=len)
