Jump to content

Newb programming confusion with RANDOM


barclay

Recommended Posts

Posted

Hi Gang,

 

This is my first ISY program and it doesn't seem to be working as I think it should. It's trying to alternate several lights for a randomized lived in look. Problem is, the program seems to be finishing too early! Like it often reports being done before 10pm, when it seems likely the mean would be much later, assuming random has some kind of normal distribution around the mean. Am I missing something about how this works? Also is there some kind of trace I can activate so I can see exactly how the program went.

 

If

Time is Sunset

 

Then

Wait 20 minutes (Random)

Set 'Workshop Landing Light' On

Wait 10 minutes (Random)

Set 'Kitchen Light' On

Wait 300 minutes (Random)

Set 'Workshop Landing Light' Off

Wait 420 minutes (Random)

Set 'Kitchen Light' Off

Wait 15 seconds (Random)

Set 'MBR Light' On

Wait 40 minutes (Random)

Set 'MBR Light' Off

 

Else

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

 

 

 

 

Thanks!

 

Barclay

Posted

Hi barclay,

 

The most important point to consider is that Wait and Repeat constructs are interruptible. This means that if the condition turns false while the program is in Wait or Repeat, then the program stops execution at that point and does not go any further.

 

The problem with your program is that Sunset + Grace period (Configuration | System tab) is less than the total amount of wait in your Then statement. As such, the program turns to false and stops prematurely.

 

What you may want to do is to change your condition and instead use:

If
  From Sunset
  To Sunset + 2 hours (same day)
Then
  ...

 

With kind regards,

Michel

Posted

I'm not quite sure I understand. My grace period is now set to the default I guess, of 10 minutes. The program is terminating perhaps 4-5 hours after it starts, when I would guess that it should terminate more like an average (taking the midpoints of the random intervals) of a total of 430 minutes or 7 hours later. But without a trace I can't tell exactly what's going on. If I understand what you're saying when "time is sunset" becomes false, which is I presume at sunset + 10 min, then the next time there is a wait, the program ends. So if I want to trigger on sunset, but not kill the program after the grace period, then how do I do it? Do I set the grace period for the maximum time the program might run after sunset, which is about 10 hours?

 

Is there a better way to do this? Should I set up some kind of variable that indicates whether the current state of the system is "sundown" or "sunup" i.e. dark or light outside, and then test on that?

 

Thanks,

 

Barclay

Posted

barclay

 

A common technique is to put the Then logic in a separate Program that does not have an If condition.

 

Program 1 is triggered by the current If condition (Time is Sunset) and the Then clause Runs Program 2 Then clause.

 

Program 2 Then clause contains the existing Then clause. The Waits will not cause Program 2 to terminate due to reevaluation as Program 2 has nothing in the If section.

 

This same approach is often used with Programs that are triggered on device status that can change over time before the Then clause completes and has Wait or Repeat Actions.

 

Lee

Guest
This topic is now closed to further replies.

×
×
  • Create New...