WARNING: Users who have this template already installed for versions of OH 5.1 and before, after removing the old template and installing this new one, open your rule(s), click on the code tab, and change the ruleTemplate property to ohrt-lastShutdown before regenerating the rule.
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
Sponsorship
If you want to send a tip my way or sponsor my work you can through Sponsor @rkoshak on GitHub or PayPal. It won’t change what I contribute to OH but it might keep me in coffee or let me buy hardware to test out new things.
