[SOLVED] Help needed with variables

I’m trying to get a rule working that adjusts my thermostat heating setpoint by using the rule below. However when the rule loads I get the error below. Any pointers?

2018-11-20 19:07:21.525 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘Heating.rules’, using it anyway:
The value of the local variable newSetpoint is not used
The value of the local variable newSetpoint is not used
The value of the local variable newSetpoint is not used
The value of the local variable newSetpoint is not used
The value of the local variable newSetpoint is not used

rule "Change Heating SetPoint"
when
        Item Time_Of_Day changed
then
        var newSetpoint = null

        if(Time_Of_Day.state == "MORNING") {
                val newSetpoint = Heating_Setpoint_Morning.state as Number
        } else if (Time_Of_Day.state == "DAY") {
                val newSetpoint = Heating_Setpoint_Day.state as Number
        } else if (Time_Of_Day.state == "EVENING") {
                val newSetpoint = Heating_Setpoint_Evening.state as Number
        } else if (Time_Of_Day.state == "NIGHT") {
                val newSetpoint = Heating_Setpoint_Night.state as Number
        } else if (Time_Of_Day.state == "BED") {
                val newSetpoint = Heating_Setpoint_Bed.state as Number
        }
        logInfo("Heating","New Setpoint: " + newSetpoint)
        Group_SetPoint_Command.sendCommand(newSetpoint)
end

You are declaring a new newSetpoint within the body of each if statement. That declaration has scope only within that of statement body, and, since you never reference that variable, the rule engine is noting that you are declaring a variable that you never reference.

Remove the val inside each of the if statements.

Thanks @mhilbush that solved that one.

@vzorglub Hey, you’re pretty quick! I was just getting ready to ask @Maximo to mark it solved. :sunglasses: