U.S. Holiday detection pistons


#1

Here are some pistons to run nightly that detect if today is a U.S. Holiday. They also find the previous and next holiday. Finally, they also calculate some floating holidays like Easter and the Jewish holidays on the first of the year.

The “Holidays” piston is the primary piston and it does not self-trigger. It must be run nightly from another piston. I have included my “Midnight Updates” piston as an example.

Just to be safe, I set them up to wait for the previous one to finish before running the next one.
Also run them at 12:01am or later (if you use midnight exactly, sometimes they run too soon and it is not the next day yet!).

They require these global variables:

string @HolidayChristmas = Christmas Day
string @HolidayColumbus = Columbus Day
string @HolidayEaster = Easter Day
date @HolidayEasterDate
string @HolidayElection = Election Day
string @HolidayHalloween = Halloween
string @HolidayIndependence = Independence Day
string @HolidayLabor = Labor Day
string @HolidayMLK = Dr. Martin Luther King Day
string @HolidayMemorial = Memorial Day
string @HolidayNewYears = New Year's Day
string @HolidayNext
date @HolidayNextDate
integer @HolidayNextDaysAway
string @HolidayPassover = Passover
date @HolidayPassoverDate
string @HolidayPresidentsDay = President's Day
string @HolidayPrevious
date @HolidayPreviousDate
integer @HolidayPreviousDaysPassed
string @HolidayRoshHashanah = Rosh Hashanah
date @HolidayRoshHashanahDate
string @HolidayStPatricks = St. Patrick's Day
string @HolidayThanksgiving = Thanksgiving Day
string @HolidayToday
boolean @HolidayTodayIsFederal = false
boolean @HolidayTodayIsObserved = false
string @HolidayValentinesDay = Valentine's Day
string @HolidayVeterans = Veterans Day
string @HolidayYomKippur = Yom Kippur
date @HolidayYomKippurDate







Piston Return Value?
Echo alarm clock
#2

Note: All the global variables are so you can compare @HolidayToday in other pistons. For example, based on the holiday, you can change your light colors.

I also use @HolidayTodayIsFederal to help detect when the kids are off from school.


#3

There is also @HolidayNext and @HolidayNextDaysAway so you can see what is coming up.

For example, “if @HolidayNext == @HolidayHalloween and @HolidayNextDaysAway < 10”,set lights to orange.

There is also “previous” holiday variables so you can make a range comparison like 10 days before/after a holiday.


#4

Also note that the Holidays piston is at the size limit of a piston (appears to max out at about 24 chunks). Any more logic added and it does not save.

I’ll probably have to break it up into a couple of pistons, like first/second half of the year.


#5

missing the “moon phase” piston for Jewish holidays
Doh! found it


#6

It would be nice if when importing a piston, it could create the global variables the piston requires.
@ipaterson

As to these pistons - I think I found a bug, in that the days past does not seem to be set correctly (for a previous holiday). It is as if the changing of the for variable {i} does not reset back as attempted when looking for the previous holiday.


#7

Sorry, I forgot to link that. Actually, it is currently hard coded to NOT use the Moon Phase piston because it wasn’t accurate enough. I should probably delete the code.


#8

You are right. The days passed is wrong. I’ll fix it this week and post again. I probably will also break apart the Holidays piston into months 1-6 and 7-12.


#9

I have updated the original post with the new pistons. I fixed the bug with the variable {i}. I guess you can’t change the for loop iterator. I changed it to a while loop and renamed the {i} to {daysAway}.

I also slightly split up “Holidays”. It now calls the “Holidays (Floating)” piston and the new bulky piston
“Holidays (Previous, Today, Next)”.

So your nightly piston just needs to call “Holidays” only. See the sample “Midnight Updates” piston I included.


#10

What is the global @PistonActiveColor ?

I did not see it in the list of globals to create or value


#11

That is “Green”. I just like to use different colors for different piston states. You can hard code that to any color or just rewrite that entire value however you want.

P.S. I wish we had global constants.


#12

This is awesome…thanks so much for sharing it.

I think the Previous Holiday isn’t being set due to the variable being named HolidayPreviousDay but it looks like the variable being set is HolidayPrevious – missing the ‘day’ in the variable name.

Awesome set of pistons however.


#13

Thanks!.. and I corrected the original post. It should have been HolidayPrevious (no Day suffix).


#14

This piston shows an issue in webcore

If you run the piston Holidays (Previous, today, next) and watch the logs
DST really hoses up addDays() function (i expect this will also hose add weeks, etc)

