Recurring items in the definition in Openhab

Have you encountered having to copy items in items, change their name or configuration?
The openhab code does not allow this possibility very much, resp. I couldn’t find a good solution via code in openhab.
That’s why I tried another way, which I will now describe.

First, You need to have the utility installed: when-changed. The utility can be found in other things as well.

Second, Verify that the envsubst command is available on your system.

Third, Write a script that will generate an output file from the input configuration file, which I chose in the format csv - delimiter “;”, and the input template file. All necessary values from the configuration file will be added to the output file.
The contents of the file can look like this:

export DOLLAR='$'
while IFS=';' read -r v1 v2 v3 v4 v5 v6 v7 v8 v9
    export f1=$v1
    export f2=$v2
    export f3=$v3
    export f4=$v4
    export f5=$v5
    export f6=$v6
    export f7=$v7
    export f8=$v8
    export f9=$v9
	envsubst < $2

Note. If the $ character is required in the template, then $ {DOLLAR} must be used instead.
Example of template file:

// ${f2}
String ${f1}EventName "Time ${f1} [%s]" <calendar> (CalendarEvents) { caldavPersonal="calendar:program type:ACTIVE eventNr:1 value:NAME filter-name:'${f1}'"}
DateTime ${f1}StartTime "Start ${f1} [%1${DOLLAR}tT, %1${DOLLAR}td.%1${DOLLAR}tm.%1${DOLLAR}tY]" <calendar> (TimeEvents) { caldavPersonal="calendar:program type:ACTIVE eventNr:1 value:START filter-name:'${f1}'"}

Example of config file:

Summer;event summer
Vacantion;event vacantion

Fourth - finally, it is then necessary to ensure that the script is run (ideally immediately after startup):

when-changed -s /srv/openhab2-conf/items/*.input -c ‘ %f %f.template > %f.items’

The script will look at all files with the *.input extension to see if they have changed. If any * .input file has changed, it searches for the *.input.template file and generates the *.input.items file. Openhab ignores other files in the folder items than they have the suffix * .items.

Finally, the idea of the whole: It has one universal solution for all households, which can be configured according to the user’s needs.