Tutorial: How to find out if it's national holidays
I have some rules, which behavior should change if I am going to work or not. Weekends are easy, but consider that I stay home sick (I use virutal switch that needs to be set in advance) or there are national holidays. I have rules scheduled such as "turn on the coffee machine" or "wake me with lights". It's uncomfortable when you want sleep and these rules are triggered too early.
I want decide which rules should be triggered during days that I am going to work and which during weekends, holidays and the days that I am staying at home.
So my goal - I needed to let zipato know, that there is national holiday, so that it wont wake me up during Christmas etc.
Thanks to David Pitchard, who bring me to idea to use Google Aps script to do this.
The idea behind this is simple:
1. create virtual sensor on zipato named "isHoliday" (and control it's state from some external app)
2. create google workbook with two sheets.
First will have only regular holidays, such as christmas, which is always on the 24.12. every year.
Second will have irregular holidays, such as easter.
These holidays differs every year so you can't create simple rule, like
"if (month ==3 and day == 24 ) then". But you can write them down for
many years in front.
3. create google app script, that will be triggered
every night and call zipato isHoliday virtual sensor, with state calculated by
simple logic:
- IF ( currentDate is in regular holidays.setYear(currentDate.getYear)) then
>>return TRUE;
- ELSE IF (currentDate is in Irregular holidays) then
>>return true;
- ELSE
>>return false;
4. Use state of isHoliday virtual sensor to check whether I am going to work this morning :)
I am attaching simple tutorial with pictures and also the script it's self. Enjoy:)
Also for slovak folks... and excel with regular and irregular holiday up to 2022.
You're welcome!
That's an interesting approach. I actually do this with rules in Zipabox itself. I put in the standard ones and the variable ones, and just make a note to update the variable ones every year.
You're welcome!
That's an interesting approach. I actually do this with rules in Zipabox itself. I put in the standard ones and the variable ones, and just make a note to update the variable ones every year.
Thas was my first attempt. It was painful to create such long rule... since we have much more holidays than it's common, it was lot's of clicks :)
But I didn't wanted to remember to change the rule every year... this is much more conveniant and also testable, since I could easily debug it in google IDE. Now I can be almost sure that it will work... working with dateTime in zipato more like trial&fail process
Thas was my first attempt. It was painful to create such long rule... since we have much more holidays than it's common, it was lot's of clicks :)
But I didn't wanted to remember to change the rule every year... this is much more conveniant and also testable, since I could easily debug it in google IDE. Now I can be almost sure that it will work... working with dateTime in zipato more like trial&fail process
Great work Juraj, it is good to have clever people on board.
Great work Juraj, it is good to have clever people on board.
My running script is failing. The error is"
TypeError: Cannot call method "setHours" of undefined. (line 2, file "zipato")Line 2 is follows: date = new Date(date.setHours(0,0,0,0));
Basically copy and paste from tutorial. What might be wrong?
My running script is failing. The error is"
TypeError: Cannot call method "setHours" of undefined. (line 2, file "zipato")Line 2 is follows: date = new Date(date.setHours(0,0,0,0));
Basically copy and paste from tutorial. What might be wrong?
Replies have been locked on this page!