This is Rules DSL and this is using basic Rules DSL syntax.
Any time you see [ something | some code]
what you are seeing what’s called a “lambda” which is a function without a name. Stuff before the | are arguments passed in and stuff after is the code to run.
You can do anything inside a function that you can do outside a function. It’s just code. But it follows the same syntax and requirements as any code.
In Rules DSL a lambda comes in two types: procedures and functions. A procedure is a lambda that doesn’t return anything. A function has a return value. The last line executed in the function is what gets returned.
Some places where a lambda is used require a procedure (e.g. createTimer
) and others require a function (e.g. anything that is used by a List).
This is basically nonsense no matter where you used code like this in Rules DSL.
filter
takes a function and it expects that function to return a boolean (true or false). If the filter function returns false it excludes that element from the filter. In the end you’ll end up with a list containing only those elements that passed the filter function. It passes one argument to the function which is the current element of the List to check.
So, same as you would test for this in an if statement is what you’d do in a filter.
.filter [ i | !i.name.contains("Entrance") && i.state == OFF ]
Or you can do two filters:
.filter[ i | !i.name.contains("Entrance") ].filter[ i | i.state == OFF ]
head
gets the first element of a List and .state
is returning the state of what is presumably an Item.
See Design Pattern: Working with Groups in Rules
Pretty much all the other rules languages except Blockly do this better as the syntax is more standard. Rules DSL takes a bunch of shortcuts and uses weird conventions which serve to obscure rather than inform.
All of this is basic Xtend syntax and capabilities and have nothing to do with openHAB itself. Therefore what documentation there is is on the Xtend reference docs which are linked to from the OH docs.