JS Transformation not updating

Hi there,

I use a JS transformation for my Bosch Home Connect devices to transform the remaining run time from seconds (coming from the API) to a more human readable format. While the non-transformed item updates as expected, the transformed value remains at “32 min” and I have no idea why. Here’s my sitemap entry:

Default item=Dishwasher_RemainingProgramTime label="Restlaufzeit [JS(time.js):%s]" visibility=[Dishwasher_PowerState==ON]
Default item=Dishwasher_RemainingProgramTime label="Restlaufzeit" visibility=[Dishwasher_PowerState==ON]

And the corresponding time.js code:

(function(i) {
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 >= 86400) { // 86400 seconds in a days
    days = Math.floor(val / 86400); // Number of days
    val = val - (days * 86400); // Remove days from val
}
if (val >= 3600) { // 3600 seconds in an hour
   hours = Math.floor(val / 3600); // Number of hours
    val = val - (hours * 3600); // Remove hours from val
}
minutes = Math.floor(val / 60); // Number of minutes

var stringDays = ''; // Initialse string variables
var stringHours = '';
var stringMinutes = '';
	
if (days > 0) {
    stringDays = days + ' T '; // More than 1 day so 's'
} // If days = 0 then stringDays remains ''

if (hours > 0) {
    stringHours = hours + ' h '; // More than 1 hour so 's'
} // If hours = 0 then stringHours remains ''

if (minutes > 0) {
    stringMinutes = minutes + ' min'; // 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)

When I test the JS, it works perfectly fine. I’m running OH3, but still use BasicUI for the OH app.

Thanks a ton for your help,
Florian

As your transform seems to work initially, I’ll hazard a guess this is an odd artefact of having the Item in the sitemap twice.

The UI gets notified when an Item state is updated - the raw Item state, before any transformation.
I think you’ll only get one notification, no matter how many times the Item appears in your sitemap.
The UI dutifully updates its screen, but in this case I suspect some timing issue where it fetches new values to display before your transform has had time to calculate a new value?
That probably arrives later, but the screen update is over by then.

I have an idea that if you remove the raw Item line, the transformed line may work as expected.

Hi Florian, can you please share your item details, too? How do get both their updates? How are they linked to a channel?

Cheers
Steffen

Unfortunately, this does not help. Even when I only have the transformed item in there, it does not get updated. I have added the raw item only for debugging purposes.

I assumed your script worked. Have you ever got anything other than “32mins” out of it? Your openhab.log may show up transform failures at UI refresh time.

openhab> openhab:items list Dishwasher_RemainingProgramTime
Dishwasher_RemainingProgramTime (Type=NumberItem, State=UNDEF, Label=Remaining program time, Category=time)

openhab> openhab:links list
Dishwasher_RemainingProgramTime -> homeconnect:Dishwasher:BOSCH-SBV68TX06E-68A40E093DE8:remaining_program_time_state Configuration[]

Is this what you’re looking for?

Nope, openhab.log doesn’t have anything on transform issues. I think I haven’t seen anything else then 32 mins, but I wouldn’t bet on it.