I wrote a javascript rule several months ago that included my first use of Ephemeis. I wanted a rule that would turn on a virtual switch, Christmas Season, on the first Advent Sunday. I was struggling with the use of Ephemeris but after a lot os searching around, and writing scripts to test possible solutions, I came up with a rule that I thought would work. I just had to wait for the first Advent Sunday. Well, today is the day and it worked, Christmas season is on, and that action in turn, activated other Christmas rules. Anyway here is my rule to turn on the Christmas season switch. It’s time activated through a cron expression.
Thank you for posting! It would be most helpful though if you posted the entire rule, not just the Script Action. How is this rule triggered for example? Click on the code tab from the rule’s page and paste the YAML you find there and we can see the whole rule in context.
Also, this appears to be Nashorn JS, correct? If it’s the newer JS Scripting add-on the following would be more standard.
Finally, please post your xml file. There are not a lot of examples of custom Ephemeris holiday xml files on the forum and a lot of people struggle with them.
You don’t need this line. The JS Scripting helper library does all this stuff for you. That’s what I meant by “more standard” above. You should almost never have to have a line that starts with Java.type in a JS Scripting 2022 rule.
I wanted to test the script condition ability within a rule so I created a test rule that sends a notification when a switch changes to on, but only if the above mentioned, First_Advent script evaluates to true. The rule threw an error. The reason is that getBankHoliday should be getBankHolidaName.
I wanted to set the record straight so that anyone finding this thread will have a working example of Ephemeris uses. Here’s the entire rule, one more time: