[SOLVED] dateTime item gets wrong timezone - how can i fix it?


Would be great when someone could explain how to fix this or where my mistake is. Thank you!
i have an DateTime item, that gets the wrong time zone or better to say the provided timezone (UTC) is replace by my local timezone

I’m using http binding to get the date&time out of a json

DateTime vSunRiseBerlin        "Sonnenaufgang [%1$tH:%1$tM]"   { http="<[https://api.sunrise-sunset.org/json?lat=52.5045667&lng=13.3534171,12&formatted=0&date=0day:360000:JSONPATH($..sunrise)]" }

the expected output would be 2018-04-08T04:23:15+00:00

in the log is written

2018-04-08 21:43:42.292 [vent.ItemStateChangedEvent] - vSunRiseBerlin changed from NULL to 2018-04-08T04:23:15.000+0200

For the sake of completeness I run openHAB 2.3.0~20180406103010-1 (Build #1251) on a Raspberry Pi 3b+, installed using openHABian


Please check you time-zone settings in PaperUI and openHABian.

33 | Set System Timezone Change the your timezone, execute if it’s not ‘22:02’ now

I have checked this, both paperUI and the raspberry have the correct time.
I also don’t think this is a problem with my local time setting, for me it looks more like the orginale timezone provided (UTC) is just been ignored and replaced with my local set on

Why don’t you use the astro binding to get the sunrise?

i was waiting for this question, the reason is that i also want to have the data for the next 3 day as well as from yesterday, it’s easy to request the different days using this api

The API has replied correctly, Berlin is +2
The datetime item is the correct timezone
What is the issue exactly?

You could always take of or ad on 1 or 2 hours in a rule

yes it’s correct Berlin is +0200, but the reply from the api is 2018-04-08T04:23:15+00:00 so the correct output should be 2018-04-08T06:23:15.000+0200, but I get 2018-04-08T04:23:15+00:00 which results in a time 2 hours too early

changing the display value using a rule would be a option, but I would prefer a solution that gets the data into the database with the correct timezone

I have just read their API docs and they only supply UTC time, you will have to use a rule, I am afraid

ok, but that leave still the problem that openhab give the wrong timezone to the item, it just ignores the given +00:00 and replace it with the wrong +0200

Lets try another approach with a javascript transform:

Create a “sunrisetime.js” file in your transform folder
With the following content:

(function(i) {
    var data = JSON.parse(i);
    var sunriseString = data.results.sunrise;
    sunriseTime = Date.parse(sunriseString)
    sunriseTime = (sunsireTime / 1000).floor()
    return sunriseTime;

And your item:

DateTime vSunRiseBerlin        "Sonnenaufgang [%1$tH:%1$tM]"   { http="<[https://api.sunrise-sunset.org/json?lat=52.5045667&lng=13.3534171,12&formatted=0&date=0day:360000:JS(sunrisetime.js)]" }

the code you provided creates an error (even with the corrected typo sunsireTime

But i was able to find a solution, the problem was that the timestamp from the api had a slightly different format the openHAB had expected it to be
Now i use this javascript transformation, it simply removes the : from the timezone

(function(i) {
    var data = JSON.parse(i);
    return (data.results.sunrise).slice(0, -6)+"+0000";

the nice thing is that openHAB now do the “math” and add 2 hours (because of my local timezone) to the timestamp before storing it into the database

so thank you very much @vzorglub for your support and inspiration, this way i was able to locate and fix the problem

1 Like


I know this thread is already solved, but I update my experiences here anyhow for those wondering the same problem with container version. Even that the container page https://hub.docker.com/r/openhab/openhab/ well explains how to get container system into local timezone from host settings, that’s not enough. Even that, and setting Paper UI timezone correct to show times right in GUI, won’t execute the rules in correct times. The Java engine runs still in UTC. To get the Java engine going right timezone, you need to pass extra java options parameter as environment variable for container like this:


This way everything within openhab runs in the correct timezone, and no conversions and offsets need to be calculated.



Hi @mueslee

I am having a similar problem. I have a timezone coming from an api as follows:


I am at +1100. I need to convert the timezone Z into +1100.
Can you provide any suggestions?


Here is the api json output:
“loadedUrl”: “https://www.melbournepollen.com.au/”,
“loadingStartedAt”: “2018-10-16T21:25:01.350Z”,
“loadingFinishedAt”: “2018-10-16T21:25:04.674Z”,
“loadErrorCode”: null,
“pageFunctionStartedAt”: “2018-10-16T21:25:04.688Z”,
“pageFunctionFinishedAt”: “2018-10-16T21:25:04.693Z”,
“isMainFrame”: true,
“postData”: null,
“contentType”: null,
“method”: “GET”,
“willLoad”: true,
“errorInfo”: “”,
“pageFunctionResult”: {
“pollenToday”: “Low”,
“taToday”: “Low”,
“forecast2”: “Low”,
“forecast3”: “Low”,
“forecast4”: “Moderate”,
“forecast5”: “Low”,
“forecast6”: “Low”
“interceptRequestData”: null,
“downloadedBytes”: 619001,
“queuePosition”: “LAST”,
“proxy”: null,
“responseStatus”: 200,
“responseHeaders”: {
“Date”: “Tue, 16 Oct 2018 21:20:53 GMT”,
“Server”: “Apache/2.4.6 (Red Hat Enterprise Linux) mod_wsgi/4.5.18 Python/3.6 PHP/5.4.16”,
“X-Frame-Options”: “SAMEORIGIN”,
“X-Mod-Pagespeed”: “”,
“Vary”: “Accept-Encoding”,
“Content-Encoding”: “gzip”,
“Cache-Control”: “max-age=0, no-cache, s-maxage=10”,
“Content-Type”: “text/html; charset=utf-8”,
“Age”: “250”,
“Warning”: “110 squid/3.5.20 “Response is stale””,
“X-Cache”: “HIT from wattle1.its.unimelb.edu.au”,
“X-Cache-Lookup”: “HIT from wattle1.its.unimelb.edu.au:8080”,
“Transfer-Encoding”: “chunked”,
“Via”: “1.1 wattle1.its.unimelb.edu.au (squid/3.5.20)”,
“Connection”: “keep-alive”,
“Set-Cookie”: “BIGipServer~AUSPOLLEN~z1_pl_melbournepollen_prod_8080=1684019372.36895.0000; path=/; Httponly; Secure”
“id”: “lnNru3Pv23tpOVa”,
“url”: “https://www.melbournepollen.com.au/”,
“requestedAt”: “2018-10-16T21:25:01.104Z”,
“uniqueKey”: “https://www.melbournepollen.com.au”,
“type”: “StartUrl”,
“label”: null,
“referrerId”: null,
“depth”: 0,
“storageBytes”: 1352

And my item:

DateTime MelbPollen_lastupdate "Last Update [%1$tY-%1$tm-%1$td %1$tH:%1$tM]" <time> {http="<[MelbPollen:3600000:JSONPATH($..loadingFinishedAt)]" }

Did you try a javascript transform?

Hi @marklavercombe,

as @vzorglub already wrote a js transfrom is needed

the code below isn’t tested but something like this should work

(function(i) {
    var data = JSON.parse(i);
    return (data.loadingFinishedAt).slice(0, -1)+"+1100";

Thanks @mueslee @vzorglub

I am getting an exception. Log:

2018-10-22 21:19:34.962 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'JS(pollenTime.js)' threw an exception. [response=[{
  "loadedUrl": "https://www.melbournepollen.com.au/",
  "loadingStartedAt": "2018-10-22T03:25:00.665Z",
  "loadingFinishedAt": "2018-10-22T03:25:03.374Z",
  "loadErrorCode": null,
  "pageFunctionStartedAt": "2018-10-22T03:25:03.379Z",
  "pageFunctionFinishedAt": "2018-10-22T03:25:03.382Z",
  "isMainFrame": true,
  "postData": null,
  "contentType": null,
  "method": "GET",
  "willLoad": true,
  "errorInfo": "",
  "pageFunctionResult": {
    "pollenToday": "Moderate",
    "taToday": "Low",
    "forecast2": "Low",
    "forecast3": "Low",
    "forecast4": "Moderate",
    "forecast5": "Low",
    "forecast6": "Low"
  "interceptRequestData": null,
  "downloadedBytes": 508749,
  "queuePosition": "LAST",
  "proxy": null,
  "responseStatus": 200,
  "responseHeaders": {
    "Date": "Mon, 22 Oct 2018 03:24:45 GMT",
    "Server": "Apache/2.4.6 (Red Hat Enterprise Linux) mod_wsgi/4.5.18 Python/3.6 PHP/5.4.16",
    "X-Frame-Options": "SAMEORIGIN",
    "X-Mod-Pagespeed": "",
    "Vary": "Accept-Encoding",
    "Content-Encoding": "gzip",
    "Cache-Control": "max-age=0, no-cache, s-maxage=10",
    "Content-Type": "text/html; charset=utf-8",
    "Age": "17",
    "Warning": "110 squid/3.5.20 \"Response is stale\"",
    "X-Cache": "HIT from wattle2.its.unimelb.edu.au",
    "X-Cache-Lookup": "HIT from wattle2.its.unimelb.edu.au:8080",
    "Transfer-Encoding": "chunked",
    "Via": "1.1 wattle2.its.unimelb.edu.au (squid/3.5.20)",
    "Connection": "keep-alive",
    "Set-Cookie": "BIGipServer~AUSPOLLEN~z1_pl_melbournepollen_prod_8080=1700796588.36895.0000; path=/; Httponly; Secure"
  "id": "lnNru3Pv23tpOVa",
  "url": "https://www.melbournepollen.com.au/",
  "requestedAt": "2018-10-22T03:25:00.572Z",
  "uniqueKey": "https://www.melbournepollen.com.au",
  "type": "StartUrl",
  "label": null,
  "referrerId": null,
  "depth": 0,
  "storageBytes": 1356
org.openhab.core.transform.TransformationException: An error occurred while executing script.
	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) [196:org.openhab.core.compat1x:2.3.0]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:194) [259:org.openhab.binding.http:1.12.0]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [196:org.openhab.core.compat1x:2.3.0]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [196:org.openhab.core.compat1x:2.3.0]

pollenTime.js per your suggestion @mueslee:

(function(i) {
    var data = JSON.parse(i);
    return (data.loadingFinishedAt).slice(0, -1)+"+1100";


DateTime MelbPollen_lastupdate "Last Update [%1$tY-%1$tm-%1$td %1$tH:%1$tM]" <time> {http="<[MelbPollen:60000:JS(pollenTime.js)]" }

I can’t seem to figure out why… any help is greatly appreciated! Thanks in advance :slight_smile:

@mueslee @vzorglub

I’m not sure how to debug this further. Any ideas?

Thanks in advance for your help! :smiley:

For some reasons your json is in []

(function(i) {
    var data = JSON.parse(i);
    return (data[0].loadingFinishedAt).slice(0, -1)+"+1100";
1 Like