OH3 - importing items and a Semantic Model

I have a large OH3 setup comprising 1236 items inside 9 items files. As my system started in the OH1 days the Items files have minimal information other than Item Name, group membership and connection to things. Label and icon information are defined in the Sitemap.
I’m thinking of using “Add Items from Textual Definition” inside the admin GUI to get rid of the items txt files and would like to add extra information such as location and function tags as I do the import.
Is there an easy way of doing this other than adding all the missing information to each items file before I do the import?

Yes but you will probably not like it.

Go to the Model settings and create your Locations model. The click on a Location and choose “Create Equipment from Thing”. Select your Thing and recreate your Items that were linked to that Thing.

I started out importing my Items from my old text configs and simply recreating the Items from the model ended up being way less error prone and way less work over all.

I thought it would be a “labour of love” :slight_smile: but figured I’d ask just in case.
I’m just started exploring semantics so I suspect this’ll be a spare time job for a while!
Overall OH3 seems very good though

1 Like

I’ve gone all in on the UI and am happy with the result. Everything that can be done through the UI I’m doing through the UI including rules.

I definitely can see the sense of that.
Can you import old style rules into the GUI, and is there error checking in the style of VSCode? I guess eventually I’ll have to learn the new rules engine, but for now I have 381 working rules I can edit with VSCode and a GUI that often hangs when I go to the rules page

Sort of. If the rules are Rules DSL and depend on global variables then no. You’ll have to rethink your approach as there is no place to put a “global” variable in Rules DSL Script Actions/Conditions. If using Python or JavaScript there is a way to save the value of a variable from one run to the next of a given rule (in JavaScript this.myTimer = (this.myTimer === undefined) ? null : this.myTimer;) but you still can’t share a variable between rules.

I’ve not used Rules DSL in the UI. I gave up on Rules DSL long before OH 3 came out. But for JS there is as much error checking and intellisence as there is for JS code written anywhere. I imagine Rules DSL would have something close to VSCode in that respect.

Thanks, it seems like its easier to leave things as they are for now and then once I’ve got rid of my items files I’ll explore the new rules engine on my simpler rules. I don’t have that many global variables as I migrated many into items previously. I’m guessing something like this needs moving to an item based store?

var myNumber = 0

rule "test"
when Item MyItem changed then
if (myNumber > 0 && myNumber< 10) {//do Something}

rule "reset variable"
when Item MyOtherItem changed then
myNumber = 0

Yes, to keep the rules as is you’d use an Item. But I’ve found that often times there are alternative approaches that would eliminate the need to keep track of myNumber in the first place.

Another alternative is to use Item Metadata which, when using the non-Rules DSL Languages, you can read, add, and modify data on an Item. So, for example, I have some lights that get controlled during the day based on the weather (turn on when cloudiness > 50%). However, if the light is controlled manually I don’t want to change the light’s settings based on the cloudiness any more. So I set an “overridden” metadata on that light switch Item to indicate it shouldn’t be controlled any more by the cloudiness rule. Without the metadata I’d have to either keep track of that in a Map in the rule or as separate Items.


That’s an interesting piece of extra functionality. I’ve got one particular rule that could be simplified a lot… It has a lambda which gets the name of an item, then creates new item names by adding bits to the end of the original item name before getting a generic item from each new name which is then used for further processing. It works well but its a challenge if something needs tweaking and I haven’t looked at it for a few months.
Once I have more spare time I’ll revisit my rules and see what I can simplify