OH3: rule to fast for changing item?

Check here for all available event properties:

https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Event%20Object%20Attributes.html

I use this as my template rule script:

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var NotificationAction = org.openhab.io.openhabcloud.NotificationAction;
var ScriptExecution = Java.type("org.openhab.core.model.script.actions.ScriptExecution");
var ZonedDateTime = Java.type("java.time.ZonedDateTime");

this.myVar = (this.myVar === undefined) ? "whatever": this.myVar;
this.myTimer = (this.mytimer === undefined) ? null: this.myTimer;

//logger.info("event: " + this.event);
//NotificationAction.sendNotification("my@email.tld","Message");
//NotificationAction.sendBroadcastNotification("Message");

/*
this.myTimer = ScriptExecution.createTimer(ZonedDateTime.now().plusMinutes(1), function(){
                  // do something
                  this.myTimer = null;
                });
*/

if((typeof this.event) == 'undefined'){
  //cron event?

}else{
  if(this.event.itemName !== undefined){
    //multiple triggers ?
    switch(this.event.itemName.toString()){
      case 'myItem':
        //command
        if(this.event.itemCommand !== undefined){
          //do something
        }
        //update
        if(this.event.itemState !== undefined){
          //do something
        }
        break;
    }
  }
  if(this.event.channel !== undefined){
    //multiple triggering channels?
    switch(this.event.channel.toString()){
      case 'TriggeringChannel':
        //do something
        // 'value' is available in this.event.this.event
        break;
  }
}

this.event = undefined;
2 Likes