Jump to content

How does If read and/or together?


BlakeB

Recommended Posts

Posted

EDIT: Oops, think I just found my solution tinkering around with it. Just saw the And (...)/ Or (...) Commands. I'll leave it here to see if I'm right, or for anyone else that doesn't notice maybe? Unless I should delete it.

 

I'm not sure if this is answered somewhere else, I looked and couldn't find quite what I'm looking for (granted I am new at searching forums), and sorry i it has been.

 

I'm trying to help my dad set up his programs, and he had one for his outside lights that wasn't working right. He wants it to turn his lights on an hour before sunrise, and turn them off 30 mins later. Here's what he had:

 

If: Time is sunrise - 1 hour

 

Then:

Set Scene 'Scenes / Outside Lights' On

Wait 1 hour 30 minutes

Set Scene 'Scenes / Outside Lights' Off

 

Else: nothing

 

It turns them on, but not off. I figure the problem was the Wait noticing that If is no longer true, so stops the process. I noticed conditions can't include scenes, and there are 2 separate lights in the scene. My plan was to do something like this:

 

If:

Time is sunrise - 1 hour

And Outside Light 1 is off

Or Outside Light 2 is off

 

Then:

Set Scene 'Scenes / Outside Lights' On

 

Else:

Wait 1 hour 30 minutes

Set Scene 'Scenes / Outside Lights' Off

 

Turning them on if either light is off. But, I don't know if the If will think

 

If

(Statement 1 AND Statement 2) OR statement 3 is true

 

or

 

If

Statement 1 is True AND (Statement 2 or 3)

 

I don't know if this even makes sense. Any help would be appreciated, or if you need clarification on anything. (Also, I think it has a couple other problems based on how the and/or will work, but I can get to those later).

Posted

UDI Wiki has a good section on order of precedence. Rather than trying to remember which takes precedence just include parentheses.

 

If
       Time is Sunrise -  1 hour 
   And (
            Status  'ICON Dimmer 1' is Off
         Or Status  'ICON Relay 2' is Off
       )

Then
  - No Actions - (To add one, press 'Action')

Else
  - No Actions - (To add one, press 'Action')



  - No Actions - (To add one, press 'Action')

 

The first Program that has only a specific time trigger should work. The Wait could be a problem if something could trigger the Program again driving the Else clause before the Wait completes but that is not the case. It is suggestive of a communication problem, perhaps caused by the specific lights in the Scene generating noise or some other appliance that is On around the time the Set Scene Off should work.

 

The other examples where Status is checked could cause the If to be reevaluated before the Wait completes preventing the Set Scene Off from executing.

Posted

Thanks for the reply! I still have a few things I want to fix with the program, this was just the first quick fix I thought of for now, and that was an issue that would most likely come up again.

Posted

Blake,

 

As Lee mentioned. Be very careful using "wait". You need to look at every line of your "if" clause and if any of them could trigger during the "wait" it will reset the program and the "wait" will end. You can do this on purpose, but it tends mostly to happen as an unintended issue that causes your program to behave other than as intended.

 

Using a wait on a program where the only "if" is something like "time is . . ." will not be a problem since the program would not be re-triggered (unless your wait is more than 24 hours).

Using "status" or "control" in your "if" clause could be trouble. If the status of the light changes or someone pushes the switches button, the wait will end right then. Again, this can be used on purpose.

 

To use "wait" where you also want other if conditions that might re-trigger, you need to write two programs where the first program calls the second program containing the "wait".

Posted

I have forgotten most of my boolean logic, but I remember that "and" takes natural priority over "or":

 

x and y or z = (x and y) or z

 

All contiguous "ands" are naturally treated as within parenthesees, separated by "ors".

Guest
This topic is now closed to further replies.

×
×
  • Create New...