Light Keeps Turning On (newbie help)

Hello,

I am just staring to use PLEG trying to understand it all. I am running into a problem where my light keeps turning off then immediately on again. I am trying to turn on my light for 5 minutes when either me or my wife unlocks the front door. I am able to get the light to turn on but I’m having a problem keeping it off. I previously had NOW in my condition and it was working but there was a little delay so I removed it. I tried to use the condition below but now I’m getting a message when vera restarts that says “Invalid Value token: 1:00”

Triggers
tFDoorUnlockPete PIN Code #2 is entered on Front Door Lock true 2014-01-30 19:23:18.382 2014-01-30 16:39:35.164
tFDoorUnlockKelly PIN Code #1 is entered on Front Door Lock false 2014-01-30 16:39:35.164 2014-01-30 19:23:18.382

Conditions
(tFDoorUnlockKelly or tFDoorUnlockPete) and DarkAnyDay and pLivingRoomOutlet==0 and ((tFDoorUnlockKelly < 1:00) or (tFDoorUnlockPete < 1:00))

The condition I previously had that was working (but a little delayed) was
DarkAnyDay and pLivingRoomOutlet==0 and ((tFDoorUnlockKelly, NOW < 1:00) or (tFDoorUnlockPete, NOW < 1:00))

Actions for Condition: cFDoorUnlockNight

Immediate
Device Action Arguments
Living Room Outl SetTarget newTargetValue=1

Delay 10:00
Device Action Arguments
Living Room Outl SetTarget newTargetValue=0

Also just thought I should mention that the delay is not very long, maybe 5 seconds but it’s enough that the we have already entered the house beyond what I’d hoped. Maybe this is just normal behavior for z-wave? Also, I don’t know if this matters or not but my VeraAlert announces that I have unlocked the door before the light turns on.

Richard, thank you so much for your development of these amazing apps. This system wouldn’t be nearly what is is without your amazing work!

How about something like this for your conditions:

LightOn = (fdpete or fdkelly) and night
LightOff = LightOn;NOW>5:00

Actions basically self explanatory.

Start with something simple making it work and then add more features / logic as you learn the capabilities.

Cheers!

PD

(tFDoorUnlockKelly < 1:00)

This is probably not what you wanted … looks like your trying to use a sequence expression …
A sequence expression requires two or more inputs/conditions/literals.

PD, thanks for the suggestion. I agree about starting small then building. I had previously done that but got stuck at the most recent step. I want to make sure I don’t get my light turned off if it is already on which is why I have the pLivingRoomOutlet==0 condition.

Richard, based on what you said I have a couple of follow up questions if you don’t mind.

  1. I guess that makes sense why it works with the NOW in there because it has two inputs/literals right? (NOW and tFDoorUnlockPete)
  2. Is there a better way to write my condition not using the “NOW”? I read that “NOW” can slow things down and I’m trying to get the fastest response I can. I have moved this condition to the very top of the PLEG conditions so it will complete first.
  3. What is the recommended method for checking a timestamp for only one input?

Sorry for the newbie questions. I have been doing a lot of reading on the forum on how to use PLEG but I’m still not fully understanding how to work with timestamps.

Thanks for the responses.

“NOW” should be interpreted as a trigger that fires every minute so it is useful in sequence expressions. I have not used it otherwise.

For example the sequence:

(Event;NOW > 5:00)

becomes true when at least 5 minutes has elapsed between event and when NOW fires, which is every minute.

Regarding your concern if the light is already on you could do:

LightOn = (fdpete or fdkelly) and night and not AlreadyOn

Where AlreadyOn is a trigger assigned to the current state of the light. This way, since the light is not “AlreadyOn” then LightOn would never become satisfied and therefore LightOff would also never become satisfied. SO, the light would not turn off after 5 minutes if it was already on.

The only exception to this logic that I can think of is if there were two door open events within 5 minutes the timer would not restart with the second door open. We would need to think further about the logic to do that…

Instead of using NOW, you can use a specific selfstart timer, but neither should be used to start your LightOn action so NOW is probably just as good. I’m not sure why you are using NOW to turn on your light. The self start timer is another discussion. I can show you how to do it, but not sure it is needed.

You can check the status of all inputs and conditions by clicking on STATUS in you PLEG control window.

Cheers!

PD

