That might be the difference.
From scratchpad can you run the following line and let me know what version you are running with?
console.info('openhab-js version: ' + utils.OPENHAB_JS_VERSION);
console.info('OHRT version: ' + helpers.OHRT_VERSION);
That might be the difference.
From scratchpad can you run the following line and let me know what version you are running with?
console.info('openhab-js version: ' + utils.OPENHAB_JS_VERSION);
console.info('OHRT version: ' + helpers.OHRT_VERSION);
openhab-js version: 5.11.3
I donāt have the helpers libraryā¦
Yes you do if you are using this rule template. It heavily depends on OHRT to function and it would definitely not work if it is not there.
But I forgot to include the import ion my code above. My bad.
var {helpers} = require('openhab_rules_tools');
console.info('openhab-js version: ' + utils.OPENHAB_JS_VERSION);
console.info('OHRT version: ' + helpers.OHRT_VERSION);
Note, openHABian installs and updates both of these when asked to do so.
But the whole issue is probably irrelevant. Iām running with openab-js 5.11.3 too.
I need to try to reprocude this error. So far Iāve no been able to.
15:20:27.251[INFO] [org.openhab.automation.script.ui.scratchpad] - openhab-js version: 5.11.3
15:20:27.251[INFO] [org.openhab.automation.script.ui.scratchpad] - OHRT version: 2.1.0
OK, Iāve been able to reproduce the error. Progressā¦
I found the error. I think that has already been fixed but I donāt think was backported to OH 5.0.1, or if it was it wonāt be there until 5.0.2.
The problem was openhab-js was changed to throw an exception when calling items.MyItem.quantityState instead of returning null. I fixed the code of the template in one place but didnāt in the init() function.
Verison 1.5 should not work whether calling quantityState throws and exception or returns null. That should keep it compatable even for openhab-js 5.3.11 and versions before and going forward.
Remove the template, re-add it. Then find all your rules based on the template, select them and regenerate. All your previous settings will be preserved.
Cool thx!
Do you know if I can assign templates to rules that were generated prior to OH5? I would like to use the regenerate feature but all rules created prior to OH5 donāt āknowā they are template rules ā¦
Unfortunately not, at least there is no way I know of. Youāll have to recreate those rules.
If you click on the code tab for the rule, your original configuration settings will be listed at the top. What I did was copy that section of the rule to text editor, disabled the rule. Then recreated the rule using the config in the text editor to remind me what settings to make. Once tested and shown to work I deleted the old rule.
Thankfully, this only has to be done the one time. After that the regenerate feature will work. I just upgraded all six of the instances I run of this template in one go and it worked like a charm. Itās definitely worth the effort.
Note an additional benefit is if you regenerate just one rule, you have the opportunity to change the parameters. This can greatly speed up dialing in the setting for a complicated rule template like this one.
Iām using the threshold alert to create a Health Check for sensors and it works like charm for a single item. now Iād like to create different actions depending on the sensor that fails. unfortunately the script fails:
console.debug('Sensor status proc called with Item ' + alertItem + ', state ' + alertState + ' initialAlert ' + isInitialAlert + ' and alerting ' + isAlerting);
if(isInitialAlert) {
// you might want to add some book keeping to only call if the alert was sent
actions.NotificationAction.hideNotificationByTag("xxxxxx@gmx.at", alertItem);
console.info('Sensor ' + alertItem + ' is back online!')
}
else {
console.info('Sensor ' + alertItem + ' has stopped reporting, updating the Item to UNDEF');
// send alert here
if (alertItem == "PV_Test") {
actions.NotificationAction.sendNotification("m.xxxxxx@gmx.at", "Huawei Dongle not reachable:", "information", alertItem, "rebooting Network switch", null, null, null, null, null, null);
}
else if (alertItem == "Boiler_Temperatur_Mitte") {
actions.NotificationAction.sendNotification("m.xxxxxx@gmx.at", "Boiler Sensor:", "information", alertItem, "manually reboot sonoff Heizraum", null, null, null, null, null, null);
}
const update = (alertItem) => {
return () => {
items[alertItem].postUpdate('UNDEF');
}
}
setTimeout(update(alertItem), 250); // helps avoid multi-threaded exceptions.
}
the error beeing logged:
Level
ERROR
Logger Class
org.openhab.automation.rules_tools.Threshold Alert.rule_monsens.Boiler_Temperatur_Mitte
Message
Error running rule script_monsens TypeError: null has no such function "toString"
what am I missing here? the rule looks too simple to fail�
The error is being generated before the code in script_monsens gets executed so the error has to come from the threshold alert rule itself.
First run the threshold alert rule manually to ensure everything is configured correctly. Then put the rule into debug level logging and post a full set of logs for one Item that generates the error from the threshold alert rule.
Use code fences and if possible use the one log per line format.
thanks for your assistance Rick!
I enabled rule logging:
openhab> log:set DEBUG org.openhab.automation.script.ui.rule_monsens
the strange thing is that a single alert always works as expected. if a second item fails, the alert fails. a successful item alert looks like this:
20:53:46.948[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock acquired before timer execution
20:53:46.986[INFO] [org.openhab.automation.script.ui.script_monsens] - Sensor PV_Test has stopped reporting, updating the Item to UNDEF
20:53:46.989[DEBUG] [org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine] - Lock released.
20:53:46.997[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock released after timer execution
20:53:47.237[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock acquired before timer execution
20:53:47.238[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock released after timer execution
20:53:47.239[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock acquired before timeout execution
20:53:47.241[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock released after timeout execution
20:53:47.243[INFO] [openhab.event.ItemStateChangedEvent] - Item 'PV_Test' changed from -2527 W to UNDEF
20:53:47.256[DEBUG] [org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine] - Lock released.
an unsucessful alert looks like this:
20:54:49.681[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock acquired before timer execution
20:54:49.697[ERROR] [org.openhab.automation.rules_tools.Threshold Alert.rule_monsens.Buderus_Test] - Error running rule script_monsens TypeError: null has no such function "toString"
20:54:49.702[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock released after timer execution
20:54:49.948[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock acquired before timer execution
20:54:49.949[DEBUG] [org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers] - Lock released after timer execution
if I manually run the rule I receive these logs:
21:02:57.112[ERROR] [org.openhab.core.automation.module.script.internal.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'rule_monsens' failed: TypeError: undefined has no such function "toString" in at line number 938 at column number 13
21:02:57.113[DEBUG] [org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine] - Lock released.
No, like I said, the error is before rule_mosens even runs. Those logs will tell me nothing. I need the logs from the Threshold Alert rule.
org.openhab.automation.rules_tools.Threshold Alert.rule_monsens
You need to manually run the Threshold Alert rule, not the rule called by the threshold alert rule.
the threshold alert rule is rule_monsens. the script called by this rule is script_monsens.
how to enable rule logging when thereās a space in its name?
openhab> log:set DEBUG org.openhab.automation.rules_tools.Threshold Alert.rule_monsens
Error executing command log:set: too many arguments specified