Author Topic: Wait til x  (Read 3175 times)

Frunple

  • Hero Member
  • *****
  • Posts: 774
    • View Profile
Wait til x
« on: May 26, 2013, 04:27:23 am »
How can I say "wait til 6am" in a script?
The only type of 'wait' I can find is the System.sleep but that won't (I believe) use an exact time.


I'll explain further, maybe there's an easier way.
I have a rule that opens my blinds at sunset. I want them to open at sunset, if sunset is after 6am.
So at sunset, when the rule executes, I want to check the current time, if before 6am, wait til 6am, then open blinds.
If sunset is after 6am, just open blinds.
« Last Edit: May 26, 2013, 04:49:51 am by Frunple »

iostream212

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
Re: Wait til x
« Reply #1 on: May 26, 2013, 08:58:24 am »
I am not sure of an easy way to do this. It is definitely doable, but the way I am thinking will require some scripting.

I would:
1.) Set a rule to run at sunrise
2.) In the script for the rule save DateTime.Now which will be your sunrise reference
3.) Define a new constant DateTime  for 6:00am
4.) Compare the times
5.) If Sunrise < Constant get the difference by Constant - Sunrise
6.) Convert above into milliseconds
7.) Run your System.Sleep using above.

I can provide a working script if needed.
I always wanted to be somebody. In retrospect, I think I should have been more specific.

iostream212

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
Re: Wait til x
« Reply #2 on: May 26, 2013, 10:52:18 am »
Here is my previous post converted to a script:
Code: [Select]

Sunrise = DateTime.Now;
Constant = New DateTime(Sunrise.Year, Sunrise.Month, Sunrise.Day, 6, 00 , 00);
Wait = 0;

if (Sunrise < Constant)
{
TimeDifference = Constant - Sunrise;
TimeParts = String(TimeDifference).Split(":");

if (TimeParts.HighestIndex == 2)
{
Wait = Number(TimeParts[0])* 3600000 +  Number(TimeParts[1])* 60000 +  Number(TimeParts[2])* 1000;
}
else
{
Wait = Number(TimeParts[0])* 60000 +  Number(TimeParts[1])* 1000;
}

System.Sleep(Wait);
}

Scenes.test();
I always wanted to be somebody. In retrospect, I think I should have been more specific.

Frunple

  • Hero Member
  • *****
  • Posts: 774
    • View Profile
Re: Wait til x
« Reply #3 on: May 29, 2013, 06:06:48 am »
Just wanted to say thanks for this. Haven't tried it yet, I might just set them to open at 6am and leave it at that, trying that now anyway, I'll have to see the 'reaction' I get.
If no good I'll definitely give this a try.

iostream212

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
Re: Wait til x
« Reply #4 on: May 29, 2013, 12:38:46 pm »
No problem. I actually had a similar need... so two stones with one bird!

Sent from my Galaxy S4 using Tapatalk 2

I always wanted to be somebody. In retrospect, I think I should have been more specific.

superjer2000

  • Jr. Member
  • **
  • Posts: 21
    • View Profile
Re: Wait til x
« Reply #5 on: September 06, 2013, 09:30:34 pm »
Late to the party here but if I understand correctly, why wouldn't you just have two rules:

1) Fire at sunrise - check that the blinds are closed by checking a global variable.  if it is after 6am the open the blinds and set a global variable to indicate the blinds are open.

2)  Fire at 6:00am - check if the blinds are already open by checking the global variable  if they are closed, open them and switch the global variable.

Then another rule would maybe switch the global variable to false or closed at 5:00pm everyday.

So if sunrise was at 5:55am rule 1 would fire, the blinds would be closed but since it isn't 6:00am the blinds wouldn't open.
At 6:00am the blinds would open when the second rule fires.

If sunrise was at 6:10am rule #2 would open the blinds at 6:00am.

iostream212

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
Re: Wait til x
« Reply #6 on: September 06, 2013, 09:49:31 pm »
Good point! I love seeing how different paths can lead to the same result.  :)
I always wanted to be somebody. In retrospect, I think I should have been more specific.