OpenHAB 4.04 duplicate things and linked items

I set up a Tasmota Smart Plug using MQTT.
Works fine.
So I bought 4 more.
Since its quite a lot of work to set them up, I was wondering, if there is a way to copy the thing and change the name.

I did that with the thing code. So far thats a success, but I didn’t find a way to copy also the items linked to the channel.

The general process using the UI is:

  1. Open the “Code” tab for the Thing

  2. Copy the YAML you find there to the clipboard after “label” (the second line)

  3. Create a new Generic MQTT Thing

  4. Open the “Code” tab for the newly configured Thing and paste the contents over everything after “label”.

  5. Modify what ever needs to be modified.

You could also use the API Explorer.

  1. Query for the example Thing. Copy the JSON you get back.

  2. Got to the create Thing endpoint and paste the JSON into the body.

  3. Make what ever edits you need (don’t forget to at least change the UUID).

  4. POST the modified JSON.

  5. Repeat the edit and POST steps for each subsequent Thing.

Using the API Explorer can be a bit faster as there is less clicking around. However the JSON is a little harder to read and understand. You’ll have to decide which is more of a pain.

Yeah, I guess I wasn’t clear.
I did it that first way. Just created a new thing with just an UID and then past the “code” into it and changed the names of the chanels.
Thats ok, but I didn’t figure out how to copy the things items.
Since the Smart Plug has 10 channels/Items I would love to copy that as well.

I just had a quick look at the API Explorer.
Am I right, that I can query the things items? I will get the response with all items code. Then I change the code according to the new thing and “post” it?
This will create the new items under the new thing?

Thanks!

Items are not Things. They are their own thing (pun intended).

The easiest thing to do would be to use “Add equipment to model” or “Add points to model” from the Channels tab. That will let you create Items automatically linked to the Channels you choose.

No, Items are independent entities and their only association with the Thing is the ItemChannelLink.

Well, I think I get the concept of Things and Items and Channels.
My question is: how to duplicate the things’s items (channel links)

Thing1

  • channel1.1
    • item1.1
  • channel1.2
    • item1.2

Thing2

  • channel2.1
    • item2.1
  • channel2.2
    • item2.2

I am able to copy the thing and it’s channel, but still have to make a manual link and create each item.
If I have 100 Things of the same kind, I want to copy also the links and and change a suffix to make it unique.

This cannot be done easily for Items.

The easiest would be to copy the Things and then use “add equipment to model” to create the Items linked to the new Thing. Just about anything else is going to just as much if not more work than that.

To duplicate the Things though you can:

  1. Create the first Thing
  2. Open the code tab and copy the YAML you find there
  3. Create a new Thing
  4. Open the code tab and paste the YAML there, edit as necessary

Alternatively:

  1. Create the first Thing
  2. Go to Developer Tools → API Explorer → things
  3. Query for the Thing created in 1, copy the JSON returned
  4. Open the “create thing” endpoint, paste in the JSON, edit as necessary (be sure to change the UID) and submit

I read quite often about things and item files.
Is that still a way in OH4 to edit items?
Where can I find the item file?

Yes.

The file locations and syntax is documented in the Configuration section of the docs. For Items see Items | openHAB