Help with group avg

See Design Pattern: Working with Groups in Rules

val sensors = SensorGroup.members.filter[ s | s.lastUpdate !== null ].filter[ s | s.lastUpdate.after(now.minusSeconds(10) ]
val sum = sensors.map[ state as Number ].reduce [ s, v | s = s + v ]
val avg = sum / sensors.size

All of the members of SensorGroup must be saved to persistence.

A better alternative, imho, is to use the Expire binding you set the sensor Item to NULL if it hasn’t received an update for too long. Then the first line above becomes:

val sensors = SensorGroup.members.filter[ s | s.lastUpdate != NULL ]

and it doesn’t require persistence. And the NULL is a good indicator to both your Rules and where you are displaying these sensors that it has not been updated so cannot be used.

In fact, I’m not certain but the AVG function may work with the NULL states on the Item so you won’t even need the rule. I’m not positive about that though.