Recently I was playing around with openHAB3 (RC1) and tried different item migration possibilities:

creation of items directly in MainUI

copy&paste from existing textual OH2.x config (expert mode)

textual creation in OH3

Some of my old items in the OH2.x config contains state presentation such as: Number zwayPlug2Energy "Verbrauch [%.1f kWh]" ...

But so far I was not able to create such items with No.1 and No.2. With the textual creation it is working but I would like to use MainUI only in the future.

Without scripting it’s not possible. But the script itself is quite easy.

// computes nicely formatted duration from given minutes
(function(i){
var d = Math.floor(i / (24 * 60));
var h = Math.floor((i / 60) - (24 * d));
var m = Math.round(i - 60 * (24 * d + h));
var result = '';
// days
if (d > 0) {
if(d == 1)
result = result + d + ' Day';
else
result = result + d + ' Days ';
}
if(h > 0)
{
if(h == 1)
result = result + ("00" + h).substr(-2,2) + " Hour "
else
result = result + ("00" + h).substr(-2,2) + " Hours "
}
result = result + ("00" + m).substr(-2,2) + " Minutes";
return result;
})(input)

Save that e.g. as duration.js within the scripts folder and add it within the state description metadata of the item that reports seconds.

But the script converts into days/hours/minutes/seconds and not only hours

thank you for the quick reply! Have the script slightly adjusted since the input variable is seconds with me. Functioning now super!

Greetings

// computes nicely formatted duration from given seconds
(function(i){
var d = Math.floor(i / (24 * 60 * 60));
var h = Math.floor((i / (60 * 60)) - (24 * d));
var m = Math.round(i / 60 -(60 * (24 * d + h)));
var s = Math.round(i - 60 * (m + (60 * (24 * d + h))));
var result = '';
// days
if (d > 0) {
if(d == 1)
result = result + d + ' Tag';
else
result = result + d + ' Tage ';
}
if(h > 0)
{
if(h == 1)
result = result + ("00" + h).substr(-2,2) + " Stunde "
else
result = result + ("00" + h).substr(-2,2) + " Stunden "
}
result = result + ("00" + m).substr(-2,2) + " Minuten ";
// result = result + ("00" + s).substr(-2,2) + " Sekunden";
return result;
})(input)