in a rule I am filtering according to the state “Off” or “On” this is fine and I get all switches whichare off or on. When I want to count the sum of all switches in this group. How can I filter correctly?
I tried
var Integer local_integer_countsum = group_house_doorwindow.members.filter[Switch m|true].size
Which rules language? This looks like Rules DSL. I’m pretty sure this approach won’t work for Rules DSL. You’ll need to test for instanceof instead of relying on the type not matching the filter argument. Rules DSL has a poor attempt at a type system and I’m pretty sure that it simply ignores the type in this case. It’s probably the primary reason I recommend against any new development of rules in Rules DSL.
Don’t give m a type. You really should almost never force the type of any variable in Rules DSL. It causes way more problems than it solves. In this case, trying to force the type to GenericItem (see below) can work against you becuase Rules DSL doesn’t usually look down the type hierarchy, only up. So it would never see that m is a SwitchItem.
I do see a problem with my version though. All the classes for Items end in “Item” so it should be