Jump to content

Newbie If/Then/Else questoin


Recommended Posts

Posted

All,

I am using a MiLightStyle (yes i know it is no longer supprted) and have recently set it up for the first time.

 

My intention for the below scene is on a daily basis check if today is Sabbath or a Holiday. If so the Dining Room lights should be on from 10 AM until 4 PM.

While this actually works for those days that the criteria is met, it seems that every other day at 10:00 AM the lights are shutting off. I understand logically (more or less) why this is happening. My question is how do I avoid lights being shut off every other day? My family has not been to happy with lights randomly turning off on them :). Should I be splitting up this event into two separate events? Meaning, one event to turn on and one to turn off with conditions so that the Then is only hit when IsSabbathOrHoliday and IsOnVacation is False and there is no Else?. Will it work to change to a From 10:00AM for 6 Hours with no else statement? Meaning after 6 hours will the system know to automatically deactivate?

 

Any help would be appreciated.

 

Thanks!

 

IF

FROM 10:00:00AM

TO 4:00:00PM (same day)

And Program 'IsSabbathOrHoliday' is True

And Program 'IsOnVacation' is False

Then

Set Scene 'Links / Fixtures / Main Floor / Dining Room Lights' Activate

Else

Set Scene 'Links / Fixtures / Main Floor / Dining Room Lights' Deactivate

Posted

You nailed it on the head. At 10AM every day the program evaluates and if 'IsSabbathOrHoliday is false or IsOnVacation is true the program will evaluate fase and turn the lights off. Breaking the program in 2 would be the answer.

 

IF
FROM 10:00:00AM
TO 4:00:00PM (same day)
And Program 'IsSabbathOrHoliday' is True
And Program 'IsOnVacation' is False
Then
Set Scene 'Links / Fixtures / Main Floor / Dining Room Lights' Activate
Else

IF
Time is 4:00:00PM
And Program 'IsSabbathOrHoliday' is True
And Program 'IsOnVacation' is False
Then
Set Scene 'Links / Fixtures / Main Floor / Dining Room Lights' Deactivate
Else

Posted
All,

IF

FROM 10:00:00AM

TO 4:00:00PM (same day)

And Program 'IsSabbathOrHoliday' is True

And

Then

Set Scene 'Links / Fixtures / Main Floor / Dining Room Lights' Activate

Else

Set Scene 'Links / Fixtures / Main Floor / Dining Room Lights' Deactivate

Programme needs to be split into two as all the negatives will trigger the else code.

Namely

.4:00 PM

or

.Program 'IsSabbathOrHoliday' is NOT True

or

.Program 'IsOnVacation' is NOT False

or

10:00 AM and another status is false.

 

Two programmes, one disabled, can separate statuses conditions and stop them from initiating triggers.

Posted

Thanks for the quick response. Can you explain one other concept, what are the benefits of using scheduling of from->to versus from->for?

 

 

Thanks

Posted

Just a thought,

If i have an If condition on the folder level such as

If Program 'IsSabbathOrHoliday' is True

 

Would the else logic be hit if the if is false or would it just skip the whole program execution?

This would allow me to keep the events the way they are without splitting into Activate/Deactivate?

Posted
Thanks for the quick response. Can you explain one other concept, what are the benefits of using scheduling of from->to versus from->for?

 

 

Thanks

To me the benefit of using from/to is for simple programs such as:

 

If

From 10:00PM

to 6:00AM

Then

Turn something on

Else

Turn something off

 

The program only evaluates twice, once at 10 and once at 6. Once you start adding other conditions to the IF things get more complicated.

Posted

To me the benefit of using from/to is for simple programs such as:

 

If

From 10:00PM

to 6:00AM

Then

Turn something on

Else

Turn something off

 

The program only evaluates twice, once at 10 and once at 6. Once you start adding other conditions to the IF things get more complicated.

Twofold. The from-to construct acts as triggers at each time node as well as it can act as a condition filter for other triggers.

 

If

. Control from Motion Sensor is Switched On

and

. From 10:00PM

. to 6:00AM

 

Then

. Turn Driveway Lights on

. Wait 1 hour

. Turn Driveway Lights off

 

Else

. -

 

