Is it possible to persist single commands of a Rollershutter?

There are lots of caveats with this, but you can with a little hack. Assuming all members of the group are persisted:

val triggeringItem = gGroup.members.sortBy[lastUpdate].last

This will return the most recently updated Item from the group.

Now for the caveats:

  • sometime it can take a couple hundred msecs before persistence catches up with the event so you may need a Thread::sleep before the above.
  • if multiple Items can be updated really close together you may lose one of the events and process the latter one twice
  • if you trigger the rule by gGroup received update your rule will be triggered multiple time per Item update. The other triggers on gGroup will not work the way you want. So you might need to trigger the rule on the individual Items but you can still use the above in the rule.

The last caveat is key so I will repeat and elaborate. If using a Group as the Item to trigger a rule in order to execute the rule when one of the Group’s Items are updated or commanded, you must use Item gGroup receive update.

When you use Item gGroup received command the rule will only trigger if you send a command to gGroup, not its members.

When you use Item gGroup changed the rule will only trigger when all of its members are the same state and one of them changes which causes a change to the gGroup’s state. For example, if all the members are Switches and they are all OFF, the rule will trigger when the first one changes to ON but it will not trigger again when the second, third, etc one changes to ON.

You should look at this thread for more examples of stuff you can do with Groups in rules.