Structures or Objects to group Items?

:+1:

Good question. @ThomDietrich used to have this power. He hasn’t been around for awhile so I don’t know who would have that ability. I’d say in the mean time let’s just use Tutorials and Examples and tag with JSR223. They can be moved later if needed.

Properties supports plain old map files. No need for XML and XML is not what I had in mind. So test.properties would be:

key1:value1
key2:value2
key3:value3

You can use = if you prefer. I don’ think , is supported like your last example though.

No one wants to write XML by hand. Yuck.

Just use prop.load(new FileInputStream(propFileName)

But for your multidimensional example you would have to use namespace hierarchy:

Morning.Low_Lux_Trigger:20
Morning.Level:1
Day.Low_Lux_Trigger:50
Day.Level:55
...

Since Properties is already a HashMap, why do you put the contents of it into another HashMap?

Your Rule could be:

import java.util.Properties
import java.io.FileInputStream

val prop = new Properties

rule "Test"
when
    Item Virtual_Switch_1 received command or
    System started // presumably one would want to load this at startup
then
    val String propFileName = "/opt/openhab2/conf/test/test.properties" // the name of the file really doesn't matter
    prop.load(new FileInputStream(propFileName))
    logDebug("Rules","Test: [{}]",prop.toString)
end

// In your Rules
    val value = props.get("key1")

But my Item labels that I want to display on my sitemap bear little to no resemblance to the name I want to use in my alert messages. So on my sitemap I might use:

image
but want my alert to read:

“The following doors are open and it is after dark: garage door 1, back door, and front door.”

I can’t use the Item label for both. And it’s a DP. That one use case (i.e. converting Item names to friendlier Strings) is just an example. It isn’t the only use case the approach is useful for.

If we apply the DP to this use case we can trade some inefficiency (i.e. the file gets loaded every time you need to access a value) for fewer lines of code.

// In your Rules
    val value = transform("MAP", "test.map", "key1")

If you are pounding the file you will probably run into performance problems but if you are not, in my experience, I’ve seen no measurable performance hit. Though like I often say, performance is almost never a problem in the home automation space.

The reason why I mentioned cat is because that rule could collapse down to:

import java.util.Map

val Map<String, String> test = newHashMap

rule "Test"
when
    Item Virtual_Switch_1 received command or
    System started
then
    logDebug("Rules","Test: Start")
    val String filePathString = "/opt/openhab2/conf/test/test.txt"
    val props = executeCommandLine("cat " + filePathString, 1000).split("\n")
    props.forEach[ line | 
        val parts = line.split(",")
        test.put(parts.get(0), parts.get(1))
    ]
    logDebug("Rules","Test: [{}]",test.toString)
end

Obviously I’m missing some error handling and it would only work on a machine that has cat (sorry Windows users). I would add some in when I write it up as a DP.

Though maybe this is just a special case for the Human Readable Names DP and not a DP unto itself.