Configuration as code (files for things) vs UI

Hi Openhabians,

I configured a couple of things, models, items via the openHAB 4 UI and well it works just fine.

I would like to benefit from “configuration as code”, having everything stored as files such as .things, .items, etc versioned within a Git repository (This way I get a totally versioned IoT configuration)

Surprisingly, openHAB is not automatically generating these files when we use the UI.
(I was expecting so: TLDR; the UI is “just” a friendly way to write these files into the file system. But it appears it is not. (Fair enough probably for valuable reason, (if you think it can be a feature to add I am willing to contribute to it :slight_smile: please let me know)

Is there an easy way to convert all what I configured with the UI to files (.things, .items, …) ?

Thank you for your guidance here

Cheers

All UI configuration is stored under userdata/jsondb in human readable files, included backups. These can also be saved on git to have a versioning. But be carefull to not edit thoses files while openHAB is running.
Searching the community you will find some tools to export items and things.

Hi @hmerk,

Thank you for your answer I actually found a script but it’s quite of old…

I will give it a try then, I guess in the worst case I just restart everything using files directly :slight_smile:

Best

Well, even it is old, it should work as the files did not change that much.

Of course the current file based configs will remain supported for the foreseeable future. But if you were to take on creating a way to migrate between file based configs and managed configs, there was an aborted attempt (more personality issues than technical) to define a YAML format for all these entities which match the YAML you see in MainUI. That normalization of the configs would be a huge step towards enabling migration between the two.

The challenge with the current .things et al formats is that there is no writier and working with Xtext, the grammar used to define these formats, is reportedly very difficult and there are few around who have both the knowledge and the willingness to create a writer using that grammar.

Hi @rlkoshak very insightful context, thank you for taking the time to share it with me.

Are you aware of the strategy/vision that openHAB projects wants to see in the future regarding configuration?

Basically, is the intent to end up with “config files” (= the UI creates config files such as .things etc and maybe keep jsondb just as a “runtime db” populated with all the “things files”)

or the other way: having config files ending up synched within “jsondb” and keep the UI writing directly to jsondb? (being just used as a “populating/import” script?)

or another way ? :slight_smile:

I think there is a misunderstanding.
Config files and jdondb config coexist and there is no plan to remove this.
But there is no syncing between the two.
You will find file based configured Things or Items shown in the UI with a lock symbol indicating it cannot be edited in the UI,

Thank you it’s more clear, so the idea is to preserve both sources of truth not converge to a single one.

Understood :+1:

After digging more and more into the documentations Configuration | openHAB

Some recommendations are there. Seems that “using files” for configuration is not really the recommended approach File-based configuration is still available, but we recommend that everyone start over with a fresh setup built using the new Main UI.

Just in case someone comes along here, here is my .gitignore I use for my config. Note that I have a Docker config and my conf and userdata folders are both in the same parent folder. You can achieve the same using symbolic links for an installed OH.

userdata/*
!userdata/secrets
!userdata/etc
!userdata/jsondb
!userdata/config
!userdata/habot
!userdata/openhabcloud
!userdata/uuid
!userdata/zigbee
!userdata/zwave
userdata/jsondb/backup
userdata/backup
.Trash-1000
conf/html/hum.jpg
conf/html/light.jpg
conf/html/power.jpg
conf/html/temp.jpg
conf/automation/lib/javascript/personal/node_modules
conf/automation/js/node_modules/*
!conf/automation/js/node_modules/rlk_personal
*py.class
*.swp
*~
*.old