PD thanks again for the reply. I’m not really sure why I’m using NOW either… I’m just trying to find a way to filter the timestamp because it is always listed as true for either me or my wife. If i don’t limit it by a specific time (5 minutes or less), the light will just keep turning on because the state of the door unlock will always be TRUE. If I’m understanding your suggestion above (which it’s very likely I’m not) I think the same thing would happen. Please let me know if I’m not understanding this correctly.

I tried changing the logic to this:

Conditions
_c1FDoorUnlock tFDoorUnlockKelly or tFDoorUnlockPete
c1LROutletOn pLivingRoomOutlet==0 and _c1FDoorUnlock and DarkAnyDay

Just like before it would turn the light back on immediately because the value of tFDoorUnlockKelly or tFDoorUnlockPete is always true.

I then changed the logic to
Conditions
_c1FDoorUnlock tFDoorUnlockKelly or tFDoorUnlockPete
c1LROutletOn pLivingRoomOutlet==0 and DarkAnyDay and (_c1FDoorUnlock, tFDoorUnlocked < 10)

This did not work either. I think I’m understanding the time sequence expression a little better from this though. Someone correct me if I’m wrong but the statement (a, b < 10) compares if ‘a’ and ‘b’ happened within 10 seconds of each other, not (as I was thinking) in the past 10 seconds.

So, with that knowledge I have now changed my statement back to:
Conditions
_c1FDoorUnlock tFDoorUnlockKelly or tFDoorUnlockPete
c1LROutletOn pLivingRoomOutlet==0 and DarkAnyDay and (_c1FDoorUnlock, NOW < 1:01)

It’s my understanding that this works because NOW will be true within the past minute and _c1FDoorUnlock will change as soon as Pete or Kelly unlocks the door. So as long as those two things happen within 1:01 the condition will be true. Since NOW changes every minute the condition will become false within a max of 1:59 seconds (I think that’s right anyway). So, as long as my living room light delay is longer than 2 min I shouldn’t get the light turn on/off I was getting.

I also think that in this case using NOW is not only my best option but it shouldn’t cause any delays, because it’s always true for the last minute.

Someone correct me if I’m wrong.

Edit: forgot to add “DarkAnyDay” in my conditions in first post. I had it removed for testing during the day.

Thought about it some more…

I simplified the variables to make it easier to read and think through.

How about something like this:

You will need to set up a self triggered timer called Timer3s by going to Inputs → Schedules → Create → Name = Timer3s → Start Type = Self Trigger → Stop Type = Interval → Every = 3 → Accept.

Link this trigger to the action for _Code by going to Actions → Add action for _Code → Advanced → Pick a device = PLEG → Select “Start Timer” → timername = Timer3s → Finished.

_Code = Kelly or Pete
AutoTurnOn = !LightOn and _Code and Night and Timer3s
AutoOnDetected = _Code;LightOn<3
AutoTurnOff = AutoOnDetected and (AutoOnDetected;NOW>5:00) and (_Code;NOW>5:00)

LightOn is a trigger tied to your outlet state = On.
AutoTurnOn has a single immediate action tied to it that turns on the light.
AutoTurnOff has a singe immediate action tied to it that turns off the light.
Timer3s is a 3 second self triggered timer set to start by _Code. This limits when the light can turn on to within 3 seconds of when a code is entered.

The key difference here is I introduced a condition “AutoOnDetected” that watches for an auto light on event and records a time stamp when it occurs. This condition should also prevent the light form turning off right away if you turn it on manually because then it would evaluate to false (turn on event did not take place within 3 seconds of a _code event). This should also cover the (somewhat unlikely but possible) case where multiple codes are entered within 5 minutes extending the turn off time when this happens. The self trigger timer (Timer3s) is needed so that the light can only turn on within 3 seconds after a code is entered. Otherwise it will also turn on by itself when night becomes true or whenever the light is turned off as you are describing.

PD

Update: Edited per RTS suggestion below… Thank you!
Update2: Added the Timer3s. Otherwise AutoTurnOn would execute every time Day turns to Night or whenever the light is turned off at night.

You might have a problem if there are any communication glitches with:

AutoOnDetected = _Code;LightOn<1

Maybe bump this to 2 or 3.

The rest looks good.

PD and Richard,

Thank you for your help! It is great to have such a powerful plugin. I am excited to finally start learning it and see such powerful results.

Pete