[SOLVED] One Line in Rule makes system die

Hello,

how can i make it easier, because in that way system reads this rule veeeery slow and then works very slow.

  message.append("opened time" + (((now.millis - new DateTime(doorLastChange.state.toString).millis)/1000).toString) + "")

doorLastChange has already Datetime format.

In other words i need to get the time in millis between Now and doorLastChange.

Thanks a lot!

Post the complete rule. What you posted is not valid Rules DSL syntax.

1 Like

I know, but onle this string makes system die, i posted only it to make it esier to understand. Please, here is complete

import org.eclipse.smarthome.model.script.ScriptServiceUtil

rule "Opened Doors Notification"
when
  Member of gDoorsSensorsTimer received command OFF
then
  val doorLastChange = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name.split("Timer").get(0) + "LastChange")
  val StringBuilder message = new StringBuilder
  message.append("opened time" + (((now.millis - new DateTime(doorLastChange.state.toString).millis)/1000).toString) + "")
  LogString.sendCommand(message) 
end 

Thanks!

Try this:

rule "Opened Doors Notification"
when
  Member of gDoorsSensorsTimer received command OFF
then
  val doorLastChange = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name.split("Timer").get(0) + "LastChange")
  val message = "opened time" + ((now.millis - new DateTime(doorLastChange.state.toString).millis)/1000).toString)
  LogString.sendCommand(message) 
end 
2 Likes

Thanks Vincent, now is ok!

But what it ther problem of StringBuilder in this case? I use it in the whole rule without any problems, but only this line.

For example this is the whole rule, where Sting Builder works ok for other lines of code


// The Expire binding will sendCommand OFF when the Timer expires
rule "Opened Doors Notification"
when
  Member of gDoorsSensorsTimer received command OFF
then

  val StringBuilder message = new StringBuilder

  val doorLastChange = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name.split("Timer").get(0) + "LastChange")

  val messages = "opened time" + (((now.millis - new DateTime(doorLastChange.state.toString).millis)/1000).toString)

  val openDoorsArray = gDoorsSensors.members.filter[ door | door.state == OPEN]
  openDoorsArray.forEach[door |  //select all the doors that have DoorSensor == OPEN
    //This here list can be put in item for future notifications
  ]
  val openDoorswithExpiredTimersArray = openDoorsArray.filter[ doorsWithExpiredTimers | ScriptServiceUtil.getItemRegistry.getItem(doorsWithExpiredTimers.name+"Timer").state == OFF ]
  if (openDoorswithExpiredTimersArray.size > 1) {
    message.append(" Also these ar opened: ")
  }

  openDoorswithExpiredTimersArray.forEach[doorsWithExpiredTimers, index | 

    if (doorsWithExpiredTimers.name != triggeringItem.name.split("Timer").get(0)) { //excludung already above selected door (triggered door)
          //message.append("index" + index)
          var doorName = transform("MAP", "sensors.map", doorsWithExpiredTimers.name)
          if (index == 0) {  // first element
            message.append(doorName)
          } else if(index == openDoorswithExpiredTimersArray.size-2) { // last element
            message.append(" и " + doorName + "")
          }
          else { // middle elements
            message.append(", " + doorName) 
          }     
   }
  ]
  
  message.append("." ) 
  LogString.sendCommand("<>" + messagePrefix + "<>" + message) 
 
end 

I don’t know to be honest. I don’t use it.