I’ve just added a rule that allows OpenHAB uptime to be displayed in a human readable format, and also reboot the system in the middle of the night once it has been up for over 7 days. As I’m doing a lot of work on the system I’ve steered away from a simple cron style reboot, and intend extending the time between reboots once I know how long it can go before it has problems. Before updating to OH2 it needed to reboot twice a week to prevent the user interface from throwing can’t read sitemap type errors, after about 6 days, and usually at an inconvenient time. I decided not to use the system info binding to save on clock cycles

I am curious how you would (automatically) retrieve the uptime of the openHAB (java) process, since the SystemInfo binding does not let you determine a process id. The SystemInfo binding does give you the computer uptime, however.

For my purposes (display only, no scheduled reboots) I have both the computer uptime through the SystemInfo binding and the uptime of the openHAB process (usually shorter, since I tend to restart the openhab2.service every now and then) through the Exec binding.

I am curious how you would (automatically) retrieve the uptime of the openHAB (java) process

The rule sets an item - OHStartedAt- at startup with the current time, and then once this is set, every minute it subtracts that from the current time to give the uptime. As I always reboot the whole system rather than restarting the service it gives me an approximate runtime.

There are of course several other ways to do this, and as I couldn’t find one I wrote my own and posted it.

Nice alternative way - I have yet to tame the new exec binding so everything I do is via a rule so far.

This is working great for me, too!
The only addonI have is the comment above - it computes duration from given seconds…
The script is nearly the same as for the uptime in the systeminfo binding (Community post) (provided also by Robert)- but only nearly:
The systeminfo binding script really calculates system uptime from given minutes (provided by the binding).
It is missing the

// seconds to minutes
i = Math.floor(i / 60)

So you have to use a different script for openhab runtime than for system runtime.
Maybe that helps others not to stumble into the same problem as me…
.

Thanks for this, nice and simple. Although your cron format is wrong. Unsure what time of the day 50 o’clock is

...cron "0 50 3 * * ?"...

I also get this when saving the rules file. Still seems to work though.

2018-01-31 11:16:44.982 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model ‘home.rules’, using it anyway:
Assignment to final field
Constant condition is always false.

I had this rule by @kevin and it was working great until I added dbmap Persistence and now on every reboot the system maintains the original “OHStartedAt” value…there for I would get in to a constant reboot scenario if I hadnt commented out the final part of the rule that does the reboot… Anyone know why or how to reset the “OHStartedAt” value on a reboot?

I’m using the persistence groups as kind of tags for items. Every item that gets persisted, is in the gPersist group. Every item which should be restored on startup is in gRestoreOnStartup. I do not use gLights or gPower in persistence, a persisted lights item is in both groups.

I would like to share my setup for tracking uptime, adapted from the posts here and extended using java specific functionality.

I am using the following for tracking PC uptime (“CPU uptime”) and openHAB uptime. The solution uses java’s ManagementFactory to access the uptime of the openHAB java process, and systeminfo addon to access PC uptime (“cpu uptime”). The rules are setup such that they do not rely on persistence, and the values are restored even if items are re-created, e.g. when modifying the items file.