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
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
(function(i){
var date = new Date(null);
date.setSeconds(parseInt(i)); // specify value for SECONDS here
return date.toISOString().substr(11, 8);
})(input)
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.
# the commit interval in seconds (optional, default to '5')
#commitinterval=5
# issue a commit even if the state did not change (optional, defaults to 'false')
#commitsamestate=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.
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.