Get item list depending on a state

Hi,
I’m trying to get a list of items depending on the state of another Item. But currently I only get errors “Type cannot be derived” and I dont find my mistake.
Here a short snippet what I want to do in Openhab Rule:

  ...
  var rollershutter_down 
  if (setting_absent.state == ON){
    rollershutter_down = gRollershutter.allMembers 
  }
  else{
    rollershutter_down = gRollershutterDown.allMembers
  } 
  ...

Currently I’m not sure if its possible to filter items like that?
Perhaps someone has a hint for me? 0:-)
Thanky you

So you have two Groups, one named gRollershutter and the other named gRollershutterDown. If setting_absent.state is ON determines which of the members you get.

There is nothing wrong with this code as written, assuming that setting_absent is a Switch Item and gRollershutter and gRollershutterDown are both Group Items.

What line generates the error?

hmm, I’m not quite sure. But the following is logged:

20:46:19.263 [INFO ] [del.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'devel.rules', using it anyway:
Type cannot be derived
The value of the local variable rollershutter_down is not used

And I don’t know whats wrong with this code :roll_eyes:

Meanwhile i found another way to get the same result with:

    val rollershutter_down = gRollershutter.allMembers.filter[item |
      setting_absent.state == ON || setting_absent.state != ON && item.getGroupNames.contains("gRollershutterDown") 
    ] 

The rule validator is smart to spot if you create a variable, even set it, but then don’t do anything useful with it later. The snippet you showed us does not “use” that variable.

I know, the error message “The value of the local variable rollershutter_down is not used” is not my problem. Even if I use the variable, e.g. print to log or loop through, it’s empty and I get the other error messages “Validation issues found in configuration model 'devel.rules', using it anyway: Type cannot be derived

You might have to give in and reveal the rest of the secret rule.

There is nothing secret about this rule :grimacing::

rule "devel"
when
  Item date changed
then
  var rollershutter_down
  if (setting_absent.state == ON){
    rollershutter_down = gRollershutter.allMembers
  }
  else{
    rollershutter_down = gRollershutterDown.allMembers
  }
  logInfo("Notification", rollershutter_down)
end

results in

13:05:53.756 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model 'devel.rules'
13:05:53.813 [INFO ] [del.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'devel.rules', using it anyway:
Type cannot be derived

rollershutter_down isn’t a string, and I don’t suppose the validator can guess what kind of object it might be at this point, so it cannot work out if can be coerced to a string
Try
logInfo("Notification", "My variable {}", rollershutter_down)

Mind you -

having an Item named date looks like a recipe for keyword confusion.