Help with script

i am struggling a bit with a script am upgrading from 2 to 4 it worked in 2 but cant get this right

2024-11-20 12:08:16.177 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘14f53ef7d9’ failed: val Number temp_Offset = 0.1
val Number temp_Offset1 = 0.5
var Number house_heat = house_temp_SP.state as Number
var Number heat_setpoint.state as Number
if (house_heat <= (heat_setpoint - temp_Offset)) {
Central_Heating_Relay.sendCommand(ON)
} else if (house_heat >= (heat_setpoint + temp_Offset1)) {
Central_Heating_Relay.sendCommand(OFF)
}


val Number temp_Offset = 0.1
val Number temp_Offset1 = 0.5
var Number house_heat = house_temp_SP.state as Number
var Number heat_setpoint.state as Number
if (house_heat <= (heat_setpoint - temp_Offset)) {
Central_Heating_Relay.sendCommand(ON)
} else if (house_heat >= (heat_setpoint + temp_Offset1)) {
Central_Heating_Relay.sendCommand(OFF)
}

can anyone point me in the right direction please

thanks

Doesn’t make sense.

Better approach:

val Number tempNeg = 0.1
val Number tempPos = 0.5
val Number tempSet = (heat_setpoint.state as Number).floatValue
val Number tempIs  = (house_temp_SP.state as Number).floatValue
var target         = Central_Heating_Relay.state

if(tempIs <= tempSet - tempNeg) 
    target = ON
else if(tempIs >= tempSet + tempPos) {
    target = OFF

if(Central_Heating_Relay.state != target)
    Central_Heating_Relay.sendCommand(target.toString)

.floatValue → will ensure to cut quantity from a QuantityType state (if Items are of type QuantityTpe - but won’t harm if not)
The detour with target will ensure only to send the command if really necessary.

thank you got it working with that code seen in mine i had missed a tag just couldnt see it for looking :smile:

Even better from a Rules DSL perspective would be

val tempNeg = 0.1
val tempPos = 0.5
val tempSet = heat_setpoint.state as Number
val tempIs  = house_temp_SP.state as Number

Rules DSL really wants to figure out the ty pe of things at runtime and when you force it it often causes problems in unexpected ways.