Jump to content

Else Statement Execution


dansmith

Recommended Posts

I know that there has been plenty of discussion on how IF, THEN, and ELSE statements execute. It took me a while to figure it out when I first got my ISY, but I thought that I finally had a handle on it. Have written some fairly complicated programs and everything has worked to my satisfaction. Then along comes what I think is something simple and it just doesn't work the way that I expected.

 

Here are two programs:

 

Program Kitchen Lights Away

If
       From    Sunset
       To      11:14:00PM (same day)
   And Program 'Away Flag' is True

Then
       Set 'Kitchen Pots' On

Else
       Set 'Kitchen Pots' Off

 

Program Away Flag

If
       Status  'DR Keypad D' is On

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

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


 

If I am away from the house then I set the DR Keypad D button on before I go. Then at Sunset the Kitchen lights will turn on and at 11:14 pm the kitchen lights will turn off. If I come home before 11:14 pm and turn Keypad D button off, then the kitchen lights will turn off. All works as expected and planned.

 

Last night I was at home and had manually turned the kitchen lights on about 11:00pm. At 11:14 pm the kitchen lights went out. This was not what I expected as the Away Flag was false. However, what appears to be happening is that at 11:14pm the schedule condition goes false and thus the ELSE statement is executed and the Kitchen Pots are turned off. Following that logic it makes sense that if the Away Flag is false then the ELSE statement would also be executed at Sunset.

 

I don't really want to put the Kitchen Lights Away program into a folder controlled by Away Flag as I have several other programs that I have written using Away Flag that won't work inside a folder. Is there any other alternative other than breaking this one tidy program into two programs; one for Kitchen Lights On and one for Kitchen Lights Off. That would avoid the ELSE statement.

Link to comment
At 11:14 pm the kitchen lights went out. This was not what I expected as the Away Flag was false.

 

It seems to me that this is exactly what should happen from your program. As I understand it, your program conditions will evaluate at sunset, 11:14p, and at any change-of-state in your away flag. In your case-in-question, it evaluated at 11:14. At the time it evaluated, your flag was false, therefore your condition was false. At that point, it executed the "then" condition, which turned off your kitchen lights.

 

Following that logic it makes sense that if the Away Flag is false then the ELSE statement would also be executed at Sunset.

 

I would, indeed, expect the else statement to execute at Sunset if the flag is false. Have you seen any evidence that it does not?

 

Is there any other alternative

 

I don't see where you describe how you wanted it to behave, so I assume you want is such that if the away flag is not set, then manual control of the kitchen light prevails? Given that you stated that you expected the kitchen light to go off when you come home before 11:14 and turn keypad D off, I assume you want to keep this feature, as well?

 

Despite your concerns, I tend to like the idea of putting this program into a folder controlled by the away flag. Contrary to your suggestions, I don't think this necessitates putting the other programs controlled by that flag into the same folder. I would keep them outside of the folder and expect them to work as before.

 

Simply putting this into a folder, hower, I would expect the kitchen light to stay on when you turn off keypad D. (I understand that programs immediately cease executing as soon as their folder condition goes false.) If this capability is important to you, then add a second program, outside the folder:

 

if

Program 'Away Flag' is False

Then

set 'kitchen pots' off

Else

Link to comment

Your correct, program event loop is going to check this if statement at sunset and register a status even if the Away Flag is false. I think the best option is two separate programs if you don't want to do the folder option.

 

Program Kitchen Lights Away On

 

If
       Time is Sunset
   And Program 'Away Flag' is True

Then
       Set 'Kitchen Pots' On

Program Kitchen Lights Away Off

 

If
       Time is 11:14:00PM
   And Program 'Away Flag' is True

Then
       Set 'Kitchen Pots' Off

 

Thanks,

Link to comment
I think the best option is two separate programs

 

As I understand, these two programs would also loose the capability of shutting off the kitchen lights by turning off the flag before 11:14. I am not sure if this is desired, but the OP described this as "expected".

Link to comment

Thanks guys for the help. For some reason I had a mental block on this one and just couldn't seem to see it straight. Either solution will work for me - it just becomes a question of whether I want the light to go out when I turn off the Away Flag. My programming background likes to keep similar functioning programs in the same style, but I am learning with the ISY that function takes precedence over form.

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...