hello, i’ve tried to make work Uptime openHAB but doesn’t work.
i ha ve this result.
can anyone give some minutes of his time to help me?
here are my files:
uptime.items
Number System_CPU_Uptime "Uptime server [JS(duration.js):%s]" { channel="systeminfo:computer:local:cpu#uptime" }
String System_openHAB_Uptime_output "Uptime openHAB [%s]" { channel="exec:command:uptime:output" }
Number System_openHAB_Uptime "Uptime openHAB [JS(duration.js):%s]"
exec.rules
val String _logger = "rules.exec"
// This rule is used to update the Number out of the returned string from the command line.
// Only Works since openhab 2.2.
rule "Convert String to Item Type"
when
Item System_openHAB_Uptime_output changed
then
// Get name of Number Item by removing "_output" from the name of the String Item
val toUpdate = triggeringItem.name.toString.split("_output").get(0)
// post the new value to the Number Item
postUpdate( toUpdate.toString , triggeringItem.state.toString )
logDebug(_logger, "Item '" + toUpdate + "' state: " + triggeringItem.state)
end
scripts/uptime.sh (i had to remove " | bc" because it was retrieving me an error in the script.
#!/usr/bin/env bash
PID=`ps aux --sort=start_time | grep openhab.*java | grep -v grep | awk '{print $2}' | tail -1`
UPTIME=`ps -o etimes= -p "${PID}"`
echo $UPTIME/60
reboot.sitemap
sitemap reboot label="Controllo Sistema" {
Frame label="openHAB" {
Text item=System_CPU_Uptime
Text item=System_openHAB_Uptime_output
Text item=System_openHAB_Uptime
}
}
uptime.things
Thing exec:command:uptime [command="/etc/openhab2/scripts/uptime.sh", interval=60, timeout=2]
Thing systeminfo:computer:local [interval_high=2, interval_medium=60]
transform/duration.js
// computes nicely formatted duration from given minutes
(function(i){
var d = Math.floor(i / (24 * 60));
var h = Math.floor((i / 60) - (24 * d));
var m = Math.round(i - 60 * (24 * d + h));
var result = '';
// days
if (d > 0) {
result = result + d + ' day(s) ';
}
result = result + ("00" + h).substr(-2,2) + ":" + ("00" + m).substr(-2,2);
return result;
})(input)
this is the only openhab.log info that could help:
2018-10-08 13:07:29.674 [WARN ] [rthome.model.script.actions.BusEvent] - Cannot convert '798/60' to a state type which item 'System_openHAB_Uptime' accepts: [DecimalType, QuantityType, UnDefType].
thanks a lot