See NOTE BELOW @ipaterson

2019-03-13 09:22:06.449 am [trace]║ Next date: Sun, Feb 17 2019 Day of week: 1

2019-03-13 09:22:05.711 am [trace]║ Next date: Mon, Feb 18 2019 Day of week: 2

2019-03-13 09:22:05.020 am [trace]║ Next date: Tue, Feb 19 2019 Day of week: 3

2019-03-13 09:22:04.400 am [trace]║ Next date: Wed, Feb 20 2019 Day of week: 4

2019-03-13 09:22:03.685 am [trace]║ Next date: Thu, Feb 21 2019 Day of week: 5

2019-03-13 09:22:03.078 am [trace]║ Next date: Fri, Feb 22 2019 Day of week: 6

2019-03-13 09:22:02.348 am [trace]║ Next date: Sat, Feb 23 2019 Day of week: 0

2019-03-13 09:22:01.546 am [trace]║ Next date: Sun, Feb 24 2019 Day of week: 1

2019-03-13 09:22:00.905 am [trace]║ Next date: Mon, Feb 25 2019 Day of week: 2

2019-03-13 09:21:59.340 am [trace]║ Next date: Tue, Feb 26 2019 Day of week: 3

2019-03-13 09:21:58.463 am [trace]║ Next date: Wed, Feb 27 2019 Day of week: 4

2019-03-13 09:21:57.681 am [trace]║ Next date: Thu, Feb 28 2019 Day of week: 5

2019-03-13 09:21:57.073 am [trace]║ Next date: Fri, Mar 1 2019 Day of week: 6

2019-03-13 09:21:56.351 am [trace]║ Next date: Sat, Mar 2 2019 Day of week: 0

2019-03-13 09:21:55.562 am [trace]║ Next date: Sun, Mar 3 2019 Day of week: 1

2019-03-13 09:21:54.955 am [trace]║ Next date: Mon, Mar 4 2019 Day of week: 2

2019-03-13 09:21:54.226 am [trace]║ Next date: Tue, Mar 5 2019 Day of week: 3

2019-03-13 09:21:53.485 am [trace]║ Next date: Wed, Mar 6 2019 Day of week: 4

2019-03-13 09:21:52.874 am [trace]║ Next date: Thu, Mar 7 2019 Day of week: 5

2019-03-13 09:21:52.141 am [trace]║ Next date: Fri, Mar 8 2019 Day of week: 6

2019-03-13 09:21:51.517 am [trace]║ Next date: Sat, Mar 9 2019 Day of week: 0

NOTE SUNDAY IS MISSING - CHANGE DAY FOR DST

2019-03-13 09:21:50.784 am [trace]║ Next date: Mon, Mar 11 2019 Day of week: 1

2019-03-13 09:21:50.050 am [trace]║ Next date: Tue, Mar 12 2019 Day of week: 2

2019-03-13 09:21:48.893 am [trace]║ Next date: Sun, Mar 17 2019 Day of week: 0

2019-03-13 09:21:48.264 am [trace]║ Next date: Sat, Mar 16 2019 Day of week: 6

2019-03-13 09:21:47.510 am [trace]║ Next date: Fri, Mar 15 2019 Day of week: 5

2019-03-13 09:21:46.872 am [trace]║ Next date: Thu, Mar 14 2019 Day of week: 4


#15

You are correct. Here is a piston that demonstrates it. Looks like it is only on subtraction.

When you pass in negative 1, “addDays” seems to subtract an extra hour which takes you back to Saturday 11pm and “addWeeks” takes you back to Sunday instead of Monday.


#16

Actually, now looking closer, anytime you cross the DST threshold, it adds an extra hour when it shouldn’t. See the 1am value. They all should remain at 12am of each day.


#17

I think this is all fixed for the Hubitat version. There is a lot of cruft and mis-understandings of time handling in webcore.


#19

Hey guys I just imported these and have them humming along nicely EXCEPT when I go to add Christmas Eve to the (Previous, Today, Next) the “then” isn’t allowing me to populate it. I’m wondering if that piston is maximized and I need to start splitting, or what might be up. When I click on the “paste code” from copying the Christmas one, nothing happens. Also when I try to add it manually the “Add” button does nothing.

I am basically adding Christmas Day identically but on the 24th (or 23rd Friday/25th Monday (which would then push Christmas to have 26th Tuesday also)).

Thanks for the starting point!