Jump to content
C4 Forums | Control4

Lua question: Best way to schedule stuff?


jackstone

Recommended Posts

This question is aimed at C4 driver developers. I know there is not really mutual help between us but I'm throwing the question anyway...

I'm looking for a simple way to schedule stuff within a Lua script, without using C4 scheduling agent and without using the C4 API that only add scheduled event but can't add task to run..

I know there is a way, some of you guys have done it, maybe someone will have the kindness to share how he have done it... Or maybe C4 staff on this forum can help on that?

TIA

 

Link to comment
Share on other sites


17 hours ago, jackstone said:

This question is aimed at C4 driver developers. I know there is not really mutual help between us but I'm throwing the question anyway...

I'm looking for a simple way to schedule stuff within a Lua script, without using C4 scheduling agent and without using the C4 API that only add scheduled event but can't add task to run..

I know there is a way, some of you guys have done it, maybe someone will have the kindness to share how he have done it... Or maybe C4 staff on this forum can help on that?

TIA

 

Method 1 - Utilise os.time() and a initial timer set up a reoccurring timer to the period you want (this lines it up to the exact second.  You will need to do a bit of math eg every minute/five/half hour/hour) and utilise a table of a schedules (time stamps) to determine when you want to fire a schedule)

Method 2 - similar to above but rather than using timestamps utilise os.date to figure out the day of the week, month, year if you want to do reoccurring based on any of those factors.

Hope that helps.

Link to comment
Share on other sites

Thanks Alan, the method I've figured out is to do a recurring timer that read os.time in epoch format, than do some math to see if the current time match a schedule each time the looping timer expire. With some tolerance since the time input comes from an interval and not real time.

I'm not really sure if that is close to what you've explained?

Link to comment
Share on other sites

17 hours ago, jackstone said:

Thanks Alan, the method I've figured out is to do a recurring timer that read os.time in epoch format, than do some math to see if the current time match a schedule each time the looping timer expire. With some tolerance since the time input comes from an interval and not real time.

I'm not really sure if that is close to what you've explained?

Yep similar concept.  My method just aligns it to the minute rather than randomly whenever the timer starts.

Link to comment
Share on other sites

3 hours ago, alanchow said:

Yep similar concept.  My method just aligns it to the minute rather than randomly whenever the timer starts.

I see... so you're pulling os.time only once and then trust your recurring timer to keep track of time?
 

 

Link to comment
Share on other sites

I think I got it, at least for my case. I only have 8 daily tasks to schedule within the driver, so instead of polling os.time periodically, I just have to get the current time once a day, then start 8 timers each 24h interval, each timer will be set to the number of seconds before triggering based on the actual epoch time. 8 timers should be more efficient than a recurring one plus a loop of IF-THEN to check if an event is set to trigger...

Link to comment
Share on other sites

6 minutes ago, jackstone said:

I think I got it, at least for my case. I only have 8 daily tasks to schedule within the driver, so instead of polling os.time periodically, I just have to get the current time once a day, then start 8 timers each 24h interval, each timer will be set to the number of seconds before triggering based on the actual epoch time. 8 timers should be more efficient than a recurring one plus a loop of IF-THEN to check if an event is set to trigger...

If it’s 8 timers only you should do the math to align the timer up to whenever you have set it once off first off.  After that 24 hour repeating timers will do.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.