Low Battery status without group

Hi,

to check the Low Battery status of all my HomeMatic things I want to avoid to add all the items in a special group. I created the following rule. Unfortunately I found no way to get the thing from item th have a real reference to the BatteryType property. Instead I have to use a guessed name of the battery type item. Does anyone know a way to get the item the item is linked to?

  
import org.eclipse.smarthome.model.script.ScriptServiceUtil

rule "Batteries"
when
    Time cron "0 14 20 * * ?"
then

    var meldung = ""
    val myItems = ScriptServiceUtil.getInstance.itemRegistry.getItemsOfType("Switch")
    myItems.forEach [ myItem | {
        if(myItem.getCategory() == "Battery") {
            if(myItem.state == ON) {
                val thingname = myItem.name.split("_").get(0)
                val myBatteryType = ScriptServiceUtil.getInstance.itemRegistry.getItemByPattern(thingname + "_*BatteryType")

                if(myBatteryType === null) {
                    logWarn("Battery test", "{} unknown type", thingname)
                    meldung += thingname + "\n"
                } else {
                    logWarn("Battery test", "{} {}", thingname, myBatteryType.state)
                    meldung += thingname + ": " + myBatteryType.state + "\n"
                }
            }
        }
    }]
    if(meldung != "") {
        sendPushoverMessage(pushoverBuilder("Batteriewechsel:\n" + meldung))
    }
end

Didn’t try, but maybe this helps:

https://community.openhab.org/t/get-thing-from-item-to-tell-item-status-e-g-online-or-offline/37542