Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Date Comparisons? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
scottmi1
Groupie
Groupie
Avatar

Joined: July 11 2006
Location: United States
Online Status: Offline
Posts: 60
Posted: July 11 2006 at 08:58 | IP Logged Quote scottmi1

Hi,

Until recently, I was using a JDS Time Commander Plus (little brother to the Stargate) as my home automation controller. It was a great unit that I was able to do a lot of interesting things with, but unfortunately the TC+ just died, so I’m checking out PH as an alternative. I’m also considering adding an Elk M1G to add back the digital and analog interfaces.

I’m very impressed (and a little overwhelmed) by PH’s features so far and I’m having some problems figuring out how to replicate some of the things I was doing with the TC+. One item that has me stumped is that I used to have a flag/variable that indicated if today was a holiday. To set it, I had a long event (macro) that did a series of date comparisons connected by logical ORs. If any of the comparisons was true, the flag was set. I can see how to do this for a particular date (like New Years Day) using a timed event with the reference date, but how about a holiday like Labor Day (first Monday in Sept.)? Another date related task I would like to do is to play an announcement on recycling days, which are the first and third Thursdays of every month. Anyone doing something like this that they can share examples?

Thanks!
Back to Top View scottmi1's Profile Search for other posts by scottmi1
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: July 11 2006 at 14:59 | IP Logged Quote dhoward

Mike,

Welcome to PowerHome!

The dates are pretty easy. What I would do is create a global variable that is a flag whether today is a holiday or not. I would then create a macro that checks today's date against your criteria for whether today is a holiday and update the global variable accordingly. Then just call this macro from a timed event that is executed everyday at midnight.

The checks for specific days are easy enough like you said but even checking for the roving holidays like Labor day is easy. The check for this would be:

if(month(today()) = 9 and daynumber(today()) = 2 and day(today()) <= 7,1,0)

This formula will return a 1 if it's the first Monday of September, otherwise it returns a 0. You could basically set the Holiday macro to initially set the GV to 0 and then just run through a sequence of checks that sets the GV to 1 if it's a holiday. If you need help with this, just give me a list of holidays that you're interested in (dates and criteria) and I'll put together a fully commented macro and post it on the board.

Concerning the recycling days...this is easy too. Just create a timed event that runs every Thursday. Then include in either the macro or formula that is called a check to see if it's the first or third Thursday. This would look like:

if(daynumber(today()) = 5 and ((day(today()) <= 7) or (day(today()) >= 15 and day(today()) <= 21)),1,0)

If it's the first or third Thursdays of the month, the formula returns 1 otherwise it returns 0.

Let me know on those Holidays and I'll get the macro put together.

Dave.

Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
krommetje
Super User
Super User
Avatar

Joined: December 29 2004
Location: Netherlands
Online Status: Offline
Posts: 695
Posted: July 11 2006 at 16:07 | IP Logged Quote krommetje

I never thought of this... this opens possibilities to announce birthdays, to help you remind to take the trash out or better yet: To remind you of your aniversary

Peter
Back to Top View krommetje's Profile Search for other posts by krommetje Visit krommetje's Homepage
 
scottmi1
Groupie
Groupie
Avatar

Joined: July 11 2006
Location: United States
Online Status: Offline
Posts: 60
Posted: July 11 2006 at 16:35 | IP Logged Quote scottmi1

Dave,

Thanks for the quick response. I can't tell you how much help it is just to see an example or 2! I must have spent an hour staring at the function descriptions and couldn't figure this out. I'll take a crack at it and post the complete Holiday macro when I'm done. It'll be a good exercise for me.

For those who might have wondered how I intend to use this, this is a critical WAF item that has been lacking since my TC+ went belly up. On workdays, it's great to have the coffee ready when the alarm goes off, so I have a timed event for weekdays to do this. However. if it's a holiday we may want to sleep in and don't want to have sludge for coffee when we finally get up. So I want the timed event to skip holidays and then we kick off the coffee maker ourselves with a palmpad by the bed when we wake up.

Thanks again for your help, Dave. I'm sure I'll be back with more questions soon.
Back to Top View scottmi1's Profile Search for other posts by scottmi1
 
scottmi1
Groupie
Groupie
Avatar

Joined: July 11 2006
Location: United States
Online Status: Offline
Posts: 60
Posted: July 11 2006 at 18:41 | IP Logged Quote scottmi1

OK, I think I've got it (but I haven't tested it yet). Am I on the right track? All comments, critiques and suggestions are welcome.

