Error in rule using a simple boolean type: really!@#$%

What fundamental knowledge am i missing that I seem unable to write a simple rule?

/* ----- 160816 MaxG: added to prevent shutter commands every minute
var boolean ShutterHouseLivingWestClosed = false

/* ----- 160815 -- check azimuth and shut roller shutter on western window ----- */
rule "Autoshading Roller Shutter Living West"
when
  Item Sun_Azimuth changed
then
  var int azimuth = (Sun_Azimuth.state as DecimalType).intValue
  logInfo("Shutter0.rule", "Shutter_House_Living_West " + azimuth)
  
  // if sun shines into west window and it is not cloudy, shut the roller shutter
  // if (azimuth > 295 && azimuth < 333) {
  //if (azimuth > 295 && azimuth < 333 && Weather_Cloudy.state != OFF && ShutterHouseLivingWestClosed=false) {
  //if (azimuth > 295 && azimuth < 333 && Weather_Cloudy.state != OFF && !ShutterHouseLivingWestClosed) {
  if (azimuth > 295 && azimuth < 333 && Weather_Cloudy.state != OFF) {
    logInfo("Shutter1.rule", "Shutter_House_Living_West is DOWN (command)")
    sendCommand(Shutter_House_Living_West, DOWN)
    ShutterHouseLivingWestClosed = true
  }
  //else if (azimuth > 293 && azimuth < 295 && ShutterHouseLivingWestClosed=true) {
  //else if (azimuth > 293 && azimuth < 295 && ShutterHouseLivingWestClosed) {
  else if (azimuth > 293 && azimuth < 295) {
    logInfo("Shutter2.rule", "Shutter_House_Living_West is UP (command)")
    sendCommand(Shutter_House_Living_West, UP)
    ShutterHouseLivingWestClosed = false
  }
end

The error I am getting is either:

or

The rule works if I leave out any references to ShutterHouseLivingWestClosed.

Are there some samples somewhere, how variables need to be defined, updated, and executed?

I’ve read in a post a while ago that it can cause problems to mix two different comment syntax’s.
So it’s a quick check to replace /* with //.

Tried it – no difference.
Also typed Boolean instead of boolean – no difference.

I figured this line:

    ShutterHouseLivingWestClosed = false

causes the 2nd error message. I am lost.

Seems like you do not close the comment in the first line with */

1 Like

Good spotting!

I ‘replaced’ */ with nothing and /* with //, which resulted in a non-matching number of replacements.

Rule now works:

2016-08-17 19:27:09.985 [INFO ] [hab.model.script.Shutter0.rule] - Shutter_House_Living_West 271
2016-08-17 19:27:11.076 [INFO ] [hab.model.script.Shutter2.rule] - Shutter_House_Living_West is UP (command)
2016-08-17 19:28:09.635 [INFO ] [hab.model.script.Shutter0.rule] - Shutter_House_Living_West 271
2016-08-17 19:29:09.633 [INFO ] [hab.model.script.Shutter0.rule] - Shutter_House_Living_West 271

… as intended!
Thank you kindly!

Be aware of the difference between == and = :wink:

if (azimuth > 295 && azimuth < 333 && Weather_Cloudy.state != OFF && ShutterHouseLivingWestClosed == false) {
//...
}
else if (azimuth > 293 && azimuth < 295 && ShutterHouseLivingWestClosed == true) {
//...
}
1 Like

Believe it or not… I just picked up on this a moment ago and changed it right now … just before your post popped in! :slight_smile:
In any case: thank you for highlighting this!

It’s only because I have to correct this issue by myself over and over again :wink: sometimes written too fast, somtetimes forgotten about the meaning…