As @rossko57 indicates, lambdas are not thread safe. And you’ve not provided your Group Item’s definition so it is certainly possible that it’s churning through the series of updates when the Group anyway. For every one change to a single member of a Group, the Group itself will receive N-1 updates where N is the number of members. So it certainly is possible that the error is that the Group is processing an update when the rule runs. Such errors tend to be intermittent and depends on timing.
Without seeing the actual code, the lambdas and the rules that use them, it’s hard to provide good recommendations for ways to proceed. Some comments with the lambda you did post:
- It’s more concise to define the lambda as
val execStd = [GenericItem item, OnOffType onOff, Boolean autoAwayMode, String modeSuffix |
]
Get rid of the "done"
when defined this way because this is properly a Procedure, not a Function and therefore has no meaningful return value. So why force it? The engine is smart enough to figure out what you want without being explicit in this case.
-
Use findFirst instead of filter…head.
gTradfri_Mode.members.findFirst[dt | dt.name == modeItemName] as SwitchItem
-
Because the Group search might be the actual problem, use the Item Registry to access the Item instead (see the Item Registry section of Design Pattern: Associated Items).
-
In general rossko’s advice is spot on. Global lambdas in Rules DSL is a code smell in my opinion. They are really only useful in a few rare circumstances. A better approach is to write the one rule to handle your lights and use things like Associated Items DP to figure out what to do.
-
If you can’t figure out a way to make this into one rule, perhaps it’s time to move to one of the other rules based languages which do support functions and classes and libraries and such.