How to create environment variables for user "openhab"

Platform information:

  • Hardware: CPU: i5-4460; RAM 7.6 GiB; SSD 115.43 GB (92.07GB free)
  • OS: Ubuntu 20.04 LTS
  • Java Runtime Environment: i386 Azul Zulu 11.45+27 (11.0.10-b9) JRE
  • openHAB version: openHAB 3.1.0

What I want to achieve:
I have a python script that reads the current list of wifi tickets from my fritzbox and posts the first one to openHAB. The author of the scriptintended to use environment variables to read the fritzbox login data.
I want the script to run by reading the login data from the system variables.

What I’ve got so far:
On my local machine (ubuntu as well) with my user I’ve setup the environment variables - the script runs just fine and i can see the latest ticket in openHAB.
The same applies when I run the script on the openHAB server with my user.

However - when the script is executed by openHAB nothing happens.
I figured that it has to do with the setup of environment variables for user “openhab”… so I hard coded the fritzbox login data (in the script) - and everything works as expected.
So I think it’s safe to assume that my assumption, the missing environment variables are the root cause, is correct.

The problem:
The problem is that the fritzbox login data is stored in plain text within the script, obviously.

With my user (locally and on the openhab server) I’ve created the environment variables as follows:

  • run command:
    sudo -H gedit /etc/environment
  • add following lines:
  • save the file and close it

However this does not work for the user openhab:

  • I can su for that user - but i do not have sufficient privileges to edit the file
  • I cannot su sudo or login with the user (there’s no password?)

Can you please help me out letting the script run from openhab without having the login data hardcoded?

Thanks in advance!

Try to put them into /etc/default/openhab.

1 Like

It’s working now!
I’ve added the variables to /etc/default/openhab. Undid my changes to the script so the access data is read from environment variables. After that I had to restart the openhab service.

I’ve double checked that solution by commenting out the variables from /etc/default/openhab and restarting the openhab service → no new WiFi ticket.
→ So for me it’s safe that editing /etc/default/openhab did the trick!

Thank you very much @Wolfgang_S!

1 Like