Import/Export Things / Items / Rules at openHab3?

Hello,

i think it would be great to import and export the configuration of things, items, rules, sitemaps, etc.
Is there an option i didnt find, yet, or maybe is it planned?

On OH2 i configured everything with textfiles but i would like to switch to the ui-based configuration. I am just missing to export my config without a full backup.

Greetings,
Alex

2 Likes

You can use openhab-cli backup/restore on both, OH2 and OH3.

However be aware that at least for the time being, you cannot upgrade that way.
The only supported way to upgrade is the standard one documented here.

We would highly appreciate any help with writing a migration tutorial and welcome anyone to do more migration testing in general, including openHABian.
Looking for someone to implement it to the backup/restore scripts, too.

At my OH2-Installation i am already using openhab-cli backup/restore to backup my system.
But with my config-files i even have the possibility to backup/restore/update/migrate just specific items/things/rules and so on. I hat some hope, that in OH3 it would be possible to use this option for ui-configured objects, too.

The import from text files was already a good beginning, now i am just missing the export :slight_smile:

Maybe I need more context to understand. For what purpose are you looking to export but not do a full backup? I’ve already opened an issue on github to have a way to save the YAML from the code view to a file directly instead of needing to copy and paste. Is that what you are asking for? Or something else?

What i really love at textbased configuration at OH2 is, that i can easily add, update and remove things / items and so on in a mass but also very controlled.
After a fresh install, for excample, i am used to upload my config files step by step. So i can always check if everything is working fine.

Actually i would like to do a soft migration (no big bang) from OH2 to OH3. There are some devices i could transfer right now to OH3. But there are other devices i would like to do some kind of “refactoring” at.
Also all rules should even run on OH2 and should be migrated step by step to OH3.
And i think it will take some time untill i have created a dashboard at the new and very cool ui.

So i think the hole migration could take some weeks or months in my case. If i would just work with full backups i think there would be a big risk to overwrite changes at the new system.

I think it would be really great if the would be an option to add and/or update objects by importing config files:
Case 1: Object from import file is not in database --> add new object (thing, item, …)
Case 2: Object from import file is already in database --> update the object with data from file

If one could also export specific objects from database, it would be really easy to do mass changes (export, change, re-import).

I hope this helps to understand my case a little bit more, even if i think there would be a lot more cases this import/export function could help at.

1 Like

OH3 is no different than OH2, it’ll “auto-import” things and items from files into memory where you cannot change them - they’re read-only from there on. OH3 unlike OH2 will symbolize that with a lock in the GUI.
OH3 also has a GUI option to import items as text lines one by one or in batches. They don’t get written to (text) files but into the JSONDB just like they do when you use the GUI to enter them (not sure if that also exists for things).

What you want (write things/items back to files) did not work in OH2 and will not work in OH3 so don’t bother asking for that, many did before - it will not happen because there’s a) no need and b) no library to write in that format, let alone a number of unresolved issues this would create.

A minor correction. It imports the text defined stuff into memory but it doesn’t save them back out to the JSONDB. It’s a little bit of a quibble but I think it’s an important distinction. The JSONDB is just the representation of what’s in memory as it gets written out to disk. From that perspective, the JSONDB and the text based configs (JSONDB is itself also text) are two ways to load stuff into openHAB’s memory and data structures.

But it could be possible to write out the YAML that we see in the code tab. And there are some use cases where that makes some sense, e.g. for more easily sharing and importing rules from others. I agree, writing out to .items files and .things files and .rules files syntax is unlikely to be supported.

2 Likes

Thanks for your reply - but did you recognize the opposition: many asked for it before vs. the is no need for it?

I know that it even doenst work at oh2, but this is in my opinion a real disadvantage - but i dont want to start the discussion again if the where so many before.

I am not a developer, my point of view is the one of a user. I unterstand the technical explainaiton why there is a difference, but as a user i really would like to import/export my objects and edit them in the ui, too. As a user i dont see a reason for a separation at this point.
And as a user i also would be very fine with a yaml-file. My point isnt the filetype, its the function.

That’s no contradiction as you can use the GUI for everything you need to do. It’s just some people don’t want to do it that way but that’s not a need.

If many people already asked for an aprovement, i think there will be a need for another solution.
Your explanation sounds a bit like “there is no need for a crane, the egyptians even built the pyramids without a crane”.
I understand the arguement, that a text file wouldnt be the best way to solve it - and agree to it, too.
But nevertheless i think an option export/import objects in generel would be a great feature. @rlkoshak mentioned another great use cases for sharing configurations…

4 Likes

Sorry for potentially hijacking this topic, but I agree with @e36Alex

I am currently thinking of upgrading from 2.5 to 3.0 - however, I only have one machine I can run OH on. You might argue that I could simply upgrade to 3.0 - but, as it turns out, when all of my items are automatically imported, I will lose a lot of functionality from 3.0, as those items are then not editable.

