Last Shutdown Timestamp [5.0.0.0;5.9.9.9]

Pulls the timestamp from the last log entry in the most recent events.log archive as a proxy for the time when OH shutdown last.

The theory is that the last log entry in events.log will be very close to the time when OH went offline. I use events.log because every log entry is guaranteed to be one line so I don’t need to search for a line with a timestamp. events.log is also constantly being written to on a typical OH install. On a normal shutdown, the last log will be when the last Thing is unloaded.

This template depends on a close to default config for events.log. If you’ve modified the logging config to suppress a lot of events from being logged, or disabled the log rotation that occurs when OH starts up this template may not work well for you.

Note, if you are running openHABian with zram enabled and the machine loses power, it will lose all the logs so the timestamp returned will be from the last normal shutdown of the RPi.

Language: JS Scripting

Dependencies:
JS Scripting addon

Changelog

Version 0.2

  • rewrote using Java file classes so the template will work for all installations, not just POSIX.
  • added a log info level log to indicate when OH was last shutdown

Version 0.1

  • initial release

Resources

https://raw.githubusercontent.com/rkoshak/openhab-rules-tools/refs/heads/main/rule-templates/lastShutdownTime/lastShutdownTime.yaml

1 Like