How can item metadata be accessed in rules?

I know it’s new to the snapshots, but I can’t wait to be able to use metadata in my items. One use case is to add metadata to my dimmer items for brightness levels based on a lux value and time of day…

"DS_HallwayStairwell_Dimmer" -> (newHashMap(
        "Morning"    -> (newHashMap("Low_Lux_Trigger" -> 20, "Level" -> 1)),
        "Day"        -> (newHashMap("Low_Lux_Trigger" -> 50, "Level" -> 55)),
        "Evening"    -> (newHashMap("Low_Lux_Trigger" -> 90, "Level" -> 55)),
        "Night"      -> (newHashMap("Low_Lux_Trigger" -> 90, "Level" -> 1)),
        "Late Night" -> (newHashMap("Low_Lux_Trigger" -> 90, "Level" -> 0))
    )
),

I currently store this in a hashmap for my rules, but I think it will be less tedious to maintain in metadata. Can it be accessed in a rule (does the DSL have access to the MetadataRegistry), and if so how? If not, I assume the REST API can be used?

It appears the REST API can only add/remove item metadata. Hmmm…

@Kai, could you please help direct me to someone who could answer this, or maybe you can?

@sjka Can you help Scott?

1 Like

I am also interested in this. Is there any way to do it?

Me too… it will add more context to the item

Kai replied over here…

Why not? this would be a very nice feature to have!

Ok, If items metadata is useless for this, can you explain how do you declare and access this hashmaps? What I’m trying to achieve is to have a “user friendly” name for the items (actually named with ugly names such as “GF_LR_Lamp2”, and what to show “Living Room Lamp” in a rule fired text)

Ok, drop it. I will do it as in this design pattern: Design Pattern: Human Readable Names in Messages

In most cases, you can just use item.label instead of item.name. For the rest, you found the DP I would have pointed to. :slight_smile:

That made the trick. Thank you!!

1 Like

I figured out how to do this using JSR223…