I am trying out the OH4 milestone 4.0.0.M4 and the rules don’t work because they are version 5.1 rules.
This is what I have done:
OH 3.4.4 installed and up and running with zulu java11
Removed java11 and installed zulu java17
Changed the apt source file from stable to testing
upgraded to openhab 4.0.0.M4
Installed Nashorn addon
config:property-set transformation regex,jsonpath
Cleared the cache: sudo openhab-cli clean-cache
When any old rules run I get this:
023-07-07 14:39:19.403 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘40ceac6bd4’ failed: org.graalvm.polyglot.PolyglotException: ReferenceError: “itemRegistry” is not defined
I stopped OH4 and ran the upgradetool.jar: java -jar $OPENHAB_RUNTIME/bin/upgradetool.jar --force
Started OH4 again and same thing.
Because I have lots of rules then going through and changing every rule is going to take a while.
Is there a way to change this in the /var/lib/openhab/jsondb/automation_rules.json
I did do a test and changed it manually using vim and I had to edit the automation_rules.json if I wanted the scripts to work as the script doesn’t have the design / code tab.
Was there anything logged related to rules when the tool ran?
The upgrade tool should have happened. However, if you were to need to change these manually, stop OH, open $OH_USERDATA/jsondb/automation_rules.json with a text editor and use find and replace. You could do them all in one go that way.
There is a growing list of breaking changes that the upgrade tool implements for managed configs including dealing with the changes to unit handling, changes to Things syntax, etc.
I think that the change of the mime type was included in the upgrade tool but an not certain. I moved to OH 4 on day one and had to manually do everything because an upgrade tool didn’t exist yet. @florian-h05, IIRC you did at least a little work on this, though maybe that was only concerning Blockly. Are the mime types for Nashorn rules supposed to be changed through the upgrade process, either through the tool or some other way?
Started OH4 and most of the rules seem to work now.
This line of code doesn’t work:
var stateof = event.itemState.toString() ;
I am getting a lot of these warnings but I had these before the above changes.
[2023-07-08 09:13:51.262 [WARN ] [.core.io.rest.internal.DTOMapperImpl] - Field 'firmwareStatus' could not be eliminated: Can not set final org.openhab.core.thing.firmware.dto.FirmwareStatusDTO field org.openhab.core.io.rest.core.thing.EnrichedThingDTO.firmwareStatus to null value
2023-07-08 09:13:51.267 [WARN ] [.core.io.rest.internal.DTOMapperImpl] - Field 'firmwareStatus' could not be eliminated: Can not set final org.openhab.core.thing.firmware.dto.FirmwareStatusDTO field org.openhab.core.io.rest.core.thing.EnrichedThingDTO.firmwareStatus to null value
I doubt it. Others have done similar upgrades without the problem. However, few users willing to run testing versions of OH are still using Nashorn JS. Must have moved to the more modern JS Scripting or Blockly.
Another observation with the openHAB 4.0.0 (build Build #3531) is the scripts don’t work if the automation_rules.json hasn’t been edited to have the
I’m willing to go to bat and argue that it will be really bad if we don’t have that in OH 4 release. In my opinion it would be worth a day or two delay compared to the masses of people who will get caught up by this.