Jump to content
View in the app

A better way to browse. Learn more.

Universal Devices Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to run a program optionally?

Featured Replies

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

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.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.