I have a large number of similar rules which wait for an item to change and then call a function passing the changed item ans a similar named item and an integer like this.
when Item LivingRoomTV_Power_Raw changed then
when Item Server_Power_Raw changed then
All the items I am checking if changed are in a single group. I can change there names too if needed. Is there anyway I can merge all these rules with some wildcards or something?
If they are in a group, I would create a rule based on the group change. Using persistence, you can determine which item caused that change. An example here: Which Item updated my Group Item?
Yes, since OH2.2 you can use the triggeringItem.
But you still need to think about the different values you want to use in your function (x). You could use a map based on the itemnames (x=transform(“MAP”, “powermap.map”, triggeringItem.name)) perhaps, or simply static unbound items.
From the triggeringItem it is most simple to add some postfix, but you could also split the name of the triggeringItem. Your Item ServerPower could renamed here into ServerPower_Raw_NOT_RAW.
Item LivingRoomTV_Power_Raw changed or
Item ServerPower_Raw changed
val notraw = gNotRawPowerGroup.members.filter[i|i.name==String::format("%s_NOT_RAW",triggeringItem.name)].last
filter.apply(triggeringItem, notraw, x)
Another alternative is to trigger the one Rule by all your Items and then the triggeringItem variable will be the Item that caused the Rule to trigger.
This eliminates the dependency on persistence and timing.
There is work underway to be able to identify the Item that caused a Rule to trigger when using a Group to trigger the Rule, but it is not yet merged.