Rules error - no viable alternative at input 'or'

hi guys, any idea what’s wrong with this rule please?

rule "bedtime lights off"

Time cron “0 30 23 * * ?”
if ( alarmstring.state == “sethome”) or
( alarmstring.state == “setaway”)
do stuff

is it a syntax error?

Yes. The or operator in Xbase (and therefore in the rules) is ||, not the word “or”.

With || is get
Couldn’t resolve reference to JvmIdentifiableElement ‘||’.

Yes, upon a closer look you are also missing parens. Once I saw the “or” error I stopped looking for other errors.

if ( (alarmstring.state == “sethome”) ||
(alarmstring.state == “setaway”) )

You should look a the Rules Syntax and the Xtend for the full documentation of the rules syntax.

Rich, thanks for your help - I did check the wiki for the correct syntax - guess I missed this. probably too tired now, thanks again :smile:

@BigCol ,

Actually this is a reasonable (mis-) conclusion on your part since the WHEN part of rules uses a literal “OR”. The implementation of “OR” operations is not symmetric at the rules level - so the abstraction of testing for (any-of- multiple-truth) is somewhat schizophrenic at the UI level.

Likewise with “AND” (ie “&&” in THEN clauses) since the WHEN part of rules does not support any (all-of-multiple) conditions — for valid reasons discussed elsewhere on the forum. (short version-nothing is ever really simultaneous, so AND’ing in WHEN would never activate.)

Because of the irrational nature of an “AND” comparator in WHEN, the rules language designers had to decide between using only the || and && comparators in both WHEN and THEN , but not supporting && in WHEN or surfacing a new WHEN-only comparator in “OR”.

This is guaranteed to be confusing regardless of the implementation choice – you either imply a functioning && in WHEN or have different operators for one-of-multiple (“OR” or “||”) in the two clauses of rules.

(end of early a.m. discourse)

I’ll just add how you have to use “.state” to get an item’s state in rules but on the sitemap where you use an item’s state for thinks like color and visibility you do not As an additional inconsistency in syntax.
I’m sure the reasoning us the same. In rules there are lots of other properties on an item you can get but on the sitemap the state is all you can get so not using it avoids the implications that you can access others on the sitemap.