How to use the trigger item name in a notification?


I’m getting to the stage now where I want to send notifications about certain types of events either as emails or prowl notifications. Here is my example:

rule "Perimeter zone notifier"
when        Item ZONE9_GENERAL_STATUS changed to OPEN or
            Item ZONE11_GENERAL_STATUS changed to OPEN or
            Item ZONE12_GENERAL_STATUS changed to OPEN or
            Item ZONE18_GENERAL_STATUS changed to OPEN or    
            Item ZONE19_GENERAL_STATUS changed to OPEN or
            Item ZONE20_GENERAL_STATUS changed to OPEN or
            Item ZONE21_GENERAL_STATUS changed to OPEN or
            Item ZONE22_GENERAL_STATUS changed to OPEN
        if(perimeterSwitch.state == ON)    {
            pushNotification(prowlApiKey, "Alarm", "Perimeter alarm activity", 1)

Which works fine. But I’d like to be able to append the zone that triggered the event to the message. And possibly then map that to something more meaningful to the recipient of the message. I could make a rule per zone, which would work but is very bad programmatically. I suspect the solution would be to define all the items in a group and somehow extract which item triggered the group to use in the message. Plus having a re-usable .map file would also be something that would be very useful.




Thread::sleep(100) // give persistence time to catch up so lastUpdate works
val triggeredItem = gMyGroup.members.sortBy[lastUpdate].last

You must have persistence configured and your events must not happen closer together than the sleep. That is the best I’ve been able to find.