It is generally a good policy to avoid the else with multiple triggers/conditions as every false result of the complex logic will trigger it. Many don't like this aspect of the 'if' section conditions and would like an option in future versions that could eliminate the trigger from any conditional line of code.

Posted

So if I am understanding this correctly,

 

using from->to

would mean that the action is evaluated twice, at the from time and at the to time

 

using from->for

would evaluate the expression once?

 

Is there a practical differance?

Posted

Both from/to and from/for are evaluated twice. Once at "from time" which will be True if no other conditions and once at "to time"/"for end time" which will be False.

 

The from/to and from/for are simply two ways of establishing a start time and an end time. The from/to establishes specific times (sunrise and sunset would vary of course). The from/for establishes an ending time relative to the from time.

Posted

I find that From/to is ideal for fixed start end end times. From/For works better for moving targets like sunset. ie: Turn on a light at sunset for 4 hours. Otherwise one is no better than the other.

 

-Xathros

Posted
Both from/to and from/for are evaluated twice. Once at "from time" which will be True if no other conditions and once at "to time"/"for end time" which will be False.

 

The from/to and from/for are simply two ways of establishing a start time and an end time. The from/to establishes specific times (sunrise and sunset would vary of course). The from/for establishes an ending time relative to the from time.

Lee, for my own clarity.

 

While what you stated would be true when only the time frame trigger is installed in the "If" but when the time frame is used as a condition (used with another trigger) would the time constraint not be evaluated each time that other trigger even was incurred?

 

So as an example:

If
 Control from Motion Sensor is Switched On
and
 From 10:00PM
 to 6:00AM

Then
  Do It
Else
  -

 

Would the time parameters not also be examined for true or false (inside/outside the frame ) each time 'Control from Motion Sensor is Switched On' is triggered?

Posted
Both from/to and from/for are evaluated twice. Once at "from time" which will be True if no other conditions and once at "to time"/"for end time" which will be False.

 

The from/to and from/for are simply two ways of establishing a start time and an end time. The from/to establishes specific times (sunrise and sunset would vary of course). The from/for establishes an ending time relative to the from time.

Lee, for my own clarity.

 

While what you stated would be true when only the time frame trigger is installed in the "If" but when the time frame is used as a condition (used with another trigger) would the time constraint not be evaluated each time that other trigger even was incurred?

 

So as an example:

If
 Control from Motion Sensor is Switched On
and
 From 10:00PM
 to 6:00AM

Then
  Do It
Else
  -

 

Would the time parameters not also be examined for true or false (inside/outside the frame ) each time 'Control from Motion Sensor is Switched On' is triggered?

 

Larry-

 

This would only evaluate true when the Control was switched On between 10pm and 6am (next day assumed here). It would evaluate false at 10Pm and 6am due to the time triggers. IF you had used STATUS instead, then it may evaluate true at 10pm if the device was already on at 10pm.

 

Now, to the point of your question, anytime a program is triggered, the ENTIRE IF section is evaluated and runs true or false based on ALL of the conditions together.

 

LeeG's example was assuming no conditions beyond the time range.

 

-Xathros

Posted

Larry-

This would only evaluate true when the Control was switched On between 10pm and 6am (next day assumed here). It would evaluate false at 10Pm and 6am due to the time triggers. IF you had used STATUS instead, then it may evaluate true at 10pm if the device was already on at 10pm.

 

Now, to the point of your question, anytime a program is triggered, the ENTIRE IF section is evaluated and runs true or false based on ALL of the conditions together.

 

LeeG's example was assuming no conditions beyond the time range.

-Xathros

That's what I was thinking but after reading the statement I got overthinking it and started doubting what I thought I knew. :)

Thanks!

Posted

Anytime. :)

 

-Xathros

Posted

With this example the Program is triggered each time the Motion Sensor sends an On message, and at 10 PM and 6AM. The Then clause executes between 10PM and 6AM when the Motion Sensor sends an On message. The Time triggers (10PM and 6AM) will always evaluate as False because "If Control" will not exist at those exact times.

 

If Control 'Motion Sensor' is Switched On

and

From 10:00PM

to 6:00AM

 

Then

Do It

Else

-

Guest
This topic is now closed to further replies.

×
×
  • Create New...