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
Stopped OH3
Removed java11 and installed zulu java17
Changed the apt source file from stable to testing
upgraded to openhab 4.0.0.M4
Started OH4
Installed Nashorn addon
Stopped OH4
removed javascript entry from /var/lib/openhab/config/org/openhab/addons.config as I was getting javascript warnings and it was being ignored.
Removed javascript transformation using the openhab console:
openha-cli console
config:edit org.openhab.addons
config:property-list
config:property-set transformation regex,jsonpath
config:property-list
config:update
Cleared the cache: sudo openhab-cli clean-cache
Started OH4
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.
NOTE: I have found if I go to the rule and open it and then and change the display from design to code (top right hand corner) and change: type: application/javascript to type: application/javascript;version=ECMAScript-5.1
IT WORKS!!!
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.
What does the upgradetool.jar change in the database if it doesn’t change type: application/javascript to type: application/javascript;version=ECMAScript-5.1 ?
ALSO NOTE: when I start typing type: application/javascript;version it auto completes to type: application/javascript;version=ECMAScript-5.1
Which JavaScript entry? There could be up to three entries: transformation, Nashorn and GraalVM JS Scriptings addons
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?
I used the mainui to install Nashorn addon.
The javascript remove was because it was getting warning saying it was being ignored. found it here: OH4 install issues
Am I seeing all of these problems because I am upgrading from 3.4.4 to 4.0.0.M4 and other people are gradually upgrading via milestones? EG going from M1-M2-M3-M4?
I am using a VM and have snapshot so I can go back to 3.4 and try different ways to install.
I will persist and see how I go.
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.
Ok, so it has an ItemStateUpdate trigger, that’s good. But it’s it the actual Item remotsonytv that’s trying the rule of is your widget running the rule directly?
It matters because event.itemState will exist in the former but not in the later.
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
“type”: “application/javascript;version=ECMAScript-5.1” in it but the rules run without having that in the file.
No, there is currently no task for the upgrade tool to do that. I’ve completely forgotten that, and won‘t make it till the feature freeze on Sunday. I can probably open a PR before the code freeze.
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.
Auto-load of Nashorn sounds like a good idea.
If the install of java 17 as well would make it a true upgrade.
If it just worked after upgrading that would be the best.