This here is a litte projekt how to show your OpenHab uptime since last restart.
It does not show the uptime of your Raspi this could be much longer.
Its running on my rpi3b+ on OH 2.4.
My approach was the following:
If you type “openhab-cli uptime” at the raspi console you will return a message like this:
A systemd service configuration exists...
Use 'sudo /bin/systemctl status openhab2.service' to find the status of an openHAB service
openHAB is running with PID: 2066 and has been running for 82-11:36:28
In the end of this string we see: “the runtime of OpenHab is: 82 days 11 hours 36 minutes 28 seconds”
I want to put that in the sitemap.
First you need the Exec Binding.
Then create a the following thing:
Thing exec:command:openhabuptime2 [command="openhab-cli status", interval=3600, timeout=5] //OpenHab Uptime
For this we need two items.
The first item receives what the command “openhab-cli status” returns as a string.
The second item then receives the concatenated string of the values for the sitemap via a rule.
Here are the items:
String BefehlOutputOpenHabUptime "Rückgabewert" {channel="exec:command:openhabuptime2:output"}
String OpenHabUptime "OpenHab uptime [%s]"
And the Rule that splits the String und put it in to the Item for the Sitemap:
// https://openhabforum.de/viewtopic.php?f=15&t=3855
rule "OpenHab Uptime"
when
Item BefehlOutputOpenHabUptime changed
then
// Suche nach 'running for'
var newValue = BefehlOutputOpenHabUptime.state.toString.split('running for ').get(1).trim
newValue = newValue.substring(0,11)
// log das Ergebnis
logInfo('OpenHab Uptime String:',newValue)
val Tage = newValue.split('-').get(0).trim
val Zeit = newValue.substring(3,11)
val Stunden = Zeit.split(':').get(0).trim
val Minuten = Zeit.split(':').get(1).trim
// log das Ergebnis
logInfo('OpenHab Uptime Tage:',Tage)
logInfo('OpenHab Uptime Zeit:',Zeit)
logInfo('OpenHab Uptime Stunden:',Stunden)
logInfo('OpenHab Uptime Minuten:',Minuten)
// post the new value to the Item
OpenHabUptime.postUpdate((( Tage + " DAYS, ") + (Stunden + " HOURS, ")) + ((Minuten + " MINUTES" )))
end
It look like that at the sitemap:
Have fun!