Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Environment variables in configuration files #4537

Open
preinhardt opened this issue Nov 13, 2017 · 5 comments
Open

Environment variables in configuration files #4537

preinhardt opened this issue Nov 13, 2017 · 5 comments

Comments

@preinhardt
Copy link

preinhardt commented Nov 13, 2017

Hi,

it is possible to use linux environment variables in the configuration files?

The backround is, that I want to use the "HOSTNAME" in the configuration files.

Update:
In the configuration files I mean in detail the *.cfg files in services.
If that does not work, where would I have to insert this as an enhancement in the code (Unix/Windows).

Would this be accepted as a pull request?

@triller-telekom
Copy link
Contributor

Currently it is not supported to insert environment variables into those .cfg files. The (ConfigDispatcher)[https://github.com/eclipse/smarthome/blob/master/bundles/config/org.eclipse.smarthome.config.dispatch/src/main/java/org/eclipse/smarthome/config/dispatch/internal/ConfigDispatcher.java] is responsible for parsing these files.

Before you create a PR: May I ask what you are trying to achieve by inserting the HOSTNAME environment variable into the config file? I.e. what is your specific use case that you are trying to cover?

@preinhardt
Copy link
Author

I have posted my specific use case in the openHAB community chat forum.

https://community.openhab.org/t/additional-parameter-in-mqtt-persistence/36039

@triller-telekom
Copy link
Contributor

From the posted link I read that you are trying to send MQTT messages that have the HOSTNAME in their topic from openHAB/ESH to a MQTT broker, right?

So I am wondering if configuration files are the right place to touch here. You somehow need access to the hostname where openHAB/ESH is running on.

So where do you create your messages with your custom topic? Within rules? Then maybe you need to have a way to retrieve the HOSTNAME from within a rule in the ruleengine?

@philomatic
Copy link
Contributor

philomatic commented Nov 15, 2017

@triller-telekom You can define the custom mqtt topic to publish to via the mqtt.persist file:

http://docs.openhab.org/addons/persistence/mqtt/readme.html

Apart from this use-case:
I can imagine that using unix (and windows) environment variables in the .cfg / .persist files could come in handy, not only for MQTT ?

I'm thinking about system hostname for callbacks (is there (apart from java code) any other chance in ESH / OH2 to retrieve the system hostname?), locales and time zones, pwd.

@triller-telekom
Copy link
Contributor

I'm thinking about system hostname for callbacks (is there (apart from java code) any other chance in ESH / OH2 to retrieve the system hostname?), locales and time zones, pwd.

That's why I want to know where he needs access to the hostname. Because things such as timezone and locale can be retrieved via I18nProvider. So I could imagine that the hostname can also be retrieved, maybe via the NetworkAddressService

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants