Hi, I’m running the latest OH3.2 and have a DSL rule which seem to have an error:
2021-11-01 21:25:00.703 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'ShellykWh' failed: gShellykWh.members.forEach[i|
val iSource = gShellyConsumption.members.filter[j|j.name.split("_").get(0) == i.name.split("_").get(0)].head
val Number nDelta = iSource.deltaSince(now.minusMinutes(1)).floatValue) / 60000
i.postUpdate((i.state as Number) + nDelta)
]
“Script execution failed” is quite a bit thin as a starting point when having no other clue what could be wrong. Is there a way to im prove the logging or to get a direct information about the possible error?
Well, it has given you the exact line of code where the error occurred. Start by breaking that line up and add lots of logging to figure out what could be going wrong.
val members = gShellykWh.members
logInfo("test", "There are " + members.size + " members in the group.")
members.forEach[ i
val namePart = i.name.split("_").get(0)
logInfo("test", "Looking for the Item with " + namePart +" as part of it's name")
]
And so on. The error is almost certainly coming from inside the lambda. Because of the way lambdas work there is usually no way to get anything more specific as an error. But if I were to guess, I’d say that either there is no Item found by the filter or the state if the Item that is found isn’t a Number.
Rich, thank you - this helped me to find out that not the group is the problem:
2021-11-01 22:06:00.057 [INFO ] [org.openhab.core.model.script.test ] - There are 12 members in the group.
2021-11-01 22:06:00.064 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with Shelly3DDrucker as part of it's name
2021-11-01 22:06:00.069 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyDaikinACWohnzimmer as part of it's name
2021-11-01 22:06:00.072 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyACMarion as part of it's name
2021-11-01 22:06:00.075 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyDaikinACSchlafzimmer as part of it's name
2021-11-01 22:06:00.077 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyLichtKamin as part of it's name
2021-11-01 22:06:00.080 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyGefrierschrank as part of it's name
2021-11-01 22:06:00.083 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyWaschmaschine as part of it's name
2021-11-01 22:06:00.090 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyACChristian as part of it's name
2021-11-01 22:06:00.093 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellySteg as part of it's name
2021-11-01 22:06:00.097 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyEiswurfler as part of it's name
2021-11-01 22:06:00.100 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyTrockner as part of it's name
2021-11-01 22:06:00.103 [INFO ] [org.openhab.core.model.script.test ] - Looking for the Item with ShellyTVWohnzimmer as part of it's name
Keep going. Log out the name of the Item that’s found. Log out the state of the Item that’s found. Log out the result of the call to deltaSince. Log out the result of the division.
val memberDeltaSince = iSource.deltaSince(now.minusMinutes(1))
logInfo("test", "The raw delta since is " + memberDeltaSince)
val floatVal = memberDeltaSince.floatValue
logInfo("test", "The delta since converted to a float is " + floatVal)