Posts: 192
Threads: 38
Joined: Dec 2006
I'm using the below logic to track when a motion sensor detects motion and turns on a light, then wait 2 minutes and turns it back off. It's not working, so what am I doing wrong? Thanks!
Devices::FieldWrite
P1=UPB.DEV-Kitchen_Cabinet_Light
P2=True
P3=True
If Not GlobalVars::Exists
P1=GVar:CurrMotionTime
GlobalVars::CreateVariable
P1=GVar:CurrMotionTime
P2=Time
P3=
P4=0
GlobalVars::SetNowPlus
P1=GVar:CurrMotionTime
P2=Seconds
P3=0
End
LocalVars::SetNowPlus
P1=LVar:CurTime
P2=Seconds
P3=0
LocalVars::ElapsedSince
P1=LVar

iffMins
P2=Seconds
P3=LVar:CurTime
P4=GVar:CurrMotionTime
If System::GrThan
P1=%(LVar

iffMins)
P2=2
Devices::FieldWrite
P1=UPB.DEV-Kitchen_Cabinet_Light
P2=False
P3=True
End
Posts: 40,483
Threads: 491
Joined: Aug 2002
You also need to set CurMotionTime back to now in the final If. I.e. once two minutes are up and you turn the lights off, you need to make sure the time stamp gets reset again, or you'll always be over two minutes for ever more. Do it before the field write, just in case the field write fails for some reason.
Dean Roddey
Explorans limites defectum
Posts: 192
Threads: 38
Joined: Dec 2006
Ok, I set the CurMotionTime back to now. Still no joy. I'm wondering if the 45 in the If System::GrThan is seconds or minutes? I assume seconds, that's why I have it set a something quick like 45.
Devices::FieldWrite
P1=UPB.DEV-Kitchen_Cabinet_Light
P2=True
P3=True
If Not GlobalVars::Exists
P1=GVar:CurrMotionTime
GlobalVars::CreateVariable
P1=GVar:CurrMotionTime
P2=Time
P3=
P4=0
GlobalVars::SetNowPlus
P1=GVar:CurrMotionTime
P2=Seconds
P3=0
End
LocalVars::SetNowPlus
P1=LVar:CurTime
P2=Seconds
P3=0
LocalVars::ElapsedSince
P1=LVar

iffMins
P2=Seconds
P3=LVar:CurTime
P4=GVar:CurrMotionTime
If System::GrThan
P1=%(LVar

iffMins)
P2=45
GlobalVars::SetNowPlus
P1=GVar:CurrMotionTime
P2=Seconds
P3=0
Devices::FieldWrite
P1=UPB.DEV-Kitchen_Cabinet_Light
P2=False
P3=True
End
Posts: 40,483
Threads: 491
Joined: Aug 2002
What's not working? Are you sure it's even being run? Set it to be logged when invoked and make sure it's running. If so, it should be working. You asked the diferrernce calc to give seconds, so it should be giving back seconds.
Dean Roddey
Explorans limites defectum
Posts: 40,483
Threads: 491
Joined: Aug 2002
Wait, why are you turning the lights on at the start? I thought this was supposed to be a triggered event that triggers when the light is turned on, that will then turn it back off later. You wouldn't want such a triggered event to turn the lights on.
Dean Roddey
Explorans limites defectum
Posts: 192
Threads: 38
Joined: Dec 2006
I have a trigger event that fires off a motion sensor. It turns the light on. That part works no problem. I now want to turn that light get gets turned on by the triggered event off after some time. Am I approaching this right?
For logging and seeing if it is running, how do I do that?
Thanks,
--Jamie
Posts: 951
Threads: 111
Joined: Jan 2008
I do this a lot, but use a TimeFldChange command. Much simpler.
i.e.
Have the sensor set as trigger.
When motion is triggered the TimeFldChange command starts
Devices::TimedFldChange
P1=Insteon.KitchenIsland
P2=100
P3=0
P4=15
When motion is tripped it turns the lite on at 100% for 15 minutes and then turns it off. If motion continues then it keeps resetting, so that it only turns off when there is no motion for those 15 minutes.
I used to use timers until I switched to this.
Thanks
George M
Posts: 40,483
Threads: 491
Joined: Aug 2002
Yep, that's another way of doing it.
Dean Roddey
Explorans limites defectum
Posts: 192
Threads: 38
Joined: Dec 2006
The TimedFldChange seems to work perfectly, thanks George! I still probably need to understand timers, as there is lots of stuff I want to do along these lines, but this will work for now.
--Jamie