[SOLVED] Problem with upper and lower case


I’m trying to get an item with ScriptServiceUtil.getItemRegistry.getItem(itemname).
The problem is that the string (itemname) I’m using is lower case and my items contain some upper case letters. So the item is not found and I get an error.

Is it somehow possible to iterate over all items, convert the item name to lower case (.toLowerCase) to compare it and then get the right item?

Thank you!

Best regards

In what context, in a rule?

What you could do is put likely target Items into some Group, and iterate through the group extracting yourItem.name and manipulating that string as you like.

Yes, this is possible

from core.log import logging, LOG_PREFIX#, log_traceback
LOG = logging.getLogger("{}.TEST".format(LOG_PREFIX))

item_name_to_find = "Virtual_String_1"
matching_items = [item for item in itemRegistry.getAll() if item.name.lower() == item_name_to_find.lower()]
if matching_item == []:
    LOG.warn("Item not found")
    LOG.warn("Item found: [{}]".format(matching_items[0]))

Please write an additional information, that this is not DSL Rules code :wink: DSL Rules are not yet deprecated, and it’s confusing users.

Thank you… I meant to include this…

I have a DSL version committed to the helper library docs…

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

            rule "Test DSL rule"
                System started
                val item_name_to_find = "Virtual_String_1"
                var GenericItem matching_item = null
                for (item : ScriptServiceUtil.getItemRegistry.getAll()) {
                    if (item.name.toLowerCase == item_name_to_find.toLowerCase) {
                        matching_item = item as GenericItem

                if (matching_item !== null) {
                    logWarn("Rules", "Item found: [{}]", matching_item)
                } else {
                    logWarn("Rules", "Item not found")

@5iver: Thank you. That is exactly what I was looking for. Works great!