<SOLVED> Wrong time in openhab karaf console

un-commenting the “EnvironmentFile=-/etc/default/openhab2” did the trick

  • Platform information:
    • Hardware: lxc container in proxmox
    • OS: Ubuntu 18.04.1 LTS
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu 8.44.0.11-CA-linux64) (build 1.8.0_242-b20)
    • openHAB version: 2.5.3 release build
  • Issue of the topic:
    the openhab used time is different to the system time zone.
    What is wring in my configuration and where to put the right configuration?

thx

karaf consol:

date
May Fri 15 16:08:30 2020

PaperUI shows
(GMT+1:00)EUROPE/Zurich

terminal on system

date
Fri May 15 18:17:56 CEST 2020

the timezone in system is configured correctly

ls -l /etc/localtime
lrwxrwxrwx 1 root root 33 May 5 21:30 /etc/localtime -> /usr/share/zoneinfo/Europe/Zurich

The system starting via systemd

cat /etc/systemd/system/multi-user.target.wants/openhab2.service
[Unit]
Description=openHAB 2 - empowering the smart home
Documentation=https://www.openhab.org/docs/
Documentation=https://community.openhab.org
Wants=network-online.target
After=network-online.target

[Service]
User=openhab
Group=openhab

WorkingDirectory=/opt/openhab2
#EnvironmentFile=-/etc/default/openhab2

ExecStart=/opt/openhab2/runtime/bin/karaf daemon debug
ExecStop=/opt/openhab2/runtime/bin/karaf stop
Restart=on-failure
SuccessExitStatus=0 143

[Install]
WantedBy=multi-user.target

I assume that this is the right location to additionally define timezone for java

/opt/openhab2# cat start.sh
#!/bin/sh

echo Launching the openHAB runtime…
export EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyS0:/dev/ttyS1:/tmp/virtualcom0 -Duser.timezone=Europe/Zurich"

if [ ! -z ${OPENHAB_RUNTIME} ]; then
RUNTIME=${OPENHAB_RUNTIME}
else
RUNTIME="dirname "$0"/runtime"
fi

exec “${RUNTIME}/bin/karaf” “${@}”

How to use code fences - Tutorials & Examples - openHAB Community

I am using openhab on a cubietruck with Ubuntu 16.04.
In file /etc/systemd/system/multi-user.target.wants/openhab2.service I have a line

EnvironmentFile=-/etc/default/openhab2

Settings then are defined in /etc/default/openhab2.
So there is not need to edit the existing startup script.
In your case the row with EnvironmentFile is commented out and will not be used.

What is the result if you execute this in the karaf console:

env |grep timezone

many thanks.

env |grep timezone
String          user.timezone   Etc/UTC

that explains the time i see in karaf.

what should be the content in in /etc/default/openhab2?
why is the
export EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyS0:/dev/ttyS1:/tmp/virtualcom0 -Duser.timezone=Europe/Zurich"
in my /openhab2.service not working?

Your

shows

#EnvironmentFile=-/etc/default/openhab2

remove the # and restart the service.

1 Like

This solution is not working with openHAB 3.
I can find the file under

cat /etc/systemd/system/multi-user.target.wants/openhab.service

but there is no # in front of EnvironmentFile=-/etc/default/openhab

Any clue how to fix this issue for openHAB 3?
Entering env |grep timezone in karaf console results in String user.tiezone Etc/UTC.
I’m in Europe/Berlin Timezone.

I wouldn’t go that far until the root cause is found …

In case there is no # in front of that row in the meantime it was removed resp. it may not be there because of it was not there in the file provided …
What is the content of your /etc/default/openhab file ?
What is the content of /etc/timezone ?
What timezone did you configure in the settings via main UI ( settings => regional settings ) ?

1 Like

Thanks for trying to help me with this issue.
The content of /etc/default/openhab file is the following:

The content of /etc/timezone is: Etc/UTC
And the regional setting is set to: (GMZ+1:00) Europe/Berlin

  • your /etc/default/openhab file just contains comments and EXTRA_JAVA_OPTS is empty
  • because of /etc/timezone is set to Etc/UTC your OS system runs with that timezone; Java picks it up from there as Java is not instructed to read it from /etc/default/openhab
  • in case you use openhabian run menu 33 to change the timezone
  • in case you don’t use openhabian follow How to Set Time and Date in Raspberry Pi : 4 Steps - Instructables to change the timezone
1 Like

Thank you for your help.
I managed to get the correct time/timezone by clearing /etc/timezone (make file empty).

1 Like