Rules / Cron / Local time

I have seen a few similar questions but none see to apply to my problem.

Background

I think my time and settings are correct.

$ date
Fri Apr 26 10:43:17 AM CEST 2024
$ timedatectl
               Local time: Fri 2024-04-26 10:40:57 CEST
           Universal time: Fri 2024-04-26 08:40:57 UTC
                 RTC time: n/a
                Time zone: Europe/Berlin (CEST, +0200)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

The issue

I created a rule based on a cron and “it does not work”.

Debug

TO debug, I created the following rules:

rule "Cron 8 test"
when
    Time cron "0 * 8 * * *"
then
    logInfo("Cron", "Cron 8 test")
end

rule "Cron 9 test"
when
    Time cron "0 * 9 * * *"
then
    logInfo("Cron", "Cron 9 test")
end

rule "Cron 10 test"
when
    Time cron "0 * 10 * * *"
then
    logInfo("Cron", "Cron 10 test")
end

and my logs says:

2024-04-26 09:44:00.044 [INFO ] [org.openhab.core.model.script.Cron  ] - Cron 9 test

Recap

  • My local time is 10:xx
  • GMT is 8:xx
  • The logger and rules think it is 9:xx

I am suspecting the fix could be this… but it is not.

And the solution was:

in /etc/default/openhab

from

EXTRA_JAVA_OPTS="-Xms192m -Xmx768m -XX:+ExitOnOutOfMemoryError"

to

EXTRA_JAVA_OPTS="-Xms192m -Xmx768m -XX:+ExitOnOutOfMemoryError -Duser.timezone=Europe/Berlin"

Followed by a reboot.

Just to elaborate a little, the local timezone is set in three different places: OS, Java, openHAB. Java is supposed to inherit from the OS but for reasons no one has been able to figure out it does not always do so.

If cron doesn’t fire at the correct times or if you notice the timestamps in your logs being off that’s often an indicate that that the Java timezone setting is incorrect. If the OS is set properly that means Java didn’t pick it up so you need to add the extra Java option as shown.

1 Like

Thanks Rich,
Editing was easy, but I’m not granted permission to save the modified file, and I have no clue how to get there. I updated permissions (config item 14) but no success. A hint?

You have to use sudo to modify files not owned by your login user. Use sudo n front if what ever company you used to edit the file.