Jump to content

How to run a program optionally?


arzoo

Recommended Posts

Posted

I’ve been working on vacation programs to turn lights on/off and I was wondering if there is a way to optionally execute a program? For example, I want to turn on some lights in my basement, but not every night.

 

I can think of one possible solution but it seems overly complex;

First, create a state variable, X (init 0). Next, create a program that runs each night at sunset. Set X=0, then use a Repeat 1 Time Random statement to increment X. So X will have a value of 1 or 2. Lastly, create a program triggered on the change of X value and set the IF condition to X=2. So the lights will only turn on if X=2 which is random each night.

 

Am I missing anything or is there a simpler way to achieve this?

 

Thanks

Posted

No, I think you pretty much have figured out the only way to randomize running of a program.

 

You could let the program run every day, but just randomize the start time and the duration time. Not exactly the same, but this is how most people would do it and it gives the impression someone is actually living there all the same.

Posted

I don't think I have yet to find a programming example where there was ONLY one way to do things. however, nothing is coming to mind that is any simpler. It seems your approach is pretty compact.

 

Do you want a given light to come on, if it comes on, at the same time? Off when?

Guest
This topic is now closed to further replies.

×
×
  • Create New...