Is there a way in OH3 to bulk add 100 items t a group?
Have you the them currently setup in .item files. You can paste directly into the new GUI.
When adding an item select
‘Add Items from Textual Definition’
But if the items already are created in GUI?
I think i need to change to have items in file configuration instead if i need to rename or do bulk changes.
A powerful but dangerous method is to edit the jsondb files with a text editor. They are located in the user data directory. Openhab must be stopped because it continuously access to these files. I tried once, after reading posts by rlkosh.
Change may need to be performed in more than one file. If the change is not consistent corruption can occur so you need a back-up.
can you find the item for your group in the UI?
if you open that item you should see 3 main parts:
(edit: sorry just saw depending on how you created the group there can be more than 3 parts… - Tags, - Semantic Classification, e.g.)
- Direct Parent Groups
- Direct Group Members
at “Direct Group Members” you should have a button “Change”. Hit it and you’ll see a column “Members”, click on it and a new window will open with all Items, checkmark everything you want to add, close the window and select apply
That is what i don’t want to do for 100 items.
I am now removing all my items and putting them in config files instead, then i can do bulk changes and renames.
If there was possible from group to choose what items that should be included and a way to rename items then i could stay in GUI.
There is need to be said (and it is in documentation as well), if you are not simple user … avoid UI for items/things and probably rules as well.
Do everything in files (and not really in jsondb files - use conf folder as in OH2), its way too quickier and easier to maintain than hundreds of clicks to edit just few items here and there.
UI is nice, but not very good for maintenance.
not sure if i was clear enough…
the way i described it you can checkmark all of the items you want to add to group.
You don’t have to repeat each step for each item you want to add.
Yes, checkmarking 100 items isn’t easy/fast either but i’m not sure if you are faster creating files and adding them to the group in a text editor…
Thank you @Raven now i have learned how to bulk add items to a Group and if i need to rename items i can do that in in jasondb files.
I try to stay in GUI.
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).
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.).
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.
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.
This is useful to know. I was wondering how was openHAB managing to remove items when I renamed them from the text file.
Sometimes, during my tests going back and forth between UI and text files I ended up with locked items that were still present in the UI but not in the file (it happened for things too). I was unable to figure out what was going on.
Probably it depended on the fact that either I renamed the items file or that the file was totally empty, which appear as an error in the log.
I’ll pay attention to this aspect next time.
As usual, many thanks for your clarifying posts.
Most likely you still had Links hanging around. I’ve seen this when Items are defined in .items files but linked to Channels through the UI. When you delete the Item from the .items file, the link remains. And because the Link remains OH still thinks the Item exists.
Another thing to be wary of when renaming Items, and one of the reasons why it’s not supported. The Item Name is the UID for the Item. That UID is used in a number of separate places to identify that Item including:
- Item Metadata
- external scripts that may publish to the Item through the REST API
All of these are separate from the Item itself. So when you change the name of the Item, you have to update that name in all these other places too.
I havent said nothing about recommended way, I said it’s in documentation in terms of file/ui driven differencies pros/cons