Rules and Scripts not executing anymore - after OH4 Update

Hi all,
since i had updated my OH instance to to OH 4, and updated the Java Zulu to 17,
all my rules are not executing anymore.
I am not sure, which kind of debug information i have to provide,
but here u can see already my informations about the system.

runtimeInfo:
version: 4.0.1
buildString: Release Build
locale: de-DE
systemInfo:
configFolder: C:\openhab\conf
userdataFolder: C:\openhab\userdata
logFolder: C:\openhab\userdata\logs
javaVersion: 17.0.7
javaVendor: Azul Systems, Inc.
javaVendorVersion: Zulu17.42+19-CA
osName: Windows 10
osVersion: “10.0”
osArchitecture: amd64
availableProcessors: 4
freeMemory: 274417376
totalMemory: 633339904
startLevel: 70
bindings: null
clientInfo:
device:
ios: false
android: false
androidChrome: false
desktop: true
iphone: false
ipod: false
ipad: false
edge: false
ie: false
firefox: false
macos: false
windows: true
cordova: false
phonegap: false
electron: false
nwjs: false
webView: false
webview: false
standalone: false
os: windows
pixelRatio: 1
prefersColorScheme: dark
isSecureContext: false
locationbarVisible: true
menubarVisible: true
navigator:
cookieEnabled: true
deviceMemory: N/A
hardwareConcurrency: 24
language: de-DE
languages:
- de-DE
- de
- en-US
- en
onLine: true
platform: Win32
screen:
width: 3440
height: 1440
colorDepth: 24
support:
touch: false
pointerEvents: true
observer: true
passiveListener: true
gestures: false
intersectionObserver: true
themeOptions:
dark: dark
filled: true
pageTransitionAnimation: default
bars: light
homeNavbar: simple
homeBackground: default
expandableCardAnimation: default
userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/115.0.0.0 Safari/537.36
timestamp: 2023-08-06T15:50:25.216Z

I think you need to provide more information about which type / languar of rules you use.
What about the log files ? What do they show ? E.g. an error about missing JS service ?

i found something in the log, i hope it helps…?

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);


HausPV = itemRegistry.getItem('FroniusFlow_PVLeistung').getState();
GartenPV = itemRegistry.getItem('FroniusFlowGartenhaus_PVLeistungGarten').getState();
GesamtPV = GartenPV + HausPV;
logger.info('Ausgeführt');
events.postUpdate('Dacheistung_PV_kpl', GesamtPV);

2023-08-06 18:32:13.830 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '35647672fe' failed: var HausPV, GartenPV, GesamtPV;

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);


HausPV = itemRegistry.getItem('FroniusFlow_PVLeistung').getState();
GartenPV = itemRegistry.getItem('FroniusFlowGartenhaus_PVLeistungGarten').getState();
GesamtPV = GartenPV + HausPV;
logger.info('Ausgeführt');
events.postUpdate('Dacheistung_PV_kpl', GesamtPV);

2023-08-06 18:32:42.344 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '35647672fe' failed: var HausPV, GartenPV, GesamtPV;

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);


HausPV = itemRegistry.getItem('FroniusFlow_PVLeistung').getState();
GartenPV = itemRegistry.getItem('FroniusFlowGartenhaus_PVLeistungGarten').getState();
GesamtPV = GartenPV + HausPV;
logger.info('Ausgeführt');
events.postUpdate('Dacheistung_PV_kpl', GesamtPV);

2023-08-06 18:32:43.664 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '35647672fe' failed: var HausPV, GartenPV, GesamtPV;

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);


HausPV = itemRegistry.getItem('FroniusFlow_PVLeistung').getState();
GartenPV = itemRegistry.getItem('FroniusFlowGartenhaus_PVLeistungGarten').getState();
GesamtPV = GartenPV + HausPV;
logger.info('Ausgeführt');
events.postUpdate('Dacheistung_PV_kpl', GesamtPV);

These are Blockly rules?

As discussed in the breaking changes section of the release notes, you must open all of your Blockly rules and save them to convert them to the new JS Scripting add-on.

Hi,
yes all of these are blockly rules,
i try it out. I open all of these and press save, but still not running.
I have to take care about anything special when i am doing this step?
/all the best

Is the code changing after you saved? You should not see “itemRegistry” in any of the code for your Blockly rules after opening it and saving the rule.

You may need to open the actual Blockly scripts themselves and save, not just the rule.

