Basic maths question

Hi,

I’m trying to modify the below rule to add some variance around the setpoint to prevent the fridge constantly hunting. In pseudo code, ideally keen write something like:

if (Curing_temp.state > Curing_temp_setpoint.state + 2) Fridge.sendCommand(ON)
if (Curing_temp.state > Curing_temp_setpoint.state - 2) Fridge.sendCommand(OFF)

but I can’t get it to work.

The currently working “dumb” rule is:

    rule "Curing Chamber Fridge Control"
    when
            Item Curing_temp_setpoint changed or
            Item Curing_temp changed
    then
            if (Curing_temp.state > Curing_temp_setpoint.state) Fridge.sendCommand(ON)
            else Fridge.sendCommand(OFF)
    end

Any advise on how to get something working would be greatly appreciated.

Something like this?

val Number maxTempTolerance = 2
val Number minTempTolerance = 2

 rule "Curing Chamber Fridge Control"
    when
            Item Curing_temp_setpoint changed or
            Item Curing_temp changed
    then
            if ((Curing_temp.state > (Curing_temp_setpoint.state + maxTempTolerance))  Fridge.sendCommand(ON)
            else if ((Curing_temp.state < (Curing_temp_setpoint.state - minTempTolerance)) Fridge.sendCommand(OFF)
    end

Thanks Alpoy, but no luck with that one.

Try adding the state as a number in your rule like:

(Curing_temp.state as Number)

That did it. Thanks so much for your help!