As has been pointed out. A String is not a Number and you canât do math with it as if it were a Number.
Rules DSL really wants to be weakly typed. Your life will go much better if you let it be weakly typed. And because it wants to be weakly typed, there is nothing that fixes the type or any variable. It will happily assign a String to a variable that was declared to be a Number.
The only times you should force a type in Rules DSL include:
you are initializing the variable to null: e.g. var Timer myTimer = null
you are casting because Rules DSL wasnât able to determine the correct type on itâs own: e.g. (MyItem.state as Number)
itâs required to be a specific type, usually a primitive, for a call to a Java method: e.g. now.plusSeconds(mySecondsVariable.intValue)
In all other cases, forcing the type in Rules DSL will cause way more problems than it solves.
2023-02-20 20:48:00.808 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID âbil-lader-2â failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.Log.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null in bil-lader
2023-02-20 21:11:20.874 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID âbil-lader-2â failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.lib.NumberExtensions.operator_greaterThan(java.lang.Number,java.lang.Number) on instance: null in bil-lader
amp_p3 isnât a Number either. Itâs a String. You have to parse it into a Number to do math with it.
Again, see my reply above. var Number amp_p3 does not convert a String to a Number. For the most part, that does nothing. You have to parse a String into a Number.
All things considered, youâd have a much better time of this if you switched to Blockly.
You can do it little by little. As you find you need to write new rules, choose Blockly for those. As you need to change rules, consider translating them to Blockly.
Thereâs no real harm in having a mix of .rules files and Blockly rules.