Hi,
i checked that, and i guess it is not changing.
As u can see u see the “itemRegistry”

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: FroniusFlowGartenhaus_PVLeistungGarten
    type: core.ItemStateUpdateTrigger
  - id: "2"
    configuration:
      itemName: FroniusFlow_PVLeistung
    type: core.ItemStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "4"
    configuration:
      blockSource: <xml
        xmlns="https://developers.google.com/blockly/xml"><variables><variable
        id="4x?XOQmvJRl2PhQxEqyh">HausPV</variable><variable
        id="}x,NKF.(rJ$.%YE@3EY?">GartenPV</variable><variable
        id="A{:ey`Su4wn{wys#?|fn">GesamtPV</variable></variables><block
        type="variables_set" id="Y,nnh}W#B|-PxRLjdmxM" x="441" y="83"><field
        name="VAR" id="4x?XOQmvJRl2PhQxEqyh">HausPV</field><value
        name="VALUE"><block type="oh_getitem_state"
        id="zF9}$[S|7oI7#L1gZOU)"><value name="itemName"><shadow type="oh_item"
        id="XJv74Kc#c*#HYm_:CH=l"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="iE|`I+a24j+.ALaZK_c/"><mutation itemName="FroniusFlow_PVLeistung"
        itemLabel="PV Leistung"></mutation><field
        name="itemName">FroniusFlow_PVLeistung</field></block></value></block></value><next><block
        type="variables_set" id="OR[fSf7w:!0dho2JhUWc"><field name="VAR"
        id="}x,NKF.(rJ$.%YE@3EY?">GartenPV</field><value name="VALUE"><block
        type="oh_getitem_state" id="GGkjHVUP0{qZRMwHm=Eg"><value
        name="itemName"><shadow type="oh_item"
        id="Qyizy)Ll9j1rJIp^UeQd"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="gVT~FoO![B5I9qK4ecqy"><mutation
        itemName="FroniusFlowGartenhaus_PVLeistungGarten" itemLabel="PV Leistung
        Garten"></mutation><field
        name="itemName">FroniusFlowGartenhaus_PVLeistungGarten</field></block></value></block></value><next><block
        type="variables_set" id="n].PjXpR~jEGTuXeYb)D"><field name="VAR"
        id="A{:ey`Su4wn{wys#?|fn">GesamtPV</field><value name="VALUE"><block
        type="math_arithmetic" id="41BsA(].6WT0YhfbrlHn"><field
        name="OP">ADD</field><value name="A"><shadow type="math_number"
        id="yL%[?wM-%d(,p^6T2Nq9"><field name="NUM">1</field></shadow><block
        type="variables_get" id=":Q6]l@(^/)8Wk,Z2*nUd"><field name="VAR"
        id="}x,NKF.(rJ$.%YE@3EY?">GartenPV</field></block></value><value
        name="B"><shadow type="math_number" id="q6VKOTvYt%=.s=mQ{{{)"><field
        name="NUM">1</field></shadow><block type="variables_get"
        id="xflTb0|{Dyd[sfr7wT{@"><field name="VAR"
        id="4x?XOQmvJRl2PhQxEqyh">HausPV</field></block></value></block></value><next><block
        type="oh_log" id="DEIBC.6BlLy:9+S*9JX4"><field
        name="severity">info</field><value name="message"><shadow type="text"
        id="^dlS3_.WPm)D5uyH3xLx"><field name="TEXT">abc</field></shadow><block
        type="text" id="OC~p7F]=?=4287`wIEkC"><field
        name="TEXT">Ausgeführt</field></block></value><next><block
        type="oh_event" id="o37Uy(80FL6+!6se%vdM"><field
        name="eventType">postUpdate</field><value name="value"><shadow
        type="text" id="w5UHssxSvkbsL}B|Wa(R"><field
        name="TEXT">value</field></shadow><block type="variables_get"
        id="8GPb:MVYSS/!%{/NgQ7z"><field name="VAR"
        id="A{:ey`Su4wn{wys#?|fn">GesamtPV</field></block></value><value
        name="itemName"><shadow type="oh_item"
        id="BIMWWUa%=c{IUOL9r~=E"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="S0:@Su$4l0hhN#Qq|UaD"><mutation itemName="Dacheistung_PV_kpl"
        itemLabel="Dachleistung PV"></mutation><field
        name="itemName">Dacheistung_PV_kpl</field></block></value></block></next></block></next></block></next></block></next></block></xml>
      type: application/vnd.openhab.dsl.rule
      script: >
        var HausPV, GartenPV, GesamtPV;


        var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);



        HausPV = itemRegistry.getItem('FroniusFlow_PVLeistung').getState();

        GartenPV = itemRegistry.getItem('FroniusFlowGartenhaus_PVLeistungGarten').getState();

        GesamtPV = GartenPV + HausPV;

        logger.info('Ausgeführt');

        events.postUpdate('Dacheistung_PV_kpl', GesamtPV);
    type: script.ScriptAction

Right, so like I said:

  1. open the rule
  2. open the Blockly Script Action/Condition in the rule
  3. save
  4. Click the code option to see if the code has converted.

image

I do exactly what u mentioned in the steps,
but I still see this code, and seems not to be converted:

var HausPV, GartenPV, GesamtPV;

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);


HausPV = itemRegistry.getItem('FroniusFlow_PVLeistung').getState();
GartenPV = itemRegistry.getItem('FroniusFlowGartenhaus_PVLeistungGarten').getState();
GesamtPV = GartenPV + HausPV;
logger.info('Ausgeführt');
events.postUpdate('Dacheistung_PV_kpl', GesamtPV);

I don’t use Blockly day to day so I don’t know what is going on. Do you see “Rule Updated” in the bottom left corner when you save it?

The docs are pretty clear. Rules Blockly | openHAB

  • Make sure the JS Scripting Addon (opens new window)addon is installed.
  • To convert / migrate a rule that was created in openHAB 3 (NashornJS) to a GraalJS-compatible one for openHAB 4, simply open each Blockly rule once in openHAB 4 and save it - that’s it.
  • In this case, nothing more needs to be installed additionally to openHAB 4.

Hi Rich,
thank you very much for your patience!
It was absolutly my fault and the docs safe my time, but wasting yours during the discussion.

The fault and my solution is it easy as described in the docs, during my update - i missed the installation of openhab-js as the addon, thats the fault why all my rules not able to run - now the system works as expected.

Again thank you for your patience!