I am using following rule to determine is outside temperature or inside temperature is below defined thresholds
rule "Blinds-down-if-temp-high"
when
System started or
Item TerrasseTemp received update or
Item Outside received update or
Item Inside received update
then
var Number Temp1 = TerrasseTemp.state
var Number Temp2 = Outside.state
var Number Temp3
Temp3 = (Temp1 + Temp2)/2
Outside_Temp.postUpdate(Temp3)
if(Outside_Temp.state <=28 || Inside.state >=26)
{
TempHigh = false
logInfo ("StatusUpdate", "Temp below Threshold " + Outside_Temp.state.toString())
}
else
{
TempHigh = true
if (TempHigh == true)
logInfo ("StatusUpdate", "Temp above Threshold " + Outside_Temp.state.toString())
{
if (gBlinds.members.filter[BlindsControl| BlindsControl.state == BlindsClosed)]
{
logInfo ("StatusUpdate", "NoAction HighTemp")
}
else
{
logInfo ("StatusUpdate", "ClosingBlinds Temp too high " + Outside_Temp.state.toString())
gBlinds.members.forEach[BlindsControl | BlindsControl.sendCommand(BlindsDown)]
gBlindsLam.members.forEach[LamellaPosition | LamellaPosition.sendCommand(blindLamella0)]
// set global variable
TempHigh = true
}
}
}
end
For reason unknown the rule stopped working and is detecting false positives:
Please use code fences to properly format your code and logs.
```
code goes here
```
It is really hard to follow the rule without proper indentation but it looks overly complex for what the rule does. At least one of the curly brackets looks miss-placed.
Load the rule into Designer to look for syntax errors.
if(Outside_Temp.state <=28 || Inside.state >=26)
Is that right? Shouldn’t it be Inside.state <= 26?
changed to inside.state <= 26
but still confused a bit, I was expecting if any of the 2 statements is true to return a positive result.
I am not able to explain, why the if statement returns TempHigh = false when both Outside_Temp.state <=28 and Inside.state >=26 where true.
Without proper code formatting I couldn’t tell you one way or the other. It is all but impossible to tell what this code does unless I spent an hour studying it which I don’t have.
All I can say is there is some logic error in the code.
@Chri46 My first approach to this issue would be to throw some logging lines in there. Have Temp1, Temp2, Temp3 printed to the log to see why the comparison fails. Easy peasy