Any spot my mistake?

Hello,

Can anyone see if there is something wrong with this IF statement from my rule?

rule “Master Rule”

when

Time cron "0 0/5 * 1/1 * ? *"  or 
Item CH_Master_Switch received update

then

if ((CH_Master_Switch.state == ON) && (CH_Home_Away.state == 1) && (CH_Program != 0)) {
    
    if ((CH_Active_Target_Room == 1) && (CH_CTemp_Living.state as DecimalType < CH_Target_Temp_Living.state as DecimalType)) or 
       ((CH_Active_Target_Room == 2) && (CH_CTemp_Bed.state as DecimalType < CH_Target_Temp_Bed.state as DecimalType)){
    
            sendCommand(CH_Boiler_Status,1)
    }

    
} else {
            sendCommand(CH_Boiler_Status,0)
}

end

What I am trying to do is say if the “CH_Master_Switch” is on AND “CH_Home_Away” is 1. Then dependent on which “CH_Active_Target_Room” is selected, if the temperature is below the target temp, turn the boiler on.

No matter what the current temp or set temp is, the boiler turns on, if I switch the Master, off the boiler receives the OFF command.

Think I have something wrong in the second IF statements?

Update:

I have split out the IF statement as follows, and now the boiler wont switch on when the current temp falls below the target temp.

if ((CH_Master_Switch.state == ON) && (CH_Home_Away.state == 1) && (CH_Program != 0)) {

    if ((CH_Active_Target_Room == 1) && (CH_CTemp_Living.state as DecimalType =< CH_Target_Temp_Living.state as DecimalType))  {
    
            sendCommand(CH_Boiler_Status,1)
    }
    
    else if   ((CH_Active_Target_Room == 2) && (CH_CTemp_Bed.state as DecimalType =< CH_Target_Temp_Bed.state as DecimalType)){
    
            sendCommand(CH_Boiler_Status,1)
    } else {
            sendCommand(CH_Boiler_Status,0)
    }

    
} else {
            sendCommand(CH_Boiler_Status,0)
}

In openHAB designer =< is flagged as an error. Do you just mean < ?

And then you also have to add some more parenthesis

    if ((CH_Active_Target_Room == 1) && ((CH_CTemp_Living.state as DecimalType) < CH_Target_Temp_Living.state as DecimalType))  {

            sendCommand(CH_Boiler_Status,1)
    }

Is CH_Active_Target_Room an Item or a variable? (i.e. should be getting its .state or something)

You are correct I did only mean “less than”, however this still doesn’t seem to trigger the IF statement, even when the condition is met.

Think something is wrong pulling the state from the item which means its not a valid number, so the less than compare statement is not working.

I think this is the case as if i manually set CH_Boiler_Status to ON, then then adjust the Target temp which triggers the rule, the Boiler is turned off. So i know the rule is being triggered but the IF criteria is not being met.

I did read on forum about Double::ParseDouble. will do bit more investigation

CH_Active_Target_Room is a Number Item.

Ive updated the status for each of the various IF’s so I can see which is being triggered as follows:

if ((CH_Master_Switch.state == ON) && (CH_Home_Away.state == 1) && (CH_Program.state != 0)) {

    if ((CH_Active_Target_Room.state == 1) && ((Double::parseDouble(CH_CTemp_Living.state)  < (Double::parseDouble(CH_Target_Temp_Living.state) ))  {
    
            sendCommand(CH_Boiler_Status,2)
    }
    
    else if   ((CH_Active_Target_Room == 2) && (CH_CTemp_Bed.state as DecimalType < CH_Target_Temp_Bed.state as DecimalType)){
    
            sendCommand(CH_Boiler_Status,3)
    } else {
            sendCommand(CH_Boiler_Status,4)
    }

    
} else {
            sendCommand(CH_Boiler_Status,0)
}

From this I am always getting State =4, so its not hitting either of the comparison IF’s

Think I am doing something wrong with the two Items.

Items:

Number CH_Target_Temp_Living “Lounge Set Temp [%.1f C]” (CH){ lightwaverf=“room=2,serial=2D42FE,type=HEATING_SET_TEMP” }

Number CH_CTemp_Living “Lounge Current” (CH) { lightwaverf=“room=2,serial=2D42FE,type=HEATING_CURRENT_TEMP,poll=120” }

Will just reading .state return a number (int or double) or a string?

I have just pasted the above in to openHAB designer and I am getting three errors.

Two are for attempting parseDouble on the temperature state and one is the lack of parenthesis I pointed out before.

Are you using openHAB designer to write your rules? If so, there is something wrong with my simulation.

Cheers

Graham

Firstly, thanks for the feedback to everyone.

I am not using OH Designer, using a text editor, so syntax errors easy to make!

I have now got this working, so seems there was something wrong with my syntax on the IF’s

if ((CH_Master_Switch.state == ON) && (CH_Home_Away.state == 1) && (CH_Program.state != 0)) {
    
    sendCommand(CH_Boiler_Status,0)

    if (CH_Active_Target_Room.state == 1)  { 
    
        if ( CH_CTemp_Living.state < CH_Target_Temp_Living.state ) {
            sendCommand(CH_Boiler_Status,1)
        } 
    
    } 
    if (CH_Active_Target_Room.state == 2) {
 
        if ( CH_CTemp_Bed.state < CH_Target_Temp_Bed.state ) {
            sendCommand(CH_Boiler_Status,1)
        } 
     }            
} else {
            sendCommand(CH_Boiler_Status,0)
}

The above is now giving me the expected results. Not pretty and if anyone can suggest way to clean it up would be good, but least I am getting the expected results now.

I can highly recommend using it, even if only to debug snippets like this.

The last item you pasted is still throwing up syntax errors when doing the < tests, so I suspect you haven’t finished.

The errors are ‘Incompatible types. Expected java.lang.Number but was org.openhab.core.types.State’

Graham