Script execution of rule with UID ‘e70053bcbc’ failed: TypeError: null has no such function “until” in @openhab-globals.js at line number 2 at column number 79926
I don’t think the error has anything to do with persistence. It’s coming from the helper library before your rule even runs.
Do you have more than two options under Settings → JS Scripting for “Variable injection”? If so, try changing that option (e.g to “Auto injection for UI based rules and transformations”), and then open and save the rule generating the error. Does that seem to help?
If you only have two options there I’m not sure what else to try. Maybe just saving the rule to regenerate it will help?
Please avoid posting screen shots unless absolutely necessary. They are impossible to read on a small screen, cannot be searched or copied from, and often they cut off important information. Text is always better. When posting a rule, click on the code tab. The log reader has a “show logs as plain text” button a the bottom.
Use code fences like you did with the JS.
Anyway, I suspect the problem is with the call to previousState. If the current state of the Item is different from the most recent entry in the database, persistence returns null because it can’t actually know what the previous state was and more importantly when the previous state occurred. That means the code is trying to find the minutes between null and now and that’s throwing an error. The fact that it happens at 60 minutes I suspect might be a fluke of the timing. What’s triggering this rule?
The good news is you don’t need persistence for this anyway. The Item keeps track of the last change and last update itself without needing persistence. Use the get [name] of item block and select “last state change” which will be the timestamp from when the Item last changed states.
It’s working without problems for me too, as long as I use the example above.
I have already changed my code to only use this option.
My question remains: why, among 3 options for calculating the time between minutes, only one of them works after the counter reaches more than 60 minutes?
In any case, we managed to discover an option that always works and this is very important.