- openhabian 3.3.0 on rPi4
I seem to hit a snag here and there during my migration from v2 to v3.
I have this rule:
if (spm_Message.state.toString.contains("|ERROR|"))
{
val String ERROR_MESSAGE = ZonedDateTime.now().toString + " " + spm_Message.state.toString.replace('|', '_')
val String CLI_RETURN_CODE = executeCommandLine(Duration.ofSeconds(3), "/bin/sh", "-c", "echo " + ERROR_MESSAGE + " >> /etc/openhab/html/Modbus.txt; echo $?")
logInfo(LOG_PREFIX + "01.05","Modbus error logged to file: {}", spm_Message.state.toString.split("\\|").get(2))
// this is printed despite being 0
if (CLI_RETURN_CODE != 0)
{
logInfo(LOG_PREFIX + "01.07","Return code: {}", CLI_RETURN_CODE)
}
/*
// next creates an error: 2022-11-11 16:27:56.331 [ERROR] [internal.handler.ScriptActionHandler] -
// Script execution of rule with UID 'sppro_modbus-2' failed: For input string: "0" in sppro_modbus
// worked in OH2
if (Integer::parseInt(CLI_RETURN_CODE) != 0)
{
logInfo(LOG_PREFIX + "01.07","Return code: {}", CLI_RETURN_CODE)
}
*/
logInfo(LOG_PREFIX + "01.08","into if")
if (Integer::parseInt(CLI_RETURN_CODE) != 0)
{
logInfo(LOG_PREFIX + "01.08","Return code: {}", CLI_RETURN_CODE)
}
}
Which creates this error:
2022-11-12 14:13:44.379 [INFO ] [enhab.core.model.script.Modbus.01.05] - Modbus error logged to file: Invalid CRC at 8051
2022-11-12 14:13:44.381 [INFO ] [enhab.core.model.script.Modbus.01.07] - Return code: 0
2022-11-12 14:13:44.383 [INFO ] [enhab.core.model.script.Modbus.01.08] - into if
2022-11-12 14:13:44.386 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'sppro_modbus-1' failed: For input string: "0" in sppro_modbus
Where I see the return code of 0 in the log, the intent is not not to print this message. It seems to be zero but isnât for this if statement (CLI_RETURN_CODE != 0
)
Assuming the CLI_RETURN_CODE is a string type as defined further up, the comparison should be CLI_RETURN_CODE != "0"
, but this also leads to the same script error.
Any hints appreciated.