PLEG Conditions / Logic Help

I’ve got three motion sensors m1, m2 and m3. I’ve got one bed pad sensor b1. I’ve got one door sensor d1.

I also have an alert device I want to turn on and off. I’ve got a schedule, sSleep, that is true between 9pm and 6am, a 1 minute retrigger, s1min, and a 10 second retrigger, s10secs.

I’m trying to set up PLEG so that if sSleep is true and m1 is tripped within 5 minutes of b1 being tripped OR if m2 or m3 are tripped within 15 minutes of b1 being tripped, and there hasn’t been any motion detected on m1, m2, or m3 for the past 20 mins, it triggers an action to turn an alert device on for 10 seconds then off again. It will repeat turing the alert device on and off for 10 seconds at a time every minute until d1 is true. The state of d1 during the first condition is irrelevant. The state of d1 only matters in resetting the sequence after the alert process has started. If the alert process has been begun and d1 is true then it should stop turning the alert device on and off (like a reset).

Naturally, after 20 minutes if the motion sensors are tripped again, all the conditions would be reevaluated and it is possible to restart the alert process.

I know it sounds like a mouthful, but I’m hoping someone can steer me in the right direction. I having trouble understanding some of the examples I’ve seen and I don’t really know where to start.

I’ve attached a floor plan to hopefully help articulate the location of the devices a little better.

Thanks,
Howie

I will give parts of this a try … I have no idea what the alert process is. You have not defined it.

When you say “within” do you mean before or after (i.e. it does not matter which is first!) ?

m23 m2 or m3
Turn Repeats on, this is true and gets a timestamp when either motion is detected.

m123 m23 or m3
Turn Repeats on, this is true and gets a timestamp when any motion is detected

MotionIn20 m123 @ 2 > 20:00
This is true if the current motion is more than 20 minutes since the last motion

Part1 sSleep and m1 and (b1, m1 < 5:00)
Part2 sSleep and m23 and (b1, m23 < 15:00)
If you meant for motion AFTER bed then change “b1,” in the above two to “b1;”

The rest of your problem I did not understand.

Firstly Richard thanks for taking the time. I’m having a little trouble understanding some of the conditions you’ve listed. For instance, m123 is true when m23 or m3 is true, but shouldn’t it be m23 or m1? Also, I don’t see where motionIn20 is used.

Here’s a brief overview of what I’m trying to do:

A person should be sleeping between 9pm and 6am. If they get up in the middle of the night b1 becomes true. If they exit their bed and begin to walk, m1 should trip and become true. At that point, as long m1 tripped after b1 within 5 minutes and there has been no motion on m1, m2 (bathroom) and m3 (living room) for the past 20 minutes, an alert process will begin. Likewise, if for some reason m1 isn’t tripped but m2 or m3 are tripped within 15 mins of b1 being tripped, the alert process will begin. The alert process is just a simple appliance on/off switch. I want it to go on for 10 seconds then off for 1 minute and repeat indefinitely until d1 becomes true. D1 represents a door being opened, hence someone has received the alert and has come to help.

I hope this explanation helps.

Thanks

So during sleep period if one gets out of bed the only way to NOT start the alarm process is to NOT make any motion for 5 minutes.

Yes, the condition for m123 should have been to or m1

yes that is true. thanks

Hey Richard,

Why is motionIn20 @ 2 > 20? shouldn’t it be @ 1 > 20?

Why is motionIn20 @ 2 > 20? shouldn't it be @ 1 > 20?
NO, your syntax says look at just the LAST (1) event and if the difference in time from the first to last (there is only 1) is less < 20 (seconds you wanted minutes) it will return true. Your syntax would ALWAYS be true.

Conditions (Repeats on the first two):
m23 m2 or m3
m123 m23 or m1
MotionIn20 m123 @ 2 > 20:00
Part1 d1 ; b1 ; m1 < 5:00
Part2 d1 ; b1 ; m23 < 15:00
StrartAlert sSleep and MotionIn20 and (Part1 or Part2)
StartShort !StopAlert and !s1Min
StartLong !StopAlert and !s30Sec
StopAlert StartAlert; d1

StopAlert should be the last condition! Define the conditions in the order specified.

Actions:
StartAlert: StartTimer s30Sec
Turn on Appliance Module
StartShort: StartTimer s30Sec
Turn on Appliance Module
StartLong: StartTimer s1Min
Turn off Appliance Module

Wow! That was SUPER helpful, thanks. Just wondering why d1 has to be true before b1 in Part1 and Part2. The problem is I can’t guarantee the state of d1.

It’s possible that d1 is open already when the cycle starts and needs to be closed and reopened in order to stop the alert. Is there a problem removing it from Part1 and 2?

H

A sequence expression does not requires it’s values to be true … It just looks at the timestamp.

So d1 had to be triggered sometime before going to bed (yesterday works!)

The reason for d1 in the sequence is that if the door opens it get’s a new timestamp and that expression will fail … even if someone is still in bed.

Okay that makes sense. I guess at some point the door would have to be open. On my workbench it was fresh out of the box so there was no prior time stamp.

No timestamp is the same as Jan 1, 1970 at 00:00:00

Something strange is happening. With d1 in place in those two conditions, sometimes it works, sometimes it doesn’t.

Look at (post) the Status report when things are working as expected.
You can see what/when things become true and false … and follow along with the logic to find the source of the problem.

Yeah, I checked out the status.

I’ve replaced the variable names we’ve been using with the real names. I’ve also added tResetSwitch which allows me to virtually reset the sequence as if the door sensor were tripped.

If you look at the Last True time stamp for the triggers in the condition cBedTripped, you’ll see that tDSLiving happened before tPSBed which happens less than 5 minutes before tMSBedVirtual, but doesn’t the < 5:00 parameter mean that all three events have to happen in less than 5 minutes, not just the last two events?

Take a look:

[size=16pt]Triggers[/size]
[table]
[tr]
[td]Name[/td][td]Description[/td][td]State[/td][td]Last True[/td][td]Last False[/td]
[/tr]
[tr]
[td]tDSLiving[/td][td]Whenever Door Sensor Living is armed and opened[/td][td]false[/td][td]2015-04-13 21:57:18.051[/td][td]2015-04-13 21:57:19.731[/td]
[/tr]
[tr]
[td]tMSBedVirtual[/td][td]VirtualSBed is turned on[/td][td]true[/td][td]2015-04-14 10:51:29.607[/td][td]2015-04-13 22:10:41.096[/td]
[/tr]
[tr]
[td]tPSBed[/td][td]Whenever Bed Pad Sensor is armed and closed[/td][td]true[/td][td]2015-04-14 10:51:28.682[/td][td]2015-04-14 10:51:27.592[/td]
[/tr]
[tr]
[td]tResetSwitch[/td][td]Reset Switch is turned on[/td][td]false[/td][td]2015-04-13 22:02:16.651[/td][td]2015-04-13 22:02:33.995[/td]
[/tr]
[/table]

[size=16pt]Conditions[/size]
[table]
[tr]
[td]Name[/td][td]Expression[/td][td]State[/td][td]Last True[/td][td]Last False[/td]
[/tr]
[tr]
[td]cBedTripped[/td][td]tDSLiving ; tPSBed ; tMSBedVirtual < 5:00[/td][td]false[/td][td]2015-04-13 22:02:04.073[/td][td]2015-04-14 10:51:28.685[/td]
[/tr]
[tr]
[td]cStartAlert[/td][td]cBedTripped or cBathLivingTripped[/td][td]false[/td][td]2015-04-13 22:02:04.076[/td][td]2015-04-14 10:51:28.686[/td]
[/tr]
[tr]
[td]cAbortAlert[/td][td](cStartAlert ; tResetSwitch) or (cStartAlert ; tDSLiving)[/td][td]true[/td][td]2015-04-13 22:02:16.659[/td][td]2015-04-13 22:02:04.082[/td]
[/tr]
[/table]

I think this change may have solved the problem:

tDSLiving ; tPSBed ; tMSBedVirtual < 5:00

becomes

(tDSLiving ; tPSBed ; tMSBedVirtual) and (tPSBed ; tMSBedVirtual < 5:00)

This way tDSLiving has to have happened before tPSBed which happened before tMSBedVirtual and tMSBedVirtual has to have happened within 5 minutes of tPSBed.

but doesn't the < 5:00 parameter mean that all three events have to happen in less than 5 minutes, not just the last two events?
Your right, my mistake ... need to break the sequence expression into two sequence expressions, the first does not have a timestamp, the second does ...

cBedTripped (tDSLiving ; tPSBed) and (tPSBed; tMSBedVirtual < 5:00)

The parenthesis are required around a sequence expression when they are combined in an expression.

In the future I recommend that you attach the STATUS report as a PDF file … there are plenty of free PDF print drivers (on windows you can use Cute PDF).

Great thanks. I think I’m finally getting it. Working like a charm with virtual switches. Today I implement real motion sensors.

Here’s another logic question for you:

Right now I’ve got a standard door sensor wired to a bed pad sensor (using the internal hardwire terminals). As long as a person is not on the bed, the state of the door sensor will be closed. My PLEG condition looks for this (door) sensor to be both armed and closed. Everything works fine accept if I disarm then rearm the door sensor, since the default state of the bed pad is closed, it evaluates to true in my condition. Is there a way to check if it’s been armed then opened then closed?

This way I can arm and disarm the (door) sensor during certain times throughout the day, but it won’t actually affect the conditions until is been opened once and then closed.

Thanks,
Howie

You would need two device propereries Armed and Tripped and then a sequence expression (Armed; Tripped)

Following up on our other thread at http://forum.micasaverde.com/index.php/topic,31758.0.html, can you give me an example of how I can use an incrementing variable each time cReAlert is true? I’ve attached a sample status report so you can see what I’ve got going on. Basically I want to send out an alert message on an action when cReAlert is true. The message would say something like “Realert 1”, “Realert 2”, etc.