Javascript not working as expected since 5.1.0

Below is a snippet of a script that was working fine for ages up to openhab 5.0.3:

var kwMinute
var frkwMinute
var srvkwMinute
var hasTickedMinutes

if (isNaN(kwMinute)) {
  console.log("PC Power Measure starting");
  kwMinute = 0;
  frkwMinute = 0;
  srvkwMinute = 0;
  hasTickedMinutes = false
  }

[...]

This script is called every 5 seconds from a rule. Before the upgrade all variables kept their values between each consecutive run and the code after the if-statement would have been run only once to initialize them. Later in the script, those values are used on each run to update (add to) item values but now they’re always zero. I left the rest of the code out because it’s not relevant to showcase the problem.

After the upgrade to 5.1.0 the code within the if-statement is run every 5 seconds. I assume it’s because “kwMinute” is not keeping its value from previous runs and is now NAN every time.

I have no idea which of the changelog entries regarding javascript is responsible for this change nor how to fix it. Any help would be appreciated.

Thanks!

Hi,
5.1.0.M2, JS does not store any data ?

5.1 no longer persists every item by default you have to explicitly enable that.
Read the breaking changes section of the relnotes.

Use the private cache and store the values there, see JavaScript Scripting - Automation | openHAB.

Storing variable values between multiple runs of script actions or script conditions was never expected to work, I wonder why it did.