Whenever I restart my Pi, I get error messages for some timers in the logs that say:
“PT2M” is an unsupported type for conversion to time.ZonedDateTime
at toZDT (/openhab/conf/automation/js/node_modules/openhab/time.js:281)
at check (/openhab/conf/automation/js/node_modules/openhab_rules_tools/timerMgr.js:46)
at execute (heating_OpenWindowSensing.js:111)
at execute (@openhab-globals.js:2))
If I edit the rule and make any change, even just adding an empty line, and save it, it will work again as expected.
Are you using the built in helper library or have you installed the helper library manually using npm.
Which version of the helper library and openhab_rules_tools library? You should be able to tell by looking at the package.json file or, if both are recent enough you can get both printed to the log using:
var {helpers} = require('openhab_rules_tools');
console.info(utils.OPENHAB_JS_VERSION);
console.info(OHRT_VERSION);
If that doesn’t work, you are running rather old versions of one or both. I believe the latest version of the helper library is 4.4.0 and the latest version of OHRT is 2.0.2.
Every time you restart or only sometimes?
How are these rules triggered?
File based or UI based rules?
Ultimately the problem is that it’s not recognizing the string “PT2M” as a standard ISO8601 duration string. It is valid so something weird is going on (this has been supported basically since time.toZDT() was written.
One good thing to try is to make sure you are running with the latest of both libraries to see if the problem persists. If you are using an older version of the helper library installed through npm you can change the settings of the JS Scripting addon to use the built in version instead as that one should be relatively recent (4.2.0 I think for M3).
It would also be informative to know if this is also a problem in OH 4.0 M4.
from the /conf/automation/js/node_modules/openhab_rules_tools folder. It looked like something was successful, but I still get the same error when checking the OHRT version.
npm is such a pain sometimes. The latest version is 2.0.2 of OHRT. But npm won’t automatically upgrade major version numbers like that.
It might work to change the version number in package.json to “^2.0.2” and then run the upgrade. If that doesn’t work, use npm uninstall openhab_rules_tools, double check that the line is removed from package.json, then reinstall.
That last bit should also tell you how to remove openhab-js.
Error: "PT15M0.000178329S" is an unsupported type for conversion to time.ZonedDateTime
at toZDT (/node_modules/openhab.js:2)
at check (/openhab/conf/automation/js/node_modules/openhab_rules_tools/timerMgr.js:46)
at execute (lights_sensorDetection.js:170)
at doExecute (@openhab-globals.js:2)
Hmmm, it should work with a time.Duration class too. Post your full code around the call to check() on timer manager. I tried the following code and it works for me.
var {helpers, timerMgr} = require('openhab_rules_tools');
console.info('Running scratchpad.');
console.info('openhab-js version: ' + utils.OPENHAB_JS_VERSION);
console.info('OHRT version: ' + helpers.OHRT_VERSION);
var tm = new timerMgr.TimerMgr();
var dur = time.Duration.ofMinutes(1);
tm.check('scratchpad', dur, () => { console.info('Timer'); });
var { timerMgr } = require('openhab_rules_tools');
let manager = cache.private.get('openWindowsTimerMgr', () => new timerMgr.TimerMgr());
let radiatorName = event.itemName.replace('_Radiator_AssociatedContactSensors', '')
let deBounce = 'deBounce_' + radiatorName;
const Heating_Debounce = items.Heating_Debounce // a number item
const deBounceDuration = time.Duration.ofMinutes(Heating_Debounce.numericState).toString() // the toString() is the bit that makes it work for me
manager.check(deBounce, deBounceDuration, checkOpenings, true)
It doesn’t address the root problem, but there is a Debounce rule template. You may not need this rule at all.
It’s really weird that the Duration is resolving to PT15M0.000178329S. What state is Heating_Debounce? I’d expect it to be an integer, not a float. In particular, when the error occurs what’s the state of that Item and what does the error message say the Duration became?