Threshold Alert and Open Reminder [4.0.0.0;5.9.9.9]

No, I made the code detect which version of the helper library is running and use the right property on the event object. If I just change everything out, the template would only work for Oh 5.1+. As currently implemented it works for OH 4.0+.

This is something that’s updated automatically when upgrading to a next version of OH, right?

It depends. The helper library can be installed separately. If that’s the case, it’s not updated automatically.

And how could I check whether that’s the case in my setup?

Have you ever installed it separately? This doesn’t happen accidnetally no automatically. You have to take an action to cause it to install.

This is done from the command line or through openhabian-config.
automation

Do you have /etc/openhab/automation/js/node-modules/openhab ?

Did you change the settings for the add-on to disable “Cache openHAB JavaScript Library Injection”? If the answer to all of these is no then you are running with the version that comes with the add-on.

There are lots of manual actions I undertake when trying out solutions offered on the forum (or the internet in general). So no idea


More or less (it’s an underscore ;)):

erik@MinipcLG2:/etc/openhab/automation/js/node_modules$ ls -pal
totaal 16
drwxr-xr-x 3 openhab openhab 4096 mei 29  2024 ./
drwxr-xr-x 3 openhab openhab 4096 dec 27 18:19 ../
drwxr-xr-x 4 openhab openhab 4096 mei 29  2024 openhab_rules_tools/
-rw-r--r-- 1 root    root     375 aug 28  2024 .package-lock.json


So since I have that folder, I’m running a manual installation?

No, you don’t have that folder. You have openHAB_rules_tools but that’s something else. You are running with the library that comes with the add-on.

I still struggle to enable logging for the “Threshold Alert” rules.

in OC console for “list -s” I do not see anything relating to the rules_tools

openhab> list -s | grep automation
162 │ Active │  80 │ 5.0.3                 │ org.openhab.core.automation
163 │ Active │  80 │ 5.0.3                 │ org.openhab.core.automation.module.media
164 │ Active │  80 │ 5.0.3                 │ org.openhab.core.automation.module.script
165 │ Active │  80 │ 5.0.3                 │ org.openhab.core.automation.module.script.providersupport
166 │ Active │  80 │ 5.0.3                 │ org.openhab.core.automation.module.script.rulesupport
167 │ Active │  80 │ 5.0.3                 │ org.openhab.core.automation.rest
379 │ Active │  80 │ 5.0.3                 │ org.openhab.automation.jsscripting
openhab>

openhab> list -s | grep rules_tools
openhab>

I did re-install the rules-tools from openhabian and created new rules. but I do not see the logger name in the list and can’t enable debugging on the rule. the log-viewer cog icon does not list it either.

You wouldn’t. It;'s not an add-on. Karaf doesn’t know anything about it.

If you’ve never configured it before the logger name won’t show up. It inherits its logger from the higher up settings (e.g. org.openhab). There are literally tens of thousands of logger names in openHAB. You don’t want it to list each and every one.

But you can type the logger name in to add a specific configuration for it. The easiest thing to do would be:

  1. open the rule created from the template
  2. open the action of the rule
  3. copy the logger name from the top of the action up to the “Threshold Alert” part.
  4. open the log viewer, click the cog, and paste the logger name into the field that says “Add custom logger package entry”

You can also open the script action, uncomment the line that sets the level, run the rule once, then comment that line back out. You must not leave that line uncommented, or your whole logging config might get destroyed.

// osgi.getService('org.apache.karaf.log.core.LogService').setLevel(console.loggerName, 'DEBUG');

Or you can manually edit the log4j2.xml file and add a logger for the logger name copied from 3 above.

Or you can set the logger level in the karaf console using the logger name copied from 3 above.

thanks Rich, now I got the debug logs from the rule. when manually running the threshold rule “rule_monitorsensors” I receive these 3 lines of logs. is this giving a hint what could be wrong?

