Rule Timezone issue

  • Platform information:
    • OS: ubuntu server 22.04 vs ubuntu server 24.04
    • openhab 4.2.1 (Build)
    • openjdk version “17.0.12” 2024-07-16 LTS
    • OpenJDK Runtime Environment Zulu17.52+17-CA (build 17.0.12+7-LTS)
    • OpenJDK 64-Bit Server VM Zulu17.52+17-CA (build 17.0.12+7-LTS, mixed mode, sharing)

Hi

I have set up two openhab devices identically with an ansible script. One device is based on ubuntu server 22.04 and one on ubuntu server 24.04. The time zone is set correctly on both devices.

The problem is that one system includes the local time zone for the values middaySun and afternoonSun in the rule (ubuntu server 22.04), the other does not.

Rules file:

val logName = "solarTimeOfDay"

var ZonedDateTime sunRise = null
var ZonedDateTime daylight = null
var ZonedDateTime middaySun = null
var ZonedDateTime afternoonSun = null
var ZonedDateTime eveningSun = null
var ZonedDateTime sunSet = null

rule "timeOfDay Calculate the times of this day"
when
  System started or // run at system start in case the time changed when OH was offline
  Time cron "0 3 0 * * ? *" // three minutes after midnight, to give Astro time to calculate the new day's times
then
  // Convert the Astro Items to ZonedDateTime
  sunRise = (sunrise_Time.state as DateTimeType).getZonedDateTime()
  daylight = sunRise.plusHours(1)
  sunSet = (sunset_Time.state as DateTimeType).getZonedDateTime()
  eveningSun = sunSet.minusHours(1)

  // Jump to tomorrow and subtract to avoid problems (summer time / winter time)
  middaySun = now.withHour(0).withMinute(0).withSecond(0).plusDays(1).minusHours(24).plusHours(11)
  afternoonSun = now.withHour(0).withMinute(0).withSecond(0).plusDays(1).minusHours(24).plusHours(13)

  // Publish the current state
  logInfo(logName, "Calculated sun rise: " + sunRise)
  logInfo(logName, "Calculated daylight: " + daylight)
  logInfo(logName, "Calculated midday sun: " + middaySun)
  logInfo(logName, "Calculated afternoon sun: " + afternoonSun)
  logInfo(logName, "Calculated evening sun: " + eveningSun)
  logInfo(logName, "Calculated sun set: " + sunSet)
end

output on ubuntu server 22.04:

penhab.log:2024-09-08 15:56:40.888 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated sun rise: 2024-09-08T06:56+02:00
openhab.log:2024-09-08 15:56:40.889 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated daylight: 2024-09-08T07:56+02:00
openhab.log:2024-09-08 15:56:40.890 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated midday sun: 2024-09-08T11:00:00.887324888+02:00[Europe/Zurich]
openhab.log:2024-09-08 15:56:40.890 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated afternoon sun: 2024-09-08T13:00:00.887697629+02:00[Europe/Zurich]
openhab.log:2024-09-08 15:56:40.891 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated evening sun: 2024-09-08T18:51+02:00
openhab.log:2024-09-08 15:56:40.891 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated sun set: 2024-09-08T19:51+02:00

output on ubuntu server 24.04:

openhab.log:2024-09-08 14:08:37.514 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated sun rise: 2024-09-08T06:56+02:00
openhab.log:2024-09-08 14:08:37.519 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated daylight: 2024-09-08T07:56+02:00
openhab.log:2024-09-08 14:08:37.522 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated midday sun: 2024-09-08T11:00:00.503058880Z[Etc/UTC]
openhab.log:2024-09-08 14:08:37.525 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated afternoon sun: 2024-09-08T13:00:00.506116451Z[Etc/UTC]
openhab.log:2024-09-08 14:08:37.528 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated evening sun: 2024-09-08T18:51+02:00
openhab.log:2024-09-08 14:08:37.531 [INFO ] [hab.core.model.script.solarTimeOfDay] - Calculated sun set: 2024-09-08T19:51+02:00

Does anyone have any idea what the problem could be?

Best regards
Michael

It looks as if the system zone is being read incorrectly by java/openhab.

timedatectl:

               Local time: Sun 2024-09-08 22:54:28 CEST
           Universal time: Sun 2024-09-08 20:54:28 UTC
                 RTC time: Sun 2024-09-08 20:54:28
                Time zone: Europe/Zurich (CEST, +0200)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Currently I can only define the time zone manually to get a correct result.

Not dynamic fix of the rule:

  var ZoneId localZone = ZoneId.of("Europe/Zurich")
  //var ZoneId localZone = ZoneId.systemDefault()
  middaySun = now.withHour(0).withMinute(0).withSecond(0).plusDays(1).minusHours(24).plusHours(11)
  middaySun = middaySun.withZoneSameInstant(localZone)
  afternoonSun = now.withHour(0).withMinute(0).withSecond(0).plusDays(1).minusHours(24).plusHours(13)
  afternoonSun = afternoonSun.withZoneSameInstant(localZone)

I do not yet understand the cause.

I may be off on a tangent here, but what does the OpenHAB regional settings page look like on the 2 different systems?
(Settings->Regional Settings-> Timezone & Location)

I am also on same version of OpenHAB (4.2.1) and Ubuntu 24.04.1 and my system TZ settings look the same as yours (RTC=UTC).
No issues for me with TZ in scripts so far…(Also used to be on Ubuntu 22.x with same result).

Also, different OS, but perhaps keep your eye on this thread too, which is currently in play:

Probably this:

There have been a lot of posts lately about time zone problems!

It comes in waves once or twice a year.

1 Like

This was exactly the problem. Thank you.