I have a rule that opens the blinds on the ground floor. The individual blinds are not opened all at once, but in series, just as a person would go from switch to switch. This works nicely so far.
Now I want to run this rule from a ECMA 2011 javascript rule. I narrowed it down to just the exec part to see how it works.
org.graalvm.polyglot.PolyglotException: ReferenceError: “exec” is not defined
Unfortunately the documentation for java script in this area is not available.
Can someone show me how to solve this please or show me where I can find the documentation.
The helper library docs for the JSScripting rules can be found here and the full reference here.
But right now, you’re trying to reinvent the wheel (several times over). You do not need to call the rest API just to run another rule. You can do it from the helper library using runRule command. But, even better, you don’t need any scripting at all to run another rule. When you are building your rule just select the “Other rules” action in the action wizard:
Thanks Justin for your help but actually I want to run the “other rule” from a more complex script. This one above was just to check how to do it generally. So here is the script I want to call the other from:
/*
Dieses Script oeffnet die Rolllaeden am Morgen. Ist es zu den
Oeffnungszeiten noch dunkel bleiben sie zu bis die Uhrzeit
erreicht ist.
Es gelten unterschiedliche oeffnungszeiten fuer
- Wochentags ( 7 Uhr ) und
- Wochenenden ( 9 Uhr ).
Die Ausloeser dieses Scripts sind:
- Sonnenaufgang
- 7 Uhr
- 9 Uhr
Ist also der Sonnenaufgang nach 7 bzw. 9 Uhr geht der Rollladen
zum Sonnenaufgang auf und nicht zu den Uhrzeiten (7-, 9-Uhr).
*/
daysOfWeek = ["SO", "MO", "DI", "MI", "DO", "FR", "SA"];
daysOfWeekend = ["SA", "SO"];
sunPhases = ["DAYLIGHT", "SUN_RISE", "CIVIL_DAWN"];
currentTime = new Date();
currentDayOfWeek = currentTime.getDay();
currentWeekdayName = daysOfWeek[currentDayOfWeek];
currentSunPhase = items.getItem("Lokale_Sonnendaten_Sonnenphase").state;
time9AM = new Date();
time9AM.setHours(9, 0, 0, 0);
time7AM = new Date();
time7AM.setHours(7, 0, 0, 0);
console.log("Script rollos_morgens_rauf gestartet");
console.log("Sonnenphase ist " + currentSunPhase);
if ( sunPhases.includes(currentSunPhase) ) {
if ( daysOfWeekend.includes(currentWeekdayName) ) {
// Hier sind wir am Wochenende
console.log("Wochenende " + currentWeekdayName);
if ( currentTime < time9AM ) {
console.log("aktuelle Zeit ist vor 9 Uhr");
console.log("keine Aktion!");
} else {
console.log("aktuelle Zeit ist nach 9 Uhr");
console.log("Starte ROLLO hochfahren Wochenende!");
/*
at this point I want to trigger the other rule
*/
}
} else {
// Hier ist Werktag
console.log("Wochentag " + currentWeekdayName);
if ( currentTime < time7AM ) {
console.log("aktuelle Zeit ist vor 7 Uhr");
console.log("keine Aktion!");
} else {
console.log("aktuelle Zeit ist nach 7 Uhr");
console.log("Starte ROLLO hochfahren unter der Woche!");
/*
at this point I want to trigger the other rule
*/
}
}
}
You see that this is harder to achieve with what is offered by the UI.