Status of triggers and sequence (apparently) being ignored

Hi

I have a strange one, not sure if related to the issues I found with triggers showing true when not. I have a condition in this PLEG that detects when the house is empty and one that detects someone comes home. When the AutoAwayDetect fires, the AutoHomeDetect fires immediately after, and things go into a flip flop loop. I have looked at the report and as far as I can tell, the AutoHomeDetect is ignoring both the status of FrontDoorOpen, which should be true for it to fire (its false) and also the sequence, which shows the timestamps are in the opposite order to that which is specified in the condition. Any ideas what could be going on please?

cAutoAwayDetect No mHome AND !sUpstairsMotion AND !sDownstairsMotion AND (!cUpstairsMotion;!cDownstairsMotion) AND (!cDownstairsMotion;!tFrontDoorOpen;!sDownstairsMotion < 3300) true 2016-05-04 12:18:01.138 2016-05-04 12:17:46.120
cAutoHomeDetect No mAway OR mVacation AND tFrontDoorOpen AND (mAway;tDriveMotion;tFrontDoorOpen) false 2016-05-04 12:17:46.142 2016-05-04 12:18:01.117

The main issue is with the OR. An OR mixed with AND without parenthesis will cause unexpected things to happen.

This would be better logically:

(mAway OR mVacation) AND tFrontDoorOpen AND (mAway;tDriveMotion;tFrontDoorOpen) 

Ok I will try that thanks. Can you give me a little more explanation as to why this misplaced OR causes the actual status of FrontDoorOpen and the (properly parentheses enclosed) sequence expression to be ignored?

Cheers

[quote=“TheRedPill, post:3, topic:192258”]Ok I will try that thanks. Can you give me a little more explanation as to why this misplaced OR causes the actual status of FrontDoorOpen and the (properly parentheses enclosed) sequence expression to be ignored?

Cheers[/quote]

I think without the parenthesis, everything on either side of the OR became a statement.
So in effect

mAway OR mVacation AND tFrontDoorOpen AND (mAway;tDriveMotion;tFrontDoorOpen)

was interpreted like:

mAway OR (mVacation AND tFrontDoorOpen AND (mAway;tDriveMotion;tFrontDoorOpen))

So it became true if only mAway was true. Richard would have to weigh in on how PLEG interprets logic, but I think that is how it would work in standard logic conventions - AND has higher precedence than OR, so the ANDs get evaluated first.

Ah ok that makes a lot more sense. Thank you!

BTW, I just realized this is covered in the PLEG basics PDF under “Logical Expressions” and it discusses how the AND versus OR precedence works… (Thanks to @RexBeckett for this…)

If you remember your Algebra … not all operations are associative.
The Behavior of PLEG is defined … from the website … highest precedence operations go first … AND has a higher precedence than OR!
The precedence order is pretty standard in most programming languages.

General Expressions

Note that the leading number for each of the following expressions indicates the precedence of the operator. You can use parenthesis to change the precedence.

Expressions with String Values
The following operators are supported from lowest to highest precedence (precedence level indicated).
4 - eq ne gt ge lt le =~
The =~ operator is a substring match operator. The left hand string is the string to search. The right hand string is the string to search for. This is a case sensitive search. A search string wrapped with forward slaches of the following format: “/SomePattern/” interprets “SomePattern” as an LUA regular expression like match.
5 - … (concatenation operator)

Expressions with Number Values
The following operators are supported from lowest to highest precedence (precedence level indicated).
4 - == != > >= < <=
6 - + -
7 - * /
8 - % (modulo operator)
9 - - (unary negation)
10 - # #! Return the On or Off Timestamp Respectively

Expressions with Boolean Values
The following operators are supported from lowest to highest precedence (precedence level indicated).
2 - or
3 - and
9 - not ! (unary negation operators)

Condition Expressions (precedence level indicated).
1 - XX ? YY : ZZ
Which is interpreted as if XX then YY else ZZ
The XX expression must evaluate to true or false. If XX is true then YY is returned. If XX is false, ZZ becomes the result. This expression has the lowest precedence of any operators, use parenthesis to explicitly control the order of evaluation.

Literals
String Literals “A String” or ‘A String’
Number Literals 23 or 123
Time Literals HH:MM:SS - On the Left Side of A Sequence Expression, this is an absolute time during the current day, on the right side it is a relative time.

Algebra was never my strong point :wink: I think I get it now though… thanks for your patience!

@TheRedPill, question did you finally get your “Alarm and Home State” PLEG to work as you envisioned? if so would you be so kind and share your latest? Mike