Best format for date


#1

Hi,

I want to list holidays and then check daily if today is contained in holiday list.

I know how to create a list and check if said date is in the list. However, I’m not sure what would be the best way to handle dates. Time is of course irrelevant in that case.

What i’m trying to achieve is the follwing :

define
date[] holiday

Execute
Set variable (holiday[0]) = 2017-09-04
Set variable (holiday[1]) = 2017-10-09
etc.

And then a if block

contains(holiday,TODAY) is true
then

What system variable would you suggest me to use? I want to keep it simple and use bulletproof formatting. Thanks!


Change light color based on holday
#2

This is a piston I use to achieve a check against electric company holidays. (And weekends)

We have tiered electric where 12-7 m-f is significantly more expensive, outside of that and any listed holiday are cheap.
Since It is cheaper, on weekdays I have my ACs blow full cold at a variable time based on days high temp forecast on weekday non holidays in advance of noon. Basically only on high price days, it does precool

So I wrote this piston with a variable and a virtual switch to turn on only on days not to precool.
I use both, but specifically use the switch with some outside automations so it is easier to tie in that way.
The piston also watches if I manually change the switch (rare occasion) to match the variable’s condition to the switch, and if the local variable changes, it updates the global variable too. I have a local and global set differently because I’m adding another (semi related) layer to Automation later that I don’t want following the global variable, but that’s another story.
Lastly once annually it sends me reminders to update upcoming year’s holiday calendar

Again this piston is only for weekend and holiday tracking, I have other pistons that monitor the virtual switch

All I did was make a list of the holidays for the year, and once a year I have to update them. That’s it.
Then it does its thing the other 364 days per year


#3

@Cozdabuch that sounds like a great way to save some coin.

I would either compare against formatDateTime($now, 'MM-dd') or formatDateTime($now, 'YYYY-MM-dd'). The latter would be useful if you want to configure a few years in advance, the former if like Cozdabuch you want to update the dates each January (because then you wouldn’t need to change them all to 2018). I would stick the Set Variable calls for the dates in two groups - holidays that are the same date every year and others that need to be updated.


#4

Thanks to both of you, that helped me. I’ll post the result here later.


#5

I would like to set up a holidays piston like yours, but the backup code does not seem to be working anymore.
Would you mind sharing your piston again?
Thanks in advance.