Duration from seconds to minutes

Hi All,

This script I found which works quite well to convert seconds to duration, however when the item has NULL on it, say at boot, it throws an error.
I have no experience with JS so Ive not a foggiest on how to convert this, but can anyone suggest a change to remove the error?

For OH3 it would be unreal! if there could be a built in formatter for seconds, minutes, hours etc etc :wink:

19:17:06.363 [WARN ] [.rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state 'NULL' on item 'UPS_Battery_Runtime' with pattern 'JS(duration_from_seconds.js):%s': An error occurred while executing script.

// computes nicely formatted duration from given seconds

        var date = new Date(null);
        date.setSeconds(parseInt(i)); // specify value for SECONDS here
        return date.toISOString().substr(11, 8);


Persistence rrd4j…Restore on startup or if that’s not working use in a rule a test for item == null and if true assign a value eg use previous value

Hi Mark,

Yep persistance is not working im afraid using mapdb. Which is odd


rule "UPS run time"
        System started

Is persistence not working (A) or does persistence not solve your problem (B).

Case A:
Please Show your Setup for mapDB, especially the files: services/mapdb.cfg and persistence/mapdb.persist

Case B:
It MIGHT be the case that your rule is run BEFORE the state of the item has been restored. In this case you will see this error once every Startup only.

1 Like

persistence is working. It appears only for this item it may not. Unlikely

Strategies {
    everyHour   : "0 0 * * * ?"
    everyDay    : "0 0 0 * * ?"

    default = everyChange

Items {
    * : strategy = everyChange, everyDay, restoreOnStartup

# the commit interval in seconds (optional, default to '5')

# issue a commit even if the state did not change (optional, defaults to 'false')

Instead of mapDB iosn’t persisting/restoring that one item, I’d vote for Option B. Please check your log after a restart wether, when and to what state the item gets sets.

Thanks opus, it absolutely is on startup.

I thought mapdb was for states, on , off etc and rrd4j was for values.

I have influx also, ill add it to that and see if the error disappears

mapDB does save the LAST state for all types, but only the last one! Hence, this DB is the suggested one for RestoreOnStartUp.
rrd4j can save ONLY values, the period is adjustable.