This rule doesn't work

Hi all,
This rule

rule "Temperatuurcontrole en Verwarming"
when
    Item GameRoom_temp changed
then
    // Lees de huidige temperatuurwaarde uit
    val Number currentTemperature = GameRoom_temp.state as Number

    // Toegevoegde logboekverklaring
    logInfo("HeatingRule", "Check temp gameroom.")
    logInfo("HeatingRule", "Huidige temperatuurwaarde: {}", currentTemperature)

    // Controleer of de temperatuur lager is dan 14 graden en zet de verwarming aan
    if (currentTemperature < 14 && Heater_Game_Room_Switch.state != ON) {
        Heater_Game_Room_Switch.sendCommand(ON)
    }
    // Controleer of de temperatuur gelijk is aan of hoger dan 18 graden en zet de verwarming uit
    else if (currentTemperature >= 18 && Heater_Game_Room_Switch.state != OFF) {
        Heater_Game_Room_Switch.sendCommand(OFF)
    }
end

Doesn’t seem to work. Must be pretty simple but I cannot figure it out.
Can anybody see what I am missing here?
The switch does not turn ON or OFF. The loginfo does indicate that the currenttemperature readout is correct.
I can also see that the switch is in the correct state. Some how there is no sendcommand action

I see two potential problems

  1. Replace ON and OFF by “ON” and “OFF”
  2. Is your item currentTemperature a number item or of unit temperature? If it is unit based please search in the docs for „Unit of Measurement“ how to deal with them.
1 Like

That’s not necessary in Rules DSL. That part of the code will work as written.

It helps us a lot to see these logs. I suspect @Oliver2’s 2 is on the right track but the logs will confirm it. In particular if the log says “Huidige temperatuurwaarde: 22 °C” (for example) as opposed to “Huidige temperatuurwaarde: 22” that would indicate that the. problem is related to units.

1 Like

I think that could be the issue. As this is the output of the log:
2023-12-18 19:12:42.508 [INFO ] [penhab.core.model.script.HeatingRule] - Check temp gameroom.

2023-12-18 19:12:42.510 [INFO ] [penhab.core.model.script.HeatingRule] - Huidige temperatuurwaarde: 10.75 °C

I removed the as Number and put | ℃ behind the 14 and 18
Now the rule works.

Thanks for pointing me in the right direction