Rule query battery status OH4

I had this rule running under OH3.
Unfortunately this no longer works under OH4.
Unfortunately, I’m not a JS pro. Maybe someone can help me adapt this for OH4.
Grazie

var whatitis = "";
ir.getItem("Batteriestatus").members
                   .stream()
                   .filter(function(batt) {if(batt.state != "NULL"){return batt.state.intValue() <= 10}; } )
                   .forEach(function(batt) { whatitis = whatitis + batt.label +": "+ batt.state +"%" + "\r\n"; } );
if(whatitis != ""){
    events.sendCommand('TelegramText', "Batteriewarnung für: \r\n" + whatitis);
    events.sendCommand('AmazonEcho_Sprich', "Batteriewarnung für: \r\n" + whatitis);
}

Which JS Add-on? This looks like Nashorn JS. If so, per the list of breaking changes, you need to change the type from application/javascript to application/javascript;ECMAScript5.1 (or something like that, create a script action, choose Nashorn, and check in the code tab for the correct type to use).

Nashorn JS and GraalVM JS are not compatible. You must make sure the correct add-on is installed and the type is right based on the way the rule is written. This code must either be rewritten or the type changed so it uses the correct add-on to run.

It helps us a lot to post errors that occur when a rule “doesn’t work” as those to words can incomass an infinity.

Thank you Rick : )
I changed the Type to ECMAScript5.1 and now its works again.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.