Restore DateTime ignoring timezone

Hello there,

I calculate a time difference in my rule and store it in a DateTime item.
Persistence is done via InfluxDB.
Item is declared like this:

DateTime Waschkueche_Waschmaschine_letzteZykluszeit "Letzte Waschdauer [%1$tH:%1$tM h]" (Waschkueche, Zeit)

Database persists the correct value:

> select * from Waschkueche_Waschmaschine_letzteZykluszeit
name: Waschkueche_Waschmaschine_letzteZykluszeit
time                value
----                -----
1516470604809000000 11554769

The sitemap shows 03:12 h after the rule updates the value but 04:12 h after the value is restored from the database.
How can I set up that no timezone offset is applied to this value when it is restored?

You should not do that. DateTime is designed to store absolute dates and times and is not suitable for storing durations.

You need to store the duration as a Number (number of minutes, number of seconds, number of milliseconds) and use a JS transform in the Item’s label or a Rule and a Proxy Item to convert that Number to Hours and Minutes.

Here is the JS transform I use to convert the uptime reported by my sonoffs in hours to days:hours:minutes:seconds.

(function(i) {
    if(isNaN(i)) return "NA";
    var days = Math.floor(i/24);
    var hours = i%24;
    var pad = "00";
    return days+":"+(pad+hours).slice(-pad.length)+":00:00";
})(input)

thank you very much, I will change this.

Hi Rich,
How do you enable your JS transform for the uptime in the paper UI?

I don’t. I define all my Items in .items files.

But to use it you store the minutes or hours in a Number Item and apply the transform to the label as documented here.

I still don’t get how its done with files, as I usually create just the items in conf files, and from Paper UI , just create new items that link to the various parameters.

Could you show your example?
much thanks!

Just replace the label for the Item in PaperUI with JS(hours2mins.js):%s.

Creating Items in .items files is https://www.openhab.org/docs/configuration/items.html

What should the thing look like? also with the JS transformation info?

Thing:

Type number : uptime	"Uptime"			   [ stateTopic="tele/sonoff/MFC/STATE", transformationPattern="JS:uptime.js"]

Item:

Number XeroxMFC_Uptime "Uptime [JS(uptime.js):%s]" { channel= "mqtt:topic:mosquitto:MFC:uptime" }

I don’t use .things files. But the Thing is irrelevant. So long as it is a Number type Channel linked to a Number Item, you just need to transform the label of the Item.