RULE: When statement to include variable value?

Is it possible in a rule statement to check when a a switch receives an update AND a variable (i define) equals something.

For example, i want to check for a switch to receive an update and my variable to equal something:

rule "Sync Soffit Lights if Double Tapped"
when
    Item Light_House_Soffit received update AND
		syncDimmer == 1
then
		percent = ((Light_House_Soffit.state as DecimalType)).intValue
		sendCommand(Light_Garage_Soffit, percent)
end

This is currently how i have it working:

rule "Sync Soffit Lights if Double Tapped"
    when
        Item Light_House_Soffit received update
    then
	if(syncDimmers == 1) {
		percent = ((Light_House_Soffit.state as DecimalType)).intValue
		sendCommand(Light_Garage_Soffit, percent)
		//pushover("Lights have been dimmed")
		}
		else
		logInfo("DIMMERS", "Dimmers not synced.")
		}
    end

No. Rules are triggered based on events, not states. Therefore it makes no sense to have an AND in a when clause. There will never be a case where both the Item and the variable will receive an event at the same time to trigger the rule.

Furthermore you cannot use a variable to trigger a rule. Only the events caused by Items changing or receiving a command or update or a few other time and system based events can trigger a rule.

If you need to do something about state like you describe you need to use if statements with conditionals as in your working example.

1 Like

Perfect. thanks for the clarification!