[ERROR] [untime.internal.engine.RuleEngineImpl] - Rule '<Rule Name>': 1

Hello, i am using openhab2. I am currently facing issue with my rule mentioned below.

rule "Water_Sensor"  
when   
Item Water_Status received update  
then  
val EPBUpdate = Water_Status.state.toString
val status = EPBUpdate.split(":")
val String sensor_state = status.get(1)

postUpdate(Water_Update,sensor_state)

if(sensor_state == "Water Detected")
{
	sendCommand (Water_Status , "LON")  
}

else if(sensor_state == "Nothing")
{
	sendCommand (Water_Status , "LOFF")  
}
 
end  

It gives me the following error:
[ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Water_Sensor': 1

Can anyone help me out with this problem.

The problem is most likely that your rule assumes that EPBUpdate will contain a string with at least one colon (:) and that in some cases this is not true, hence status.get(1)will fail:

val String sensor_state = status.get(1)

I would add the following debug line immediately below then so you can see which state is giving you problems:

logInfo("Water_Sensor", "Water_Status.state = '{}'", Water_Status.state.toString)

Thank you.
I was sending data packets to zigbee serialy, so also got recieve status packet along with colon data .

Here’s how I would rewrite your rule:

rule "Water_Sensor"  
when   
    Item Water_Status received update  
then
    val String loggerName = "Water_Sensor"
    logDebug(loggerName, 'Water_Status.state = "{}" (previously "{}")',
        Water_Status.state.toString,
        Water_Status.previousState().state.toString
    )
    val EPBUpdate = Water_Status.state.toString
    val status = EPBUpdate.split(":")
    if (status.length < 2) {
        logWarn(loggerName, 'Water_Status.state = "{}"  - It contains no ":" separator',
            Water_Status.state.toString
        )
    } else {
        // The sensor state is the 2nd parameter
        val String sensor_state = status.get(1)

        postUpdate(Water_Update, sensor_state)

        switch (sensor_state) {
            case "Water Detected": {
                sendCommand (Water_Status , "LON")  
            }
            case "Nothing": {
                sendCommand (Water_Status , "LOFF")  
            }
        }
    }
end

To see the debug level messages at the start of the rule, you can either set the log level to DEBUG (log:set DEBUG org.openhab) or temporarily replace logDebug with logInfo which will display INFO messages (default log level for org.openhab).

1 Like