Comparing Temperature in Javascript Rule (How to do it?)

Hi,

I’m trying to compare temperature on my virtual Item vs Heater item. I’m not sure if both items have to have exactly same Class ?

I picked same Type Number:Temperature. One has class Setpoint other just Point.
One has Semantic Property None with the second item I picked Temperature.

When I will run below piece of code with Logs I see that “°C” is being printed but I don’t know why comparison fails.

    Z_waveThing_SetPoint_Name = Z_waveThingName + '_Setpointheat'
    Z_waveThing_SetPoint_Value = itemRegistry.getItem(Z_waveThing_SetPoint_Name).getState();

    VirtualThingName = ListOfThings[i].virtual_item;
    Desired_SetPoint_Name = VirtualThingName + '_Desired_SetPoint';
    Desired_SetPoint_Value = itemRegistry.getItem(Desired_SetPoint_Name).getState();

    logger.info((['| Validate_Heater_Mode | Items: ', Z_waveThingName, ' : ', VirtualThingName].join('')));
    logger.info((['| Validate_Heater_Mode | SetPoint: ', Z_waveThing_SetPoint_Value, ' : ', Desired_SetPoint_Value].join('')));

   if (Z_waveThing_SetPoint_Value != Desired_SetPoint_Value) {
    logger.info((['| Validate_Heater_Mode | Synchronise SetPoint_Values mode : ', SyncMode].join('')));
    logger.info((['| Validate_Heater_Mode | SetPoint - z_wave : ', Z_waveThing_SetPoint_Value, ' Desired: ', Desired_SetPoint_Value, ' |'].join('')));

The problem is I’m not able to compare the temperatures of those two items.

2021-02-01 20:24:15.762 [INFO ] [org.openhab.rule.2c7096d114         ] - | Validate_Heater_Mode | SetPoint: 23 °C : 23.0 °C

2021-02-01 20:24:15.764 [INFO ] [org.openhab.rule.2c7096d114         ] - | Validate_Heater_Mode | Synchronise SetPoint_Values mode : VIRTUAL_HEATER

2021-02-01 20:24:15.767 [INFO ] [org.openhab.rule.2c7096d114         ] - | Validate_Heater_Mode | SetPoint - z_wave : 23 °C Desired: 23.0 °C |

Heater config:
obraz
Virtual Heater:
obraz

IIRC you can only compare decimaltypes and integers. So you need to cast them first

Z_waveThing_SetPoint_Value = itemRegistry.getItem(Z_waveThing_SetPoint_Name).getStateAs(DecimalType.class);

@tsmit thanks!