I’m checking whether it is considered “correct” or at least “acceptable” to add custom metadata to .items files as shown below eg specifically the room="Study" part.
I couldn’t see anything in the items section of the docs to specifically disallow it, but also it wasn’t specifically allowed. I read some dated posts that discussed this, but they are now a little old. I can see that it works (OH4.3.3), but I am wanting to confirm that I’m not trying to do something that ought not be done.
I know I can set custom metadata using the UI, but I’m not quite ready to go there yet.
Sure! Not only is it correct, it’s incredibly powerful and can be used by many parts of OH. For example, oh-repeater can read and configure widgets using custom Item metadata. You can read and write Item metadata from rules (except in Rules DSL).
If you can do it though the UI, it’s officially sanctioned.
I personally use Item metadata in some of my rule templates to override settings on an Item-by-Item bases (e.g. Debounce, Threshold Alert, etc). In another set of rules I use it to mark certain lights as having been overridden so they no longer change based on the automation for a time.
However, room = "Study" gives me pause. If that’s all there is to it, are you sure a tag wouldn’t do the job? Usually, when you have Item metadata, it’s because you need a more complicated structure, not just a single value.
Also, that looks like you are trying to recreate something the semantic model provides for you. If you set up the semantic model, you could use the following.
const myItem = items.hue_Study_Lamp_Right_Switch;
const room = myItem.semantics.location; // Room is a Group Item
console.info('This Item is in ' + room.label);
This too can become very powerful. For example, I trigger a rule when certain Items go to UNDEF which indicates they’ve stopped reporting. I find the corresponding status Item so I can set it to OFF using the semantic model.
Thanks for the response. The room example was just to illustrate - the actual implementation is to apply different switching rules to hue lights (via scenes) vs zwave lights (via simple switches).
I applied the tagging to my .items and it all seems to work which is great and I appreciate the reassurance that even if it were to be blocked at some stage I could easily update the item via the UI.
At some point in the future when I have more time I’ll need to explore the semantic model more closely