Casting item states and comparison

I’ve got two issues (I think).

  1. VSCode is showing no issue with validation but I get the following error

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Hotwater Hotwater_Booster Switch’: Could not cast 34.63 C to org.eclipse.smarthome.core.library.types.DecimalType; line 90, column 26, length 29
on this line:
rule:

var double HotwaterTempBefore = 0.0  
..
HotwaterTempBefore = (HOTWATER.state as DecimalType).floatValue

items

Number:Temperature HOTWATER "Hotwater temperature [%.1f C]"  <temperature>
Number:Temperature HotwaterLow "Hotwater Low temperature [%.1f C]" <temperature> (hotwater)  //38.0
Number:Temperature HotwaterVeryLow "Hotwater very low temperature [%.1f C]" <temperature>  (hotwater) // 29.0

issue 2. which vscode is showing two errors “type mismatch”
Type mismatch: cannot convert from State to Number
on this line:

if (HOTWATER.state < HotwaterLow.state ) {
        msg = "Hotwater Temp is low, threshold (" + HotwaterLow.state + ") \n"  + msg  
    ....

UoM - your Item state carries units information, not just numeric value

var HotwaterTempBefore = (HOTWATER.state as QuantityType<Number>).doubleValue

Here you’re building a string

msg = "Hotwater Temp is low, threshold (" + HotwaterLow.state.toString + ") ...

ok great working now… thanks muchly

so I assume the VSCode (addon) warnings I can ignore as openhab seems to work

ie {
“resource”: “/o:/rules/hotwater.rules”,
“owner”: “generated_diagnostic_collection_name#0”,
“code”: “org.eclipse.xtext.xbase.validation.IssueCodes.incompatible_types”,
“severity”: 8,
“message”: “Type mismatch: cannot convert from State to Number”,
“startLineNumber”: 50,
“startColumn”: 23,
“endLineNumber”: 50,
“endColumn”: 40
}

I’m not sure what it’s whinging about there.