var Number LowTemp = 75
var Number MedTemp = 77
var Number HiTemp = 80
rule "turn on/off family room fan as necessary"
when
Item GF_HomeCinema_Temperature changed
then
if (vOverrideCinemaFan == NULL || vOverrideCinemaFan.state == OFF) {
var Number temp = GF_HomeCinema_Temperature.state
if (temp < LowTemp) {
GF_HomeCinema_Fan.sendCommand(OFF)
} else (temp >= LowTemp) {
logError('family room fan', 'temp is ' + temp)
GF_HomeCinema_Fan.sendCommand(ON)
if (temp >= LowTemp && temp < MedTemp) {
GF_HomeCinema_Fan_Speed.sendCommand(10)
} else if (temp >= MedTemp && temp < HiTemp) {
GF_HomeCinema_Fan_Speed.sendCommand(50)
} else if (temp >= HiTemp) {
GF_HomeCinema_Fan_Speed.sendCommand(100)
}
}
}
end
When the rules runs, I see the following in the log:
2020-01-09 13:13:30.869 [ERROR] [arthome.model.script.family room fan] - temp is 71.0
However, the fan turns on; why? For the life of me, I can see anything wrong with the logic; in fact, I have a rule for another fan that is working fine. Why is this one turning on before it is supposed to?
Some thoughts: add more log statements to log out the variables and everything on each branch, that will allow you to narrow down what is going on.
You may also try to pack your variable definition after the then statements (sometimes trying to make variable that are global for the specific rule file causes more problems than solutions), i.e., try it this way:
rule "turn on/off family room fan as necessary"
when
Item GF_HomeCinema_Temperature changed
then
val Number LowTemp = 75
val Number MedTemp = 77
val Number HiTemp = 80
if (vOverrideCinemaFan == NULL || vOverrideCinemaFan.state == OFF) {
var Number temp = GF_HomeCinema_Temperature.state
if (temp < LowTemp) {
//log statement here to indicate that your condition is < LowTemp is met
//also log out all your variables and item states that are relevant
while I am not privy to your other conditions, try logInfo as statement during debugging to get highest verbosity; you can always comment them out when you are done debugging. hope that helps
I’m surpirsed the rule validation wouldn’t squawk about this. Sometimes the rules DSL helps too much. Your if/else statement is formatted wrong here. Try this instead…
if (temp < LowTemp) {
GF_HomeCinema_Fan.sendCommand(OFF)
} else {
logError('family room fan', 'temp is ' + temp)
GF_HomeCinema_Fan.sendCommand(ON)
@5iver I just found that myself. I i changed it the way you have it or by putting the ‘if’ after ‘else’ it works. I’m surprised it wasn’t flagged an error my self.