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?
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.
I have a DSL version committed to the helper library docs…
import org.eclipse.smarthome.model.script.ScriptServiceUtil
rule "Test DSL rule"
when
System started
then
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")
}
end