[SOLVED] Call a javascript transform script from within habpanel

I want to display uptime in “days, hours minutes” format.
The systeminfo binding sets the uptime value in minutes.
javascript transform can do the conversion (see here)

The current setting is:
in .items:

Number CPU_Uptime  "Uptime [JS(duration.js):%s]" <clock> (gSystem) { channel="systeminfo:computer:work:cpu#uptime" }

in habpanel (in template widget):

<div class="name">Uptime</div>
<div class="valueGroup"><div class="value">{{itemValue('CPU_Uptime') | number:0}} min</div></div>

If it is possible to call a javascript transform script from within habpanel, what will the call look like?
If not, is there another way to present the uptime in a “days, hours minutes” string format from within habpanel?

Thanks

I don’t know about HABpanel, I suspect the answer is no.

But you can create a separate String Item an use a rule to parse the number into hours, minutes, seconds. Then put that String other on your HABpanel.

Thank @rlkoshak
The following settings fixed it for me.

rule "Test Duration Script"
when
    Item CPU_Uptime received update
then
    val String duration  = '' + transform("JS", "duration.js", CPU_Uptime.state.toString)
    logInfo('Test', 'Number ==> ' + CPU_Uptime.state.toString)
    logInfo('Test', 'String ==> ' + duration)
    CPU_UptimeStr.postUpdate(duration)
end 

.item

Number CPU_Uptime  "Uptime [JS(duration.js):%s]" <clock> (gSystem) { channel="systeminfo:computer:work:cpu#uptime" }
String CPU_UptimeStr

In habpanel I have

...
  	<div class="widget">
		<div class="icon off"><svg viewBox="0 0 48 48"><use xlink:href="/static/button.svg#pressure"></use></svg></div>
		<div class="name">Uptime</div>
		<div class="valueGroup"><div class="value">{{itemValue('CPU_UptimeStr')}}</div></div>

Thank you, Avner! It works!
Ayden,
javascript obfuscator

1 Like