Hi!
How to introduce variable or constant in item configuration file?
You canāt - what would be the benefit?
Possible semantic translation issue hereā¦just PERHAPSā¦@tim06ka means an logical switch (for example) not bound to a real item. DK, though.
I think this is a valid question and one of the first i stumbled upon.
E.g. i set up 3 appartments with nearly identical layout. Using variables or parameters would drastically improve simplicity, modularity and reusabuility of the āappartmentā items (and sites, naturally). Now i have to manually copy&paste to create 3 different namespaces.
Items&Sites are DSL, but that does not mean that findings from other languages do not apply.
I was actually about to post the same question (assuming I understand it correctly.)
My use case would be the following:
I have some milights and a wifi bridge. What I would like to do is configure each zone with the same options (a switch for white, a drop-down for different colors, an on/off switch, etc.) This means I need 4N items configured to cover all zones (N being the number of different options,) while the only difference between them will be a single integer, indicating the zone.
This results in a copy-paste situation, which is ok for initial setup, but over time, maintenance becomes a chore (a la DRY principle in software dev.)
Further, allowing variables would remove the confusion that currently exists with magic numbers in bindings (which zone is 8 again? Does 7 mean all?, etc.)
Is there a better way to do something like this already? I am admittedly new at a lot of this.
Thanks,
Mark
Hi,
is there an answer to the question / topic above? Iāve got multiple copies of e.g. Homematic address strings in my Item file and would be more than happy to replace this by constants.
Cheers.
Rainer
Is there a plan to introduce variables in items file (I have same issue as @Rainer15)?
Cheers,
Your request is something that can be done with an exhaustive change of concept for the framework!
I have worked with thousands of items with various setups!
My advice for you is to create your own string builder for the items file! I have done it with sql and php for the end user!
The framework as it is in terms of textual configurations is using a parsing scheme!
If you are on linux and dont rely on an editor, use shell variables:
- in a items template file use shell variable syntax, like :$PLG_OFFICE_DESK_ID in this line:
Number PLG_OFFICE_DESK_temp .... {channel="avmfritz:FRITZ_DECT_200:$PLG_OFFICE_DESK_ID:temperature"}
- Then have the variables in a definition file, I use a file default.devices:
export PLG_OFFICE_DESK_ID=974a800c:087610273253
- Then, process the file into the real default.items using this one-liner:
source default.devices ; envsubst < default.items_tpl > default.items
(envsubst is a utility in the debian gettext package)
Of course you can turn this one liner into a more elaborative script, processing all config filesā¦