rule "openHAB uptime formatieren"
when
Item UptimeRaw received update
then
val input = newState.toString.split(" ")
val datum = input.get(0)
val uhrzeit = input.get(1)
val tz = input.get(2)
var st = "+0100"
if (tz == "CEST") st = "+0200"
val dtOnline = DateTimeType.valueOf(datum + "T" + uhrzeit + st)
val uptime = Duration.between(dtOnline.getZonedDateTime(ZoneId.systemDefault), now).toSeconds
val Minutes = (uptime / 60) % 60
val Hours = (uptime / 60 / 60) % 24
val Days = (uptime / 60 / 60 / 24).intValue
var zeit = Days.toString + " Tage "
switch Days.intValue {
case 0 : zeit = ""
case 1 : zeit = "1 Tag " }
zeit += Hours.toString + " Std. " + Minutes.toString + " Min. "
OH_UptimeText.postUpdate(zeit)
end
logger.info java.lang.management.ManagementFactory.runtime_mx_bean.uptime # in milliseconds
# Convert it to a Duration object:
uptime_duration = java.lang.management.ManagementFactory.runtime_mx_bean.uptime.milliseconds
logger.info uptime_duration
logger.info "openHAB was started less than an hour ago" if uptime_duration < 1.hour
Yes, but for me it is the same
There is no reason for me to only restart OpenHab.
When I do a system update I also restart the whole system to finalize the procedure and see that everything comes up properly.
Create a simple rule that triggers at a system runtime level and post an update to a DateTime Item. You can use and expression like =dayjs(items.SystemStart.state).fromNow() in a MainUI widget and you’ll get a text like “3 days ago”. This will give you how long OH has been operational, not just when it was started.