In addition, as Alexander pointed out, I want to take my time for the new model creation, getting rid of old leftovers which still might be existing im my installation and so forth.

All of this will take some time, but I don’t want to live without my smart home for that time, but it seems to be the only option if I upgrade from 2.5 to 3.0 - or am I missing something?

My “migration” is actually more like a complete new setup, what really takes it time.
I am taking my configuration step by step to OH3, while 2.5 is still running.
Maybe it could work for you, to start with a fresh install on a virtual machine, while your old setup is running. When your new setup is ready, you could update your productive setup to OH3 an then import the backup from the virtual machine?

Yes, a new installation on a new virtual machine is actually what I started right now, as well.
However, it meant additional work, since I have configured quite a few firewall rules with my original OH machine…compared to the actual new setup, though, the effort was definitely managable.

I would still like to keep my previous reply open, as I still believe it would be helpful to have a sound migration strategy.
Right now, if you do migrate, your old items are effectively locked out from OH3, at least you cannot configure them as easily as “new” items.

1 Like

That is no different from how it works in OH 2.5. You’ve not lost any functionality to define your Items in .items files. As it has always been, if you are using text based configs those configs cannot be modified in the UI. You have to make all your changes to the text files.

For Items at least, if you want to import those Items in OH 3, there is an option for that. Click on “import Items from text” when clicking on the + icon, and paste in the contents of your .items file.

But, if you are looking to rebuild and use the Model, you are probably better off using “create equipment from Thing” from the Model settings to recreate your Items than importing them from .items files. I started by importing a few hundred Items directly from my files. I’ve since abandoned that approach. It’s actually less work to recreate them.

The use of txt based configuration is something that pops up in a lot of threads, and I read you migrated away from txt to UI.
I think there are actually two separate discussions going on:

  1. how to set up a system, for which some users feel more in control and understanding how stuff works when using the txt based appraoch and others prefer a UI approach.
  2. how to backup your system (which is linked to how to migrate). I understand there are much better options to backup an OH system other than having a copy of your config files. However: for me, as a non IT guy, they are completely BlackBox with me stupidly typing, executing directions like a monkey.
    I’m not al comfortable enough with that to rely on it. In order for me to use OH3, I have to be able to more or less feel in control of what I’m doing, especially with regards to backup. As an example: I’m using OH for a year now and I absolutely love Habpanel. The only thing is that is hard to backup: it required met to really look hard for the config file and add an additional manual step to copy that file. I do not mind that this file is not easily readable but would really prefer the location of that file to be somewhere in the config section.

A good option for me would e.g. be that these config files would have a mirror file somewhere in the config section. That would allow users to easily backup, restore and migrate, without the need for a more professional approach that drives people away from OH. It could be a section of the config files which is clearly marked separately as “backup_of_config_files” section. I’m not sure how this would be setup. I would consider it a big step up if the mainUI would have a primitive interface to create a copy/restore these non humanly readable files.

But I could be missing some important technical issues. I’m just reporting what could help me as a non-expert.

I also upgraded from OH 2.5 to OH 3 this week.
With OH 2.5 I had everything in textual files, but I want to move over to UI creation.
Is there a way to delete the locked imported items? When I remove them in the .items file (or the items files completely for that matters) the items still stay in MainUI.

Edit: My bad - I was editing files in the openhab2 folder instead of the openhab folder…

First a compliment, OH3 really is a good next step, quite stable so far. Really congrats to all who helped !

I also just migrated (or actually in the process of system testing) from OH25 to OH3.
I have a system test setup and a production setup that can run in parallel (using Docker).

I like the UI to do configurations, but I would love to be able to put new or changed configurations of Things and Items into .things and .items files in order to be able to maintain my environment in the config files and move them from system test into production environment.

A simple instruction on how to move the JSONDB of YAML content into config files would really be appreciated.

I struggled now quite some time on the changed HTTP binding that I did have in config files in OH25 and would not work in OH3. I made new config in the OH3 UI defining new Thing with channels and items, but hate to redo that in the production environment.

1 Like

As a beginner, I’d like to export my model, and start a-fresh (on same version).
(Right now I’m struggling with two MQTT auto-discovered things that I cannot delete. They remain “Removing” until when I in beginner desperation restart, then they come online again. DOH)

From what I understand in that i read above that is not supported.

An hour into the “OpenHab virtual meetup 2020” Yannick imports the model from a text file.
Where did he get that one from?
To me it sounds a bit contradictory that there is no need…

1 Like

Not 100% sure what the question is, but @ysc imported his configuration from one of his *.items files.

If you want to you can configure the entire model in your *.items files;

just copy the files from userdata/jsondb. Even better, use openhab-cli backup and restore which will grab everything you need.

There model is created through Groups, Group membership, and tags, all of which can be defined in. items files.