Problem with using variables (.toString' cannot be resolved)


I’m having an weird issue for some hours now…

Having this part of my script:

    val nextValveNum = 0
    val nextValveName = ""
    val nextValveSwitch = null

    val activeValves = gIrrigationTime.members.filter[t|t.state > 0]
    logInfo("Irrigation", "--------------------------------------------")
    var boolean exitFlag = false
        if(!exitFlag) {
            logInfo("Irrigation", i.toString)
            val valveTimeName =
            val valveName = valveTimeName.split("_").get(0) + "_" + valveTimeName.split("_").get(1)
            val valveNum = Integer::parseInt(valveName.split("_").get(1)) // Irrigation_1_Time

            if(valveNum > currValveNum) {
                logInfo("Irrigation", "Found new active valve: " + valveName.toString)
                nextValveNum = valveNum
                nextValveName = valveName
                nextValveSwitch = gIrrigation.members.filter[i| == valveName].head
                logInfo("Irrigation", gIrrigation.members.filter[i| == valveName].head.toString)
                logInfo("Irrigation", nextValveNum.toString)
                logInfo("Irrigation", nextValveName.toString)
                logInfo("Irrigation", nextValveSwitch.toString)
                exitFlag = true
        } else {
            logInfo("Irrigation", "Already found a next valve!")
    logInfo("Irrigation", "Continuing")

I’m trying to fill nextValveSwitch with the valve from gIrrigation which has a runtime greater than 0. So far so good, I’m getting this error:

2017-04-17 22:14:06.298 [INFO ] [se.smarthome.model.script.Irrigation] - --------------------------------------------
2017-04-17 22:14:06.318 [INFO ] [se.smarthome.model.script.Irrigation] - Irrigation_1_Time (Type=NumberItem, State=2.0, Label=null, Category=null, Groups=[gIrrigationTime])
2017-04-17 22:14:06.364 [INFO ] [se.smarthome.model.script.Irrigation] - Irrigation_5_Time (Type=NumberItem, State=2.0, Label=null, Category=null, Groups=[gIrrigationTime])
2017-04-17 22:14:06.456 [INFO ] [se.smarthome.model.script.Irrigation] - Found new active valve: Irrigation_5
2017-04-17 22:14:06.579 [INFO ] [se.smarthome.model.script.Irrigation] - Irrigation_5 (Type=SwitchItem, State=OFF, Label=State, Category=Switch, Groups=[gIrrigation])
2017-04-17 22:14:06.589 [INFO ] [se.smarthome.model.script.Irrigation] - 5
2017-04-17 22:14:06.598 [INFO ] [se.smarthome.model.script.Irrigation] - Irrigation_5
2017-04-17 22:14:06.608 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Irrigation switch cascade': The name '<XFeatureCallImplCustom>.toString' cannot be resolved to an item or type.

So it looks like it can’t fill the “nextValveSwitch” var.

How can I fix that?

nextValveSwitch should be an Item?

As it is an Item, you would want to examine its .state or .name or whatever it is you are interested in?

Yes, nextValveSwitch should be an item.
That log command is just to Check if nextValveSwitch has been set to the new item but it fails because it is still null.

I think you miss my point. Items do not have a toString method. Maybe or nextValveSwitch.state.toString

I’m not too sure about that.

This one is working with .toString:

logInfo("Irrigation", gIrrigation.members.filter[i| == valveName].head.toString)

And I think it’s nearly the same