Author Topic: "Daily at a specific time" whenever variable  (Read 2238 times)

Walken100

  • Full Member
  • ***
  • Posts: 190
    • View Profile
"Daily at a specific time" whenever variable
« on: April 13, 2011, 07:51:53 pm »
Figured I'd ask before I make a request.

Can the whenever time for a rule using a date time event of "daily at a specific time" be set to a variable.

The goal is to be able to set and display the variable in a touchscreen. My specific use is setback times in a thermostat.

Thanks.
Bart
So tell me again why I have a right half of my brain?

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2852
    • View Profile
    • Codecore Technologies
Re: "Daily at a specific time" whenever variable
« Reply #1 on: April 19, 2011, 09:00:58 am »
No, you would need to use the timers driver, which would probably be more complicated than you would want to get into.

You could store a date/time in a global variable using the following script:

vars.TriggerTime = new TimeSpan(6, 0, 0); //6am

Then calculate how long the timer should run and create a timer:

if (DateTime.Now.TimeOfDay < vars.TriggerTime)  // is the trigger time later today?
    triggerDateTime = DateTime.Now.Date + vars.TriggerTime; // today
else
    triggerDateTime = DateTime.Now.AddDays(1).Date + vars.TriggerTime; // tomorrow

triggerDelta = triggerDateTime - DateTime.Now;

timers.StartTimer("MyTimerName", triggerDelta);

Then you would add a new rule which triggers on the Timers driver's Elapsed event for the timer named MyTimerName. The event would do whatever you want but it would then need to run the same script as above to start the timer for the next day.

The trick is that you need some way to kick off the 1st execution of the script above which adds the timer. That could be a touch screen button or some other means.
John Hughes
Codecore Technologies

Walken100

  • Full Member
  • ***
  • Posts: 190
    • View Profile
Re: "Daily at a specific time" whenever variable
« Reply #2 on: April 19, 2011, 01:54:03 pm »
No, you would need to use the timers driver, which would probably be more complicated than you would want to get into.


I think you are right.  ;D

Thanks for the info. I may give it a try.
Bart
So tell me again why I have a right half of my brain?