Expiring items

You can configure Expire to only reschedule itself on changes. If the weather station goes offline, presumably the Item’s states are just being updated, not changing.


Just check “ignore state updates” and it will timeout the Item even if it’s continuing to be updated to the same value.

You’ll have to be careful to set a long enough expire so the Item doesn’t reset just because the weather isn’t changing that much.

An Item like that shouldn’t be in your model in the first place.

You should not put every Item into the model. Only those your end users will care about.

The easiest approach would be to just tell expire to ignore updates.

The next easiest would be to go down the path you are going now and write a JS transform that returns null if the timestamp in the message is too old. Chain that to your JSONPATH and the message will be thrown out entirely if it’s too old.

If you want an alert or want to take some sort of remedial action, use Threshold Alert and Open Reminder [4.0.0.0;4.9.9.9].

A rule can be configured from this template to call another rule you write if an Item remains the same value for too long a time. The rule you write can take remedial actions based on that fact (send an alert, turn something on/off, disable a Thing, etc).

I use one instance of this rule template to get an alert when a service goes offline, another when a sensor stops reporting, yet another for alerts when the doors are left open, another for when the humidity gets too low, another to drive the humidifiers, and another to get an alert when the motion sensor at my dad’s house doesn’t detection motion for too long a time.

The config I use that’s most relevant here is:

configuration:
  dndEnd: 08:00
  rateLimit: ""
  invert: true
  initAlertRule: new-sensor-status-proc
  dndStart: 22:00
  alertRule: new-sensor-status-proc
  endAlertRule: ""
  thresholdState: UnDefType
  defaultRemPeriod: ""
  operator: ==
  hysteresis: ""
  reschedule: true
  namespace: sensorStatus
  gkDelay: 250
  defaultAlertDelay: PT15M
  group: Sensors

The new-sensor-status-proc rule is as follows:

configuration: {}
triggers: []
conditions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: >
        var equipment = actions.Semantics.getEquipment(items[alertItem]);

        var statusItem = items[equipment.name+'_Status'];

        if(equipment === null || statusItem === null) {
          console.warn(alertItem + ' does not belong to an equipment or equipment doesn\'t have a Status Item!');
          false;
        }

        else {
          var statusItem = items[equipment.name+'_Status'];
          console.debug('Sensor status reporting called for ' + alertItem + ', equipment ' + equipment.label + ', is alerting ' + isAlerting + ', and is initial alert ' + isInitialAlert);
          // Sensor is back online                          Sensor went offline
          (isInitialAlert && statusItem.state == 'OFF') || (!isInitialAlert && statusItem.state != 'OFF');
        }
    type: script.ScriptCondition
actions:
  - inputs: {}
    id: "1"
    configuration:
      type: application/javascript
      script: >
        var {alerting} = require('rlk_personal');

        var logger = log('Sensor Alert');

        var equipment = actions.Semantics.getEquipment(items[alertItem]);

        var statusItem = items[equipment.name+'_Status'];


        if(!isInitialAlert && statusItem.state != 'OFF') {
          statusItem.postUpdate('OFF');
          alerting.sendAlert('Offline: ' + equipment.label + ' has stopped reporting', logger);
        }

        else if(isInitialAlert && statusItem.state != 'ON') {
          statusItem.postUpdate('ON');
          alerting.sendAlert('Online: ' + equipment.label + ' is back', logger);
        }
    type: script.ScriptAction

What it does is if an Item doesn’t change for 15 minutes it will call my alert rule. My alert rule pulls the Item’s semantic model, sends an alert and sets a status Item to OFF indicating the Equipment is offline. When the Item changes again, the rule is called again and the status Item is changed back to ON and an alert is sent indicating the Equipment is back online. Of course, there is a DND period so I don’t get these alerts at night.

1 Like