If you are using Blockly you don’t have to do anything. When you upgrade to OH 4 you can open and save your rules and they will be recompiled to GraalVM JS Scripting automatically for you.
You will have to install the GraalVM JS Scripting add-on separately though, No JS comes with OH any longer as of OH 4. Only Rules DSL comes by default and even that is being looked at to remove and move to an add-on.
That was a temporary error. That message was incorrect and has since been corrected. You should remain on Java 11 for 3.4.2.
You don’t have to worry about it. @stefan.hoehn and @florian-h05 spent a lot of time making sure that your Blockly scripts will upgrade with minimal effort on your part. But again, you will have to install the JS Scripting add-on. There is no getting around that.
A much better approach for this is to use a cron trigger.
Let’s say that FlurSteckdose_Leistung updates every 10 seconds (which is pretty slow compared to what I’ve seen most of these power sensors report).
This rule triggers and immediately sleeps for 2 minutes. In that two minutes, the rule is retriggered 12 more times before the first one runs. Finally the rule runs and does it’s thing and then it runs again, waits two more minutes and an addition 12 triggers pile up in the mean time. Now we have 23 triggers of this rule queued up waiting to run. Two minutes later the rule runs again but in the mean time 12 more triggers piled up. Now we have 34 triggers of this rule waiting to run. At this point those remaining 10 triggers of the rule are probably starting to time out so you’re probably topped out at around 34 triggers of the rule always waiting to run at all times.
You can achieve the behavior you are after (i.e. every two minutes check if the power is less than 1.5 W) by using a cron trigger to run the rule every two minutes (get rid of the other triggers), add a condition to check if FlurSteckdose_Leistung is below 1.5 W and maybe another one to check if FlurSteckdose_Betrieb is ON, and your script action just needs to send command to FlurSteckdose_Betrieb. You don’t even need Blockly for this.
If you change your requirement to turn the switch off when it uses < 1.5 W for two minutes then it’s better to use a Timer. In that case, trigger the rule when FlurSteckdose_Leistung changes only. In the script action (in JS Scripting):
var currState = Quantity(event.itemState.toString());
var threshold = Quantity('1.5 W');
// If the current state < 1.5 W create the timer if it doesn't exist
if(currState.lessThan(threshold) && cache.private.get('timer') === null) {
cache.private.put('timer', actions.ScriptExecution.createTimer(time.toZDT(120000, () => {
console.log('switch power off');
items.FlurSteckdose_Betrieb.sendCommand('OFF');
}
}
// If the current state is above the threshold and the timer exists, cancel the timer
else if(cache.private.get('timer') !== null) {
cache.private.get('timer').cancel();
}
The above code creates a timer as soon as the wattage drops below 1.5 to wait for two minutes. If there is a timer and the wattage is >= 1.5 the timer gets cancelled. As a result, the Item will only be commanded to OFF when the wattage has measured under 1.5 W for two minutes.