Hello, I’m glad you like this widget
In addition, the storage size is not displayed in GB. Do you have any idea what I’m doing wrong here?
Maybe I also need to add something to the metadata here?
set Item metadata unit to GB
and set Item Metadata: stateDescription Pattern to %.2f %unit%
but the operating time is not displayed in days, hours and minutes, but only in minutes, not as shown in your screenshot.
set Item metadata unit to min
and set Item Metadata: stateDescription Pattern to use this JS transformation
exemple : JS(config:js:78b97e3b17:fr):%s
/*
Javascript transform function to change the number
of minutes of CPU time from the System Info Binding
into a more readable format
eg: 2365 into '1 day 15 hours 25 minutes
*/
(function(i) {
if (i == 'NULL') { return i; }
if (i == '-') { return 'Undefined'; }
var val = parseInt(i); // The value sent by OH is a string so we parse into an integer
var days = 0; // Initialise variables
var hours = 0;
var minutes = 0;
if (val >= 1440) { // 1440 minutes in a days
days = Math.floor(val / 1440); // Number of days
val = val - (days * 1440); // Remove days from val
}
if (val >= 60) { // 60 minutes in an hour
hours = Math.floor(val /60); // Number of hours
val = val - (hours * 60); // Remove hours from val
}
minutes = Math.floor(val); // Number of minutes
var stringDays = ''; // Initialse string variables
var stringHours = '';
var stringMinutes = '';
if (days === 1) {
stringDays = '1 j '; // Only 1 day so no 's'
} else if (days > 1) {
stringDays = days + ' j '; // More than 1 day so 's'
} // If days = 0 then stringDays remains ''
if (hours === 1) {
stringHours = '1 h '; // Only 1 hour so no 's'
} else if (hours > 1) {
stringHours = hours + ' h '; // More than 1 hour so 's'
} // If hours = 0 then stringHours remains ''
if (minutes === 1) {
stringMinutes = '1 m'; // Only 1 minute so no 's'
} else if (minutes > 1) {
stringMinutes = minutes + ' m'; // More than 1 minute so 's'
} // If minutes = 0 then stringMinutes remains ''
var returnString = stringDays + stringHours + stringMinutes
return returnString.trim(); // Removes the extraneous space at the end
})(input)
have a nice day