Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turning light off after certain time
#1
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=LVarBig GriniffMins
P2=Seconds
P3=LVar:CurTime
P4=GVar:CurrMotionTime

If System::GrThan
P1=%(LVarBig GriniffMins)
P2=2

Devices::FieldWrite
P1=UPB.DEV-Kitchen_Cabinet_Light
P2=False
P3=True

End
Reply
#2
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
Reply
#3
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=LVarBig GriniffMins
P2=Seconds
P3=LVar:CurTime
P4=GVar:CurrMotionTime

If System::GrThan
P1=%(LVarBig GriniffMins)
P2=45

GlobalVars::SetNowPlus
P1=GVar:CurrMotionTime
P2=Seconds
P3=0

Devices::FieldWrite
P1=UPB.DEV-Kitchen_Cabinet_Light
P2=False
P3=True

End
Reply
#4
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
Reply
#5
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
Reply
#6
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
Reply
#7
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
Reply
#8
Yep, that's another way of doing it.
Dean Roddey
Explorans limites defectum
Reply
#9
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Time to replace my mSata HDD. ellisr63 4 1,441 11-23-2018, 11:47 AM
Last Post: ellisr63
  Adding Christmas Light control to CQC with Lutron HW8 avtexan 10 5,467 11-18-2015, 12:35 PM
Last Post: avtexan
  Return time from UPB rtarver 9 2,610 08-01-2015, 08:34 AM
Last Post: Dean Roddey
  Daylight Savings Time Deane Johnson 9 3,271 03-08-2015, 12:28 PM
Last Post: Deane Johnson
  run time driver potts.mike 3 1,582 02-06-2011, 06:49 PM
Last Post: Dean Roddey
  Help - Trying to compare to Time fields sic0048 10 3,396 11-19-2010, 11:48 AM
Last Post: sic0048
  Night Light (UPB, ELK & CQC) gacevich 22 5,123 02-25-2009, 02:28 PM
Last Post: ea_automation
  Formatting STDRtv time / date Sendero 2 1,735 01-27-2009, 12:56 AM
Last Post: Sendero
  Lights go off after set time ellisr63 3 1,667 12-16-2007, 09:05 AM
Last Post: ellisr63
  Speaker wire beside light runs ewiz 6 2,395 06-26-2007, 01:13 PM
Last Post: klindy

Forum Jump:


Users browsing this thread: 1 Guest(s)