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?
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)
}
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
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.