[SOLVED] If clause in rule - syntax?

I’m too blind for getting behind this error in the log:

2018-05-23 11:20:00.242 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Sonne und Ereignisse': Unknown variable or command '=='; line 108, column 70, length 24

what happens in this rule is I compare some states and move my shutters accordingly. I don’t want to post the whole Thing here as it is a bit more complex, but the main Things:

// declaration of variables
	var DateTime HoursAgo = now.minusHours(3)
	var DateTime lastKnownMotion = new DateTime((Binder_AutoShutter.state as DateTimeType).getZonedDateTime.toInstant.toEpochMilli)
	var Number newShutterPos = -1
	var Switch newShutterOverride = OFF

// this is the famous line 108:
	if (newShutterPos != -1 && ((HoursAgo.isAfter(lastKnownMotion)) || (newShutterOverride == ON))) {

  • HoursAgo: is just 3Hours ago (to avoid frequent movements)
  • lastKnowMotion: everytime the rule changes the shutter-position, the Binder_AutoShutter gets updated, with HoursAgo I avoid frequent movements, as the rule fires every 5mins.
  • newShutterPos: this variable is declared as -1 and gets updated with the percentage of the shutter (0-100) within the rule
  • newShutterOverride: in case, there was a rule-triggered movement within the last 3Hours, but I have to move the shutters (e.g. sun is gone), the override is set to ON

So, I’m out of ideas on why the if-clause fails. I already tried it with ===, but still same… thanks for help.

can you really declare a variable as a switch (item) type?

var Switch newShutterOverride = OFF

That was also my first guess. Try it with boolean

Thanks guys! That was it… :beers: