Ternary expression error

I’m trying to create a rule for dimming some lights on my porch, but getting error when trying to use ternary expression. If I remove the line, there’s no error in the script otherwise. Here’s the scritpt;

var Timer runTimmer = null

rule "Motion sensor light"
	Item MotionDetector_Porch changed to ON
	if (Astro_SunPhase.state == "Dag") {
		if (runTimmer === null) {
			logInfo("LAMP STATE","Prev state: " + Light_Entry_Dimmer.state)
			var prevLightState = (Light_Entry_Dimmer.state > 50) ? Light_Entry_Dimmer.state : 50
			runTimmer = createTimer(now.plusMinutes(1), [|
				runTimmer = null
		} else {

The error thrown is;

[WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model 'daylight.rules' has errors, therefore ignoring it: [12,57]: no viable alternative at input '?'
[12,84]: mismatched input ':' expecting '}'
[21,2]: extraneous input '}' expecting 'end'

In have used Ternary expression a lot in PHP, and what I could read the usage is the same in Xtend. Tried to search for the error, but didn’t find anything related to ternary expressions. Any idea?

[EDIT] Btw, ignore the usage of Lamp_Kitchen, it’s just so I don’t have to be outside in the cold while testing it :slight_smile:

Found a other (and better) solution to solve it, but still bit confused about why ternary expression in OH failed.

It’s just DSL syntax

var prevLightState =  if (Light_Entry_Dimmer.state > 50)  Light_Entry_Dimmer.state else 50
1 Like

Changed the script entirely to fit better into what I wanted, but you are right that that would work to. Maybe ternary expressions aren’t supported?

That is the syntax for a ternary expression in DSL. if() replaces ? , else replaces :