[SOLVED] OH2.1: rule checking for threshold gives false result

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:

2017-08-01 19:18:14.566 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp above Threshold 33.74350000
2017-08-01 19:18:20.522 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp above Threshold 33.74350000
2017-08-01 19:24:14.966 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp above Threshold 33.36850000
2017-08-01 19:24:20.881 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp above Threshold 33.36850000
2017-08-01 19:30:14.915 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp above Threshold 33.18100000
2017-08-01 19:30:20.827 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp above Threshold 33.18100000
2017-08-01 19:36:15.072 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp above Threshold 32.99350000
2017-08-01 19:36:20.983 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp above Threshold 32.99350000
**2017-08-01 19:42:14.833 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp above Threshold 32.77500000**
**2017-08-01 19:42:20.734 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp below Threshold 32.77500000**
2017-08-01 19:43:47.862 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp below Threshold 32.22500000
2017-08-01 19:43:51.960 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp below Threshold 32.22500000

Since 2017-08-01 19:42:20.734 the rule results in TempHigh = false and I am not able to figure out why

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 I’ve fixed your first posting. Please remember to do so to get better and quicker answers.

@rlkoshak don’t we all love good coffee :wink:

Clearly I’ve not had mine yet. Stupid autocorrect.

@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 :wink:

thanks for helping you with formatting - still a newbie to openhab and the community.

enhanced logging, thought of that before and that is why I did create this thread

Temp1 and Temp2 are sensors from which I am calculating the average -> Temp3
Temp3 = Outside_Temp (which I am persisting to influxdb)

Simplifying the code snippet:

 if(Outside_Temp.state <=28 || Inside.state <=26)
  {
  TempHigh = false
  logInfo ("StatusUpdate", "Temp below Threshold " + Outside_Temp.state.toString())
  }
 else
  {
  TempHigh = true
  logInfo ("StatusUpdate", "Temp above Threshold " + Outside_Temp.state.toString())
 }

Outside_Temp is now greater than 28
Inside is now smaller than 26

017-08-03 14:50:27.391 [INFO ] [pse.smarthome.model.script.Debugging] - Temp1 39.3
2017-08-03 14:50:27.394 [INFO ] [pse.smarthome.model.script.Debugging] - Temp2 35.187
2017-08-03 14:50:27.396 [INFO ] [pse.smarthome.model.script.Debugging] - Temp3 37.24350000
2017-08-03 14:50:27.399 [INFO ] [pse.smarthome.model.script.Debugging] - Outside_Temp 37.24350000
2017-08-03 14:50:27.402 [INFO ] [pse.smarthome.model.script.Debugging] - Inside 25.937

results in:

2017-08-03 14:50:27.407 [INFO ] [.smarthome.model.script.StatusUpdate] - Temp below Threshold 37.24350000

And rethinking it (again) over coffee, what I actually need is NOR instead of OR
@rlkoshak Thanks for the logic hint and the advise for more coffee

1 Like