OpenHAB 3 Bulk adding items to Group

Navigate to the Group’s Item page. Click on change under Direct Group Members and then click on “Members”. Search for or browse for your Items that you want to add to the Group. Put a check next to those. You can do multiple searches without losing the checks.

Renaming is something worth a mention. It is impossible to rename an Item, even in .items files. What you can do is delete an Item and then recreate it with a new name. And that’s what happens when you change the .items files. Every time the file is unloaded all the Items defined in that file are deleted. Then when the file is loaded all the Items defined in that file are recreated.

It would be better to go through the REST API where possible. I wouldn’t edit the JSONDB file except as a last resort, if for no other reason that OH has to be stopped to do so.

See above. Items cannot be renamed. But as described above be my and Raven, you can “bulk” add Items to a Group from the Group. You can add 100 Items to a single Group in one go.

Shouldn’t be any more. If it is let me know where so I can remove it. It has always been the recommendation to use the UI for Things. Now the implied recommendation is to use the UI because that’s all that’s presented in the Getting Started Tutorial.

This is probably one of the few cases where I would recommend this approach.

One final thing to mention. I written this a bunch of times in lots of different contexts and it keeps coming up. I guess I need to create a tutorial.

Making Bulk Edits to stuff defined in the UI

In OH 3 you don’t even have to install the REST API Docs separately any more. It’s right there under Developer Tools. So why should you care? Because if you, for example, have 20 similar Generic MQTT Things that you need to create, or you want to apply Expire metadata to 100 Items, or something like that what do you do?

There will always be a “text first!” user who will pop in and smugly say “that’s why I only use text configs.” But that’s not the only way to do the above in a relatively fast and efficient manner.

There are two approaches you can take though the UI to make these a bit easier. The first one, using the code tab, requires a few more clicks. The second one requires dealing with the RAW JSON (and no it’s not editing the JSONDB by hand).

Code Tab

Lets say I have a smallish number of very similar Generic MQTT Things. First create the first one in the usual way through the UI. Once created and working flip over to the “Code” tab and copy the YAML there. Now create another one and immediately flip over to the code tab, paste in the YAML and edit those things that are different (name, ID, topics, etc.).

REST API

This approach is best if you have a lot of repeated actions to perform and are OK messing with the JSON. As with the previous step, unless you are pretty good with the syntax, create an exemplar in the usual manner. Now query for that from the REST API Docs. Copy the JSON. Then go down to the “create” endpoint for that thing, paste in the JSON and edit it as required for the new thing. Submit and you’ve created a new one. Edit the JSON again and click submit. Repeat until done.

Both approaches work with Things, Item Metadata, Rules (yes rules) and just about everything else in OH except for Items. Only the second approach works for Items but be careful. There are a lot of concepts that users of .items files may thing are all part of the Item but which are in fact separate entities. For example the Link between the Item and the Channel are not part of the Item. The Item metadata similarly is not part of the Item. But of course, you don’t need the REST API to bulk create/edit Items if you want to. You can use “add items from text config” and use .items file syntax to bulk create/edit a bunch of Items.

5 Likes