Announcement

Collapse
No announcement yet.

Precedence of AND and OR in Events

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Precedence of AND and OR in Events

    Does anyone know the precednce when using multiple OR IF + AND IF when creating an Event

    Question 1:
    For example. Creating the event like this:

    IF (condition1)
    OR IF (condition2)
    OR IF (condition3)
    AND IF (condition4)

    Would this be executed as

    condition1 OR condition 2 OR (condition3 AND condition4)

    or as

    (condtion1 OR condition2 OR condition3) AND (condition4)

    ?

    Question 2:
    So how would one create

    (condtion1 OR condition2) AND (condition3 OR condition4)

    Thanks in advance
    /Marcus

    #2
    Originally posted by metkhoo View Post
    Does anyone know the precednce when using multiple OR IF + AND IF when creating an Event

    Question 1:
    For example. Creating the event like this:

    IF (condition1)
    OR IF (condition2)
    OR IF (condition3)
    AND IF (condition4)

    Would this be executed as

    condition1 OR condition 2 OR (condition3 AND condition4)

    or as

    (condtion1 OR condition2 OR condition3) AND (condition4)

    ?

    Question 2:
    So how would one create

    (condtion1 OR condition2) AND (condition3 OR condition4)

    Thanks in advance
    /Marcus
    Hi Marcus,

    The first thing to note in HS3 events is the difference between Triggers and Conditions and then the order starts to make more sense.
    IF are triggers
    OR IF are triggers
    AND IF are conditions

    So in your questions 1 - Condition1,2 and 3 are all triggers with only Condition4 actually being a condition. Call them Trigger1, Trigger2, Trigger3 and Condition4.

    In your question 1 the event will be run:
    When Trigger1 occurs
    or
    When Trigger2 occurs
    or
    When Trigger3 occurs if Condition4 is also true

    You can have as many triggers (IF, OR IF) as you like in an event and each trigger can have any number of conditions (AND IF) attached to it. You will find that as you build up an event it is laid out with the conditions grouped with the triggers shown by a slight space to the next trigger.

    I hope this helps.

    Steve

    Comment


      #3
      Hi, Marcus,

      Question 1 answer:
      condition1 OR condition2 OR (condition3 AND condition4)
      (The AND IF operator has a higher precedence (earlier evaluation) than the OR IF operator.)

      Question 2 answer depends on whether your needs can be met by making two of your conditions triggers. As you know, there are two kinds of conditions. A trigger is a condition that initiates execution of an event, provided that there are no passive conditions that prevent it from doing so. A passive condition doesn't cause an event to run -- it just places an additional constraint on a trigger.

      The HS3 event language introduces a trigger with either of the keywords "IF" or "OR IF". The "AND IF" keyword introduces a passive condition which might or might not inhibit a preceding trigger.

      If your needs can be satisfied by making, say, condition1 and condition2 triggers, then the solution to question 2 might look like this:
      IF <condition1>
      AND IF <condition3>

      OR IF <condition1>
      AND IF <condition4>

      OR IF <condition2>
      AND IF <condition3>

      OR IF <condition2>
      AND IF <condition4>

      THEN ...

      If, however, you have a separate trigger in mind, and you want condition1 .. condition4 all to be passive conditions, then your solution might look like this:

      IF <trigger>
      AND IF <condition1>
      AND IF <condition3>

      OR IF <trigger>
      AND IF <condition1>
      AND IF <condition4>

      OR IF <trigger>
      AND IF <condition2>
      AND IF <condition3>

      OR IF <trigger>
      AND IF <condition2>
      AND IF <condition4>

      THEN ...

      Let me add that, while I am in general a strong advocate of the HomeSeer hardware and software system offerings, I am not a big fan of their event trigger/condition rules. With only slight additional condition complexity, the solution, while possible, can quickly get out of hand. (Suppose, for example, you wanted to throw an "ELSE" into the mix.) I have a programming background, and I'd like to be able to employ a more generalized if/then/else approach. There are at least two somewhat persuasive counterarguments: (1) Too much flexibility encourages violations of the KISS principle, and (2) if I really need to write complex trigger specifications, then I should start writing scripts. (Not there yet.)

      Anyway, I hope this helps.

      Comment


        #4
        Thanks to SteveMSJ and ericg. Your explanations certainly shed light on the issue. Very many thanks again /Marcus

        Comment


          #5
          It also might help to read this thread.

          The Event Clinic table of contents post is also a good reference.
          HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

          Comment


            #6
            Thanks for all the info here much clearer however, what would I need to do if I wanted:

            IF (trigger 1) occurs
            and either (condition 1) OR (condition 2) are satisfied
            THEN ...


            To save duplicating the THEN stuff, would I need to create three events for that?
            Event 1
            IF (trigger 1) occurs
            AND IF (condition 1) is satisfied
            THEN
            Do Event 3

            Event 2
            IF (trigger 1) occurs
            AND IF (condition 1) is satisfied
            THEN
            Do Event 3

            Event 3
            If (this event is manually triggered)
            THEN
            (Do stuff)

            Thanks
            /Marcus

            Comment


              #7
              Originally posted by metkhoo View Post
              Thanks for all the info here much clearer however, what would I need to do if I wanted:

              IF (trigger 1) occurs
              and either (condition 1) OR (condition 2) are satisfied
              THEN ...


              To save duplicating the THEN stuff, would I need to create three events for that?
              Event 1
              IF (trigger 1) occurs
              AND IF (condition 1) is satisfied
              THEN
              Do Event 3

              Event 2
              IF (trigger 1) occurs
              AND IF (condition 1) is satisfied
              THEN
              Do Event 3

              Event 3
              If (this event is manually triggered)
              THEN
              (Do stuff)

              Thanks
              /Marcus
              No. One Event:

              IF (trigger 1) occurs
              AND IF (condition 1) is satisfied

              OR IF (trigger 1) occurs
              AND IF (condition 2) is satisfied

              THEN
              (Do stuff)

              All Triggers and associated Conditions in a single event share common Actions.
              HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

              Comment


                #8
                Great thanks!

                Comment

                Working...
                X