Initial Setup - Cloning Things, Items, and Rules

Hello everybody,

i have a SETUP QUESTION… how would you go about Cloning things, Items, and Rules

I have 5 Rooms with 5 Same hardware setups… - everything works trough MQTT

EACH ROOM HAS, 12 Relays, 2 Sensorboards with (every board has Temp, Co2, Light, Radar, Power counter)

So each room has about 30 Mqtt Topics - and the only thing that changes is the first (SERIAL NR. of the MQTT gateway (the number code before the first /)


one room

other room

i would like to setup one room with things items and rules. and then just duplicate everything and only change the first number code of the MQTT gateway.

What is the best way to proceed?


Are you using the UI to setup your Items, or files?

The best way depends on what you are comfortable with.


  1. Open the “code” tab of one of your MQTT Things and copy the YAML there. Create a new Generic MQTT Thing, open the code tab there and paste. Edit the pasted YAML as required.

  2. Query for the Thing using the API Docs (under Developer Tools). Copy the JSON. Go to the create Thing endpoint, paste the JSON, edit as required and submit. Repeat your edits and submits for each subsequent Thing.

  3. NOT RECOMMENDED: Stop openHAB. Open $OH_USERDATA/jsondb/org.openhab.core.thing.Thing.json, copy an entry, paste it and edit it in place.

  4. Use .things files


  1. Define the Items in .items files and leave them there.
  2. Define the Items in .items files and paste them into ‘Create Items from text definition’
  3. Use “create equipment from Thing” to create the Items (recommended approach if you are using the semantic model).

i am not using anything yet… what would be the best way…
is it smart to set one room in the UI and then duplicate it in the code?


That is what I would recommend. The UI is pretty self explanatory and shows you all the options.

NOTE: The trick of copying and pasting from the “Code” tab can be done on a Channel level. So you can create one Channel, copy the YAML, and then paste/edit that for subsequent Channels. But that is only really useful if they are the same sort of Channels (e.g. all the Number Channels but not the Switch Channels) because the different Channel types have different properties.

and what about the rules then? when i have all the things and items and channels set up?

can i generate rules for one room
i want all the lights to work in a similar manner.
heating also
rollos etc

and then copy to all the rooms?

How similar? If really similar it’d probably be better to just make the one rule (e.g. one rule to handle lighting). Rules define behavior and functionality so they tend to be written and organized around the functionality they provide, not the rooms they operate in.

It is almost always worth while to avoid duplicated code so you wouldn’t want to have separate rules for each room, unless the behaviors are really different.

1 Like

its the same rule… but different movement sensor turns on different lights

one room
turns one

other room
turns on

just the prefix (in this case “021991464317” and “0235610921FB” of the CHANNEL changes

OK, but by the time you get to a Rule you don’t know nor do you care what MQTT topic it comes from, or for that matter that it’s MQTT at all.

You have a montion sensor represented either as a Contact or a Switch.
You have Lights.
You have complete control over how the Item representing the motion sensors and the Lights are named.

So, assuming you have one motion sensor named “KitchenSensor1” and one light named “KitchenLight1” we have

sendCommand("Sensor", "Motion", "ON")

Now, as long as you are consistent in naming your sensor and light Items, you can use this one, one liner script, to control all of your motion sensor controlled lights.

Just put all your motion sensors into a group and use a “Member of group changed to ON” trigger to kick off the rule.

If you have more than one light controlled by a given motion sensor, create a Group:Switch using this naming scheme. Sending a command to such a Group will command all the members of that Group.

1 Like

…so with this script… if the kitchensensor1 triggers, it will turn on the KitchenLight1.
If the Bathroomsensor1 triggers it will turn on the Bathroomsensor1?
or do i need a separate script for each room?

… sorry for my newbienesss :slight_smile:

Correct, assuming you stick to a consistent naming convention for the Items. Note that case matters.

You only need the one rule and it will handle all of your rooms.

You don’t want duplicate copies of rules because if you have N rules, you have to make N edits every time you want to change the behavior of your lights. This way you can make one edit and it applies to all your rooms.

1 Like