15:27:57.568[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Starting threshold alert
15:27:57.569[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Running without event wrapper
15:27:57.570[ERROR] [org.openhab.core.automation.module.script.internal.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'rule_monitorsensors' failed: TypeError: undefined has no such function "toString" in at line number 938 at column number 13

Are you running the latest version of the rule? What are your JavaScript Scripting settings for the wrapper and event object conversion?

I’m not able to reproduce this error. We need to find what’s different between my instance and yours.

I’m running OH 5.11.3 with OHRT 2.1.0. I did reinstall JS and the rules-tools a couple of times and tried both ways via openhabian and the OH add-on store.

these are my JS scripting settings, but I can’t figure out where to find settings for wrappers and conversions.

I mean which version of the rule template? There is a comment that’s the top line of the script action with the version of the template.

It should read

// Version 1.7

If it reads anything else, or that comment isn’t there you are running an outdated version of the template. You must reinstall the template and regenerate the rule(s).

There is no such version of OH. Do you mean 5.0.3 or 5.1.0?

Click “Show advanced” assuming you are on OH 5.1. If you are still on OH 5.0 these settings won’t be there.

sorry, I meant OPENHAB_JS_VERSION is on 5.11.3.

openHAB 5.0.3 - Release Build

openhab-rules // Version 1.7

and so there is no “show advanced”

OK, so the wrapper isn’t available in 5.0.

I don’t have a 5.0 instance to test with.

Please replace the code at the bottom of the script action with this:

//~~~~~~~~~~~~~ Body
// If triggered by anything other than an Item event, check the config
// Otherwise process the event to see if alerting is required
if(this.event === undefined || event.eventName == "ExecutionEvent") {
  console.debug('Rule triggered without an event, checking config.');
  init();
}
else {
  let name = event.itemName;
  let type;
  let wrapper;
  if(event.newState === undefined && event.receivedState === undefined){
    console.debug('Running without event wrapper');
    type = event.type.toString();
    wrapper = false;    
  } 
  else {
    console.debug('Running with event wrapper');
    type = event.eventName;
    wrapper = true;
  }
  switch(type) {
    case 'ItemStateEvent':
    case 'ItemStateUpdatedEvent':
    case 'ItemStateChangedEvent':
      let state;
      if(wrapper) {
        state = (event.newState !== undefined) ? event.newState : event.receivedState;
      }
      else {
        state = event.itemState.toString();
      }
      console.loggerName = loggerBase+'.'+name;
      console.debug('Processing an Item event');
      procEvent(name, stateToValue(state));
      break;
    default:
      console.info('Rule triggered without an Item event, ' + type + ' checking the rule config');
      init();
  }
}

this code change looks promising. manually starting the rule runs without errors now:

Summary
20:34:13.411[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Starting threshold alert
20:34:13.412[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Running without event wrapper
20:34:13.413[INFO] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Rule triggered without an Item event, ExecutionEvent checking the rule config
20:34:13.415[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Rule config defaults: Group - gMonitoringSensor Threhsold - UnDefType Operator - == Invert Operator - true Reschedule - true Default Alert Delay - Default Reminder Duration - DND Start - 00:00 DND End - 00:00 Alert Rule - script_monitorsensors End Alert Rule - Alert Group - gMonitoringSensor Alert Items - Buderus_Test, PV_Test, Boiler_Temperatur_Mitte Gatekeeper Delay - 0 Rate Limit -
20:34:13.416[INFO] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Cancelling any running timers
20:34:13.420[INFO] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Buderus_Test has an alert timer scheduled, cancelling now.
20:34:13.421[INFO] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Threshold is UnDefType, this will cause Item states of NULL and UNDEF to be converted to UnDefType for comparisons.
20:34:13.422[INFO] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Items without SensorHC alertDelay metadata will alert immediately
20:34:13.423[INFO] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Items without SensorHC remPeriod metadata will not repeat alerts
20:34:13.429[INFO] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - No end alert rule configured, no rule will be called when alerting ends
20:34:13.436[INFO] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - These Items do not have SensorHC metadata and will use the default properties defined in the rule: Boiler_Temperatur_Mitte
20:34:13.447[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Metadata for Item Buderus_Test alertDelay: PT15M
20:34:13.450[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Metadata for Item PV_Test alertDelay: PT2M
20:34:13.450[INFO] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Threshold Alert configs check out as OK

the first time a sensor fails, the rule successfully triggers an alert, no error message here:

Summary

20:39:36.579[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state -2837 W of type string
20:39:36.580[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a string: -2837 W
20:39:36.581[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a Quantity: -2837 W
20:39:36.582[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Populating record from Item metadata or rule defauls
20:39:36.600[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Converting threshold to value
20:39:36.600[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state UnDefType of type string
20:39:36.601[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a string: UnDefType
20:39:36.601[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is an undef type, normalizing to UnDefType
20:39:36.602[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Converting hysteresis to value
20:39:36.602[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state of type string
20:39:36.603[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a string:
20:39:36.603[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is the empty string, no conversion possible
20:39:36.603[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing event for Item PV_Test with properties: Threshold - UnDefType Operator - == Invert - true Reschedule - true Alert Delay - PT2M Reminder Period - Alert Rule ID - script_monitorsensors End Alert Rule ID - Init Alert Rule ID - script_monitorsensors Gatekeeper Delay - 0 Hystersis - Rate Limt - DnD Start - 00:00 DnD End - 00:00
20:39:36.604[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Alert timer expired for PV_Test with dnd between 00:00 and 00:00 and reminder period
20:39:36.604[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Timeout is not valid, using null
20:39:36.605[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Checking if we are in the alerting state: !(-2837 W == UnDefType)
20:39:36.605[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Result is true
20:39:36.606[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - PV_Test is still in an alerting state.
20:39:36.606[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Calling script_monitorsensors with alertItem=PV_Test, alertState=-2837 W, isAlerting=true, and initial alert false
20:39:36.613[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state -10.1 °C of type string
20:39:36.614[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a string: -10.1 °C
20:39:36.614[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a Quantity: -10.1 °C
20:39:36.614[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Checking if we are in the alerting state: !(-10.1 °C == UnDefType)
20:39:36.615[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Result is true
20:39:36.615[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state -2837 W of type string
20:39:36.615[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a string: -2837 W
20:39:36.615[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a Quantity: -2837 W
20:39:36.616[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Checking if we are in the alerting state: !(-2837 W == UnDefType)
20:39:36.616[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Result is true
20:39:36.616[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state 39.1 °C of type string
20:39:36.617[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a string: 39.1 °C
20:39:36.617[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a Quantity: 39.1 °C
20:39:36.617[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Checking if we are in the alerting state: !(39.1 °C == UnDefType)
20:39:36.618[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Result is true
20:39:36.619[INFO] [org.openhab.automation.script.ui.script_monitorsensors] - Sensor PV_Test has stopped reporting, updating the Item to UNDEF
20:39:36.621[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Rule script_monitorsensors has been called for PV_Test
20:39:36.625[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Waiting until null to send reminder for PV_Test
20:39:36.874[INFO] [openhab.event.ItemStateChangedEvent] - Item ‘PV_Test’ changed from -2837 W to UNDEF
20:39:36.890[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Starting threshold alert
20:39:36.891[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Running without event wrapper
20:39:36.892[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing an Item event
20:39:36.892[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state UNDEF of type string
20:39:36.893[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a string: UNDEF
20:39:36.893[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is an undef type, normalizing to UnDefType
20:39:36.894[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state UnDefType from PV_Test
20:39:36.894[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Populating record from Item metadata or rule defauls
20:39:36.908[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Converting threshold to value
20:39:36.908[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state UnDefType of type string
20:39:36.908[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a string: UnDefType
20:39:36.909[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is an undef type, normalizing to UnDefType
20:39:36.909[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Converting hysteresis to value
20:39:36.909[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing state of type string
20:39:36.909[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is a string:
20:39:36.910[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - state is the empty string, no conversion possible
20:39:36.910[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Processing event for Item PV_Test with properties: Threshold - UnDefType Operator - == Invert - true Reschedule - true Alert Delay - PT2M Reminder Period - Alert Rule ID - script_monitorsensors End Alert Rule ID - Init Alert Rule ID - script_monitorsensors Gatekeeper Delay - 0 Hystersis - Rate Limt - DnD Start - 00:00 DnD End - 00:00
20:39:36.910[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Checking if we are in the alerting state: !(UnDefType == UnDefType)
20:39:36.910[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Result is false
20:39:36.910[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - PV_Test’s new state is UnDefType which is no longer in the alerting state, previously alerted = true
20:39:36.911[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Applying hysteresis with: curr = UnDefType, alert = UnDefType, hyst =
20:39:36.911[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - Not all values are compatible, skipping hysteresis
20:39:36.911[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.PV_Test] - No end alert rule is configured, exiting alerting for PV_Test

and when this sensor comes back, it is successfully processed as well.

unfortunately, if the sensor fails, and another one fails after that, the rule fails again with the toString error: see timestamp 20:57:14.919[ERROR]

Summary
20:57:14.780[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Starting threshold alert
20:57:14.780[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors] - Running without event wrapper
20:57:14.781[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing an Item event
20:57:14.781[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state 39 °C of type string
20:57:14.782[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a string: 39 °C
20:57:14.782[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a Quantity: 39 °C
20:57:14.783[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state 39 °C from Boiler_Temperatur_Mitte
20:57:14.784[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Populating record from Item metadata or rule defauls
20:57:14.791[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Converting threshold to value
20:57:14.791[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state UnDefType of type string
20:57:14.791[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a string: UnDefType
20:57:14.792[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is an undef type, normalizing to UnDefType
20:57:14.792[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Converting hysteresis to value
20:57:14.792[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state of type string
20:57:14.792[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a string:
20:57:14.792[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is the empty string, no conversion possible
20:57:14.793[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing event for Item Boiler_Temperatur_Mitte with properties: Threshold - UnDefType Operator - == Invert - true Reschedule - true Alert Delay - Reminder Period - Alert Rule ID - script_monitorsensors End Alert Rule ID - Init Alert Rule ID - script_monitorsensors Gatekeeper Delay - 0 Hystersis - Rate Limt - DnD Start - 00:00 DnD End - 00:00
20:57:14.793[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Checking if we are in the alerting state: !(39 °C == UnDefType)
20:57:14.793[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Result is true
20:57:14.793[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Boiler_Temperatur_Mitte is in the alert state of 39 °C
20:57:14.794[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Timeout is not valid, using null
20:57:14.794[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Calling the initial alert rule for Boiler_Temperatur_Mitte
20:57:14.804[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Creating looping alert timer for Boiler_Temperatur_Mitte at PT0S
20:57:14.905[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Calling init alert rule for Boiler_Temperatur_Mitte
20:57:14.907[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Calling script_monitorsensors with alertItem=Boiler_Temperatur_Mitte, alertState=39 °C, isAlerting=false, and initial alert true
20:57:14.915[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state -10.1 °C of type string
20:57:14.915[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a string: -10.1 °C
20:57:14.915[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a Quantity: -10.1 °C
20:57:14.916[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Checking if we are in the alerting state: !(-10.1 °C == UnDefType)
20:57:14.916[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Result is true
20:57:14.917[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state null of type object
20:57:14.917[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is not a String, converting to a String.
20:57:14.919[ERROR] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Error running rule script_monitorsensors TypeError: null has no such function "toString"
20:57:14.919[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Rule script_monitorsensors has been called for Boiler_Temperatur_Mitte
20:57:14.927[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state 39 °C of type string
20:57:14.927[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a string: 39 °C
20:57:14.927[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a Quantity: 39 °C
20:57:14.927[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Populating record from Item metadata or rule defauls
20:57:14.930[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Converting threshold to value
20:57:14.930[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state UnDefType of type string
20:57:14.930[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a string: UnDefType
20:57:14.930[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is an undef type, normalizing to UnDefType
20:57:14.930[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Converting hysteresis to value
20:57:14.931[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state of type string
20:57:14.931[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a string:
20:57:14.931[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is the empty string, no conversion possible
20:57:14.931[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing event for Item Boiler_Temperatur_Mitte with properties: Threshold - UnDefType Operator - == Invert - true Reschedule - true Alert Delay - Reminder Period - Alert Rule ID - script_monitorsensors End Alert Rule ID - Init Alert Rule ID - script_monitorsensors Gatekeeper Delay - 0 Hystersis - Rate Limt - DnD Start - 00:00 DnD End - 00:00
20:57:14.931[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Alert timer expired for Boiler_Temperatur_Mitte with dnd between 00:00 and 00:00 and reminder period
20:57:14.931[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Timeout is not valid, using null
20:57:14.931[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Checking if we are in the alerting state: !(39 °C == UnDefType)
20:57:14.931[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Result is true
20:57:14.931[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Boiler_Temperatur_Mitte is still in an alerting state.
20:57:14.932[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Calling script_monitorsensors with alertItem=Boiler_Temperatur_Mitte, alertState=39 °C, isAlerting=true, and initial alert false
20:57:14.933[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Waiting until null to send reminder for Boiler_Temperatur_Mitte
20:57:15.029[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state -10.1 °C of type string
20:57:15.031[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a string: -10.1 °C
20:57:15.032[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is a Quantity: -10.1 °C
20:57:15.033[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Checking if we are in the alerting state: !(-10.1 °C == UnDefType)
20:57:15.034[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Result is true
20:57:15.034[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Processing state null of type object
20:57:15.035[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - state is not a String, converting to a String.
20:57:15.037[ERROR] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Error running rule script_monitorsensors TypeError: null has no such function "toString"
20:57:15.038[DEBUG] [org.openhab.automation.rules_tools.Threshold Alert.rule_monitorsensors.Boiler_Temperatur_Mitte] - Rule script_monitorsensors has been called for Boiler_Temperatur_Mitte

That’s a different error in a different place for a different reason. Unfortunately, it doesn’t tell me the line this time. It will take a little it of time to trace it and figure out why it failed, namely why it’s trying to convert null to a String.

For some reason my instance of the rule is throwing errors related to duration parsing - I don’t use the durations but even when I set them they keep throwing:

[.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'c2acc16246' failed: Error: Error: Failed to parse string : DateTimeParseException: Text cannot be parsed to a Duration: , at index: 0

Any help to guide me where to look in the code?
I’m on OpenHAB 5.2 with version 1.7 of the template. Manually triggering says everything is okay, it only happens when the actual humidity changes to trigger it.

Apparently, dndStart and dndEnd need a value, even when you don’t use them as in ‘generateAlertTime’ it will error out otherwise

They should be defaulted to empty string. But if you fill them in and then remove them something might go wrong. I’ll take a look at this when I have time.

Hey @rlkoshak, hope you’re well!

I ran into an issue with the Threshold Alert template after OpenHAB restarts. Since the rule only fires on GroupStateChangeTrigger, all state in cache.private is lost on restart and items that were alerting before the restart produce no new events. In practice: a dehumidifier that was running stays on forever because the end-alert rule never fires after the restart.

I put together a fix and tested it on my Pi 5 running 14 instances of the template. The change is insert-only (v1.8):

  • A SystemStartlevelTrigger so the rule gets a chance to run on startup
  • saveRecord/loadRecord helpers that persist alerted state to Item metadata (JSONDB — survives restarts, writes only on alert transitions)
  • A restoreAndReconcile() function that reads the persisted state and re-evaluates each group member on startup

PR here if you’d like to take a look: feat(thresholdAlert): persist alert state to Item metadata for restart recovery (v1.8) by Ltty · Pull Request #122 · rkoshak/openhab-rules-tools · GitHub

Happy to adjust anything based on your feedback!

Cheers,
Flo