Hi
I’m trying to convert a very simple rule from the Rules DSL to JSR223 Javascript and can’t for the life of me work out why it doesn’t execute properly…
Here’s the Rules DSL rule which works fine…
rule "Packed Lunch Reminder"
when
Time cron "0 0 22 * * ? *"
then
var Number DayOfWeek = now.getDayOfWeek
if ((DayOfWeek == 2) || (DayOfWeek == 7)) {
ECHOFRONTROOM_TTS.sendCommand("blah blah blah")
}
end
And the rule in JSR223 Javascript which fails… The rule triggers fine but the if statement never evaluates to true and therefore the command is never sent.
load(Java.type("java.lang.System").getenv("OPENHAB_CONF")+'/automation/jsr223/jslib/JSRule.js');
JSRule({
name: "Packed Lunch Reminder",
description: "Packed Lunch Reminder",
triggers: [
TimerTrigger("0 0 22 * * ? *")
],
execute: function (module, input){
// Get day of week
var DayOfWeek = new Date().getDay;
// Get required items as JSON object
var cTTS = getItem("ECHOFRONTROOM_TTS");
logInfo("Packed Lunch Reminder Running");
if (DayOfWeek == 1 || DayOfWeek == 7) {
curr = "blah blah blah";
sendCommand(cTTS, curr);
}
}
});
I’m sure I’m missing something really really obvious, just can’t see it…
Also, is it possible to output the value of a variable in a log message?