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.
Blockly hast another advantage: you can do the blocks and then look into the code tab and learn from it if you want use code later on. Blockly tries to do its best to keep the typed blocks consistent.
And as Rich said: you can have a mixed set of rules. I still have a few rules based on pure code while most of the others are blockly but that is matter of tasteā¦