Rule Parsing error -fixed-

Hello,
this thread is for devs or people who know where i can file a bug report.

I created a rule which works like a charm but I always get the entry
[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘rollerShutter.rules’ is either empty or cannot be parsed correctly!
in my logfile. The SmartHome Designer says in line 35 “Type mismatch: cannot convert from void to Timer”.
Since the rule works this matter isn’t pressing but since I want to improve Openhub I thought I consult the community, best case, we improve it, otherwise I spent some time writing this.
Feel free to ask questions, I’m glad if I could help.

import java.util.HashMap
import java.util.Map

val Functions$Function6<RollershutterItem, Integer, Integer, Integer, Boolean, Map<String, Boolean>, Boolean> rollerShutterFunction = [
	RollershutterItem rollerShutter,
	int sunAzimuthFrom,
	int sunAzimuthTo,
	int runtime,
	Boolean setHorizontal,
	Map<String, Boolean> triggeredMap |
	
		logInfo("RollerShutterLogger", "got triggered with item " + rollerShutter.name);
		
		if(SunAzimuth.state > sunAzimuthFrom && SunAzimuth.state < sunAzimuthTo
			&& !triggeredMap.get(rollerShutter.name) 
			&& NightState.state == OFF
			&& isRaining.state == OFF
			&& gBrightnessMax.state >= 10000.0
		) {
			logInfo("RollerShutterLogger", "Lowering " + rollerShutter.name);
			triggeredMap.put(rollerShutter.name, true);
			rollerShutter.send(DOWN);
			if (setHorizontal) {
				createTimer(now.plusSeconds(runtime), [ |
					rollerShutter.send(UP);
					createTimer(now.plusSeconds(2), [ | 
						rollerShutter.send(STOP);
					])
				])
			}
		} else if(SunAzimuth.state >= sunAzimuthTo
			&& triggeredMap.get(rollerShutter.name)) {
			logInfo("RollerShutterLogger", "Lowering " + rollerShutter.name);
			triggeredMap.put(rollerShutter.name, false);
			rollerShutter.send(UP);
		}
		true
]

val double bightnessThreshold = 10000.0

val HashMap< String, Boolean> triggeredMap = newHashMap(
    "A2" -> false,
    "A25" -> false
)

// lounge
rule "rollershutter lounge"
when
    Item SunAzimuth changed
then
	logInfo("RollerShutterLogger", "SunAzimuth changed from " + previousState + " to " + SunAzimuth.state);
	//OG
	rollerShutterFunction.apply(A2, 260, 360, 75, true, triggeredMap); //links neben tür
end

rule "rollershutter  open for night"
when
	Item DayPhase changed to SUN_SET 
then
	logInfo("RollerShutterLogger", "night opening Rollershutteres")
	A25.send(UP); triggeredMap.put("A25" ,false);
end

** NOTE ** the script as it’s posted is already fixed

There is nothing wrong with OH. You are missing the |
in your lambda definitions in your createTimers.

createTimer (now.plusSeconds(runtime)) [ |
     //Timer code goes here
]

I updated the rule but the Designer still says the same error message.

What is srollerShutter? I see no other reference to that anywhere. It’s it an item not passed in to the lambda or a typo?

Also, add a true as the last line of the lambda. The result of the jar line gets returned and at return cannot be void.

Yes the srollerShutter was a typo which happened when I updated the post after your first hint.
What did the trick was the true in the end.
While trying to find the “last line of the lambda” I stumbled across your tutorial ""reusable functions, a simple lambda example
which cleared things up a lot for me. I even got ride of the warning that i should use parameterized functions ^^
Out of curiosity one thing remains that I don’t quite understand, is there a difference between

createTimer (now.plusSeconds(runtime)) [ |
     //Timer code goes here
]

and

createTimer(now.plusSeconds(runtime), [ |
    //Timer code goes here
])

Besides that a big thank you for your help :slight_smile:, seems like there is still a lot to learn for me.
Without you I wouldn’t have found a solution anytime soon.
Wish you a nice day and thanks again!
Anton

There is no functional difference between the two. The developers of Xtext, the language upon which the Rules DSL is based, added a bit of syntactical sugar to the language.

Basically, any time you have a method that takes a lambda as its last argument, you can define the lambda after the closing parens rather than inline as part of the method call.

As far as I can tell all they managed to do was eliminate needing to close everything with a ]) instead of a ] but at the cost of obscuring the fact that the lambda actually is an argument passed to the method.

1 Like