Set Global HOLIDAY ""
Jump if(month(today()) = 1 and day(today()) = 1,1,3)
Set Global HOLIDAY "New Years Day"
Goto Label "holiday"
Jump if(month(today()) = 1 and daynumber(today()) = 2 and day(today()) > 14 and day(today()) < 22,1,3)
Set Global HOLIDAY "Martin Luther King Day"
Goto Label "holiday"
Jump if(month(today()) = 2 and daynumber(today()) = 2 and day(today()) > 14 and day(today()) < 22,1,3)
Set Global HOLIDAY "Presidents Day"
Goto Label "holiday"
Jump if(month(today()) = 5 and daynumber(today()) = 2 and day(today()) > 24 and day(today()) <= 31,1,3)
Set Global HOLIDAY "Memorial Day"
Goto Label "holiday"
Jump if(month(today()) = 9 and daynumber(today()) = 2 and day(today()) <= 7,1,3)
Set Global HOLIDAY "Labor Day"
Goto Label "holiday"
Jump if(month(today()) = 11 and daynumber(today()) = 5 and day(today()) > 21 and day(today()) < 29,1,3)
Set Global HOLIDAY "Thanksgiving Day"
Goto Label "holiday"
Jump if(month(today()) = 11 and daynumber(today()) = 6 and day(today()) > 21 and day(today()) < 29,1,3)
Set Global HOLIDAY "Day after Thanksgiving"
Goto Label "holiday"
Jump if(month(today()) = 12 and daynumber(today()) > 2 and daynumber(today()) < 7 and day(today()) = 24,1,3)
Set Global HOLIDAY "Christmas Eve"
Goto Label "holiday"
Jump if(month(today()) = 12 and daynumber(today()) > 2 and daynumber(today()) < 7 and day(today()) = 25,1,999)
Set Global   HOLIDAY "Christmas Day"
Label "holiday"
Back to Top View scottmi1's Profile Search for other posts by scottmi1
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: July 11 2006 at 19:23 | IP Logged Quote dhoward

Mike,

Yes, you've got it! Definately on the right track. I came up with something similar and modified it to match what you were doing. It goes something like this:

Code:

Set Global HOLIDAY ""
Jump /*New Years Day*/ if(month(today()) = 1 and day(today()) = 1,ph_setglobal_s("HOLIDAY","New Years Day") + 999,1)
Jump /*Martin Luther King Day*/ if(month(today()) = 1 and daynumber(today()) = 2 and day(today()) > 14 and day(today()) < 22,ph_setglobal_s("HOLIDAY","Martin Luther King Day") + 999,1)
...


This would give you the ability to make one global Holiday macro and would then allow users to pick the holidays they are interested in by just checking the "Skip" column of the ones they arent interested in.

Heh...didnt take you long to come up to speed

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
scottmi1
Groupie
Groupie
Avatar

Joined: July 11 2006
Location: United States
Online Status: Offline
Posts: 60
Posted: July 11 2006 at 21:21 | IP Logged Quote scottmi1

That's much more elegant. Just 9 lines for your version instead of 28 for mine! Here's how it came out:

Set Global Holiday ""
Jump if(month(today()) = 1 and day(today()) = 1,ph_setglobal_s("HOLIDAY","New Years ") + 999,1)
Jump if(month(today()) = 1 and daynumber(today()) = 2 and day(today()) > 14 and day(today()) < 22,ph_setglobal_s("HOLIDAY","Martin Luther King Day") + 999,1)
Jump if(month(today()) = 1 and daynumber(today()) = 5 and daynumber(today()) = 2 and day(today()) > 24 and day(today()) <= 31,ph_setglobal_s("HOLIDAY","Memorial Day") + 999,1)
Jump if(month(today()) = 9 and daynumber(today()) = 2 and day(today()) <= 7,ph_setglobal_s("HOLIDAY","Labor Day") + 999,1)
Jump if(month(today()) = 11 and daynumber(today()) = 5 and day(today()) > 21 and day(today()) < 29,ph_setglobal_s("HOLIDAY","Thanksgiving Day") + 999,1)
Jump if(month(today()) = 11 and daynumber(today()) = 6 and day(today()) > 21 and day(today()) < 29,ph_setglobal_s("HOLIDAY","Day after Thanksgiving") + 999,1)
Jump if(month(today()) = 12 and daynumber(today()) > 2 and daynumber(today()) < 7 and day(today()) = 24,ph_setglobal_s("HOLIDAY","Christmas Eve") + 999,1)
Jump if(month(today()) = 12 and daynumber(today()) > 2 and daynumber(today()) < 7 and day(today()) = 25,ph_setglobal_s("HOLIDAY","Christmas Eve") + 999,1)

Thanks again for your help with this, Dave!
Back to Top View scottmi1's Profile Search for other posts by scottmi1
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: July 14 2006 at 16:28 | IP Logged Quote dhoward

No prob.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
syonker
Senior Member
Senior Member
Avatar

Joined: March 06 2009
Location: United States
Online Status: Offline
Posts: 212
Posted: October 11 2010 at 14:16 | IP Logged Quote syonker

Adding on to an old topic with a perplexing question....

Hi Gang, I have a unique problem space and am trying to figure out how to implement it with the PH date functions. My wife has a work schedule where she gets "every other Friday" off (including this coming Friday, October 15th, 2010. I have a macro that wakes her up, but right now it's only smart enough to do this on weekdays.

I was wondering if anyone had any creative ideas on what the formula would be to determine "every other Friday" starting this coming Friday?

-S

__________________
"I will consider myself having succeeded when my house becomes sentient and attempts to kill me."

><(((º>`·.¸¸.·´¯`·.¸><(((º>¸.

·´¯`·.¸. , . ><(((º>`·.¸¸.·´¯`·.¸><(((º>
Back to Top View syonker's Profile Search for other posts by syonker Visit syonker's Homepage
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: October 11 2010 at 15:07 | IP Logged Quote BeachBum

You could have a wakeup on Fridays by checking the day number and check a global even or odd and flip the value. I’m sure there more fancier ways but this is easy for me.

__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 
syonker
Senior Member
Senior Member
Avatar

Joined: March 06 2009
Location: United States
Online Status: Offline
Posts: 212
Posted: October 11 2010 at 15:28 | IP Logged Quote syonker

Yup - that would be what I'm looking to do. Geez, I could have figured that on out. Forgive me - I'm about 4 cups of coffee short of a pot today...

Thanks again Pete!

BTW - I am all proud and smug now that I'm a "Groupie" (per our earlier discussion).   

-S

Edited by syonker - October 11 2010 at 15:29


__________________
"I will consider myself having succeeded when my house becomes sentient and attempts to kill me."

><(((º>`·.¸¸.·´¯`·.¸><(((º>¸.

·´¯`·.¸. , . ><(((º>`·.¸¸.·´¯`·.¸><(((º>
Back to Top View syonker's Profile Search for other posts by syonker Visit syonker's Homepage
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: October 11 2010 at 16:09 | IP Logged Quote BeachBum

Saw that… Funny you weren’t the first person to ask. If you’ve got the time the answer to the wakeup probably would be Timed Event Formulas.

__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: October 11 2010 at 16:44 | IP Logged Quote dhoward

Create a new Timed Event Formula. Make an appropriate Frequency Text and Description. Use the following for the formula:
Code:
datetime(relativedate(date(2010,10,15),[INCREMENT] * 14),00:00:00)


Now just create a timed event using this new frequency.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
syonker
Senior Member
Senior Member
Avatar

Joined: March 06 2009
Location: United States
Online Status: Offline
Posts: 212
Posted: October 11 2010 at 17:11 | IP Logged Quote syonker

Huh...that's the one-line, no {GLOBAL} version...I've already written the alternative, but I may change it to work this way. So far, I have a modified "CHECK HOLIDAYS" macro ("TODAY_IS") which looks at a number of holidays, and other days off she gets, which decides ultimately along with the "off friday" rule whether to wake her up or not.    Since she goes to sleep in different parts of the house (couch, baby room, master) depending on the events of the night before, I was thinking about using a motion sensor to figure out just *where* to wake her up (and not the rest of the house).

This is SOOOOOOO FUN Dave! Thank you for creating this masterpiece, and thank you to the rest of the forum users (like Pete, and Patrick, and the gang) for helping grow and support it.

I'm not going to say, "I can't wait for the next version" because I know you've probably heard that enough to be pulling your hair out....oh.....wait.....I guess I *did* just say that....oh well, please disregard.   

-S

__________________
"I will consider myself having succeeded when my house becomes sentient and attempts to kill me."

><(((º>`·.¸¸.·´¯`·.¸><(((º>¸.

·´¯`·.¸. , . ><(((º>`·.¸¸.·´¯`·.¸><(((º>
Back to Top View syonker's Profile Search for other posts by syonker Visit syonker's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum