Display history of events in app

I use the notifications for a number of things, but when they occur my phone dings…

I would like to have a section of my sitemap (a page in the app) that shows a different history but I am not sure if there is an easy way to do it.

The hard way is to have 10 or 20 (or N) items and when the top one changes move the last entry down one slot to make room for the new one

(example below)

Is there a way I can use Persistence (like mysql) instead?


// Example pseudo-code
items Log_Current, Log_Old1, LOg_Old2, Log_Old3, etc

rule "update log"

    Item Log_Current changed
    postUpdate(Log_Old3, Log_Old2.state)
    postUpdate(Log_Old2, Log_Old1.state)
    postUpdate(Log_Old1, Log_Current.state)

Then have a page that displays then in order newest to oldest




You can only put an Item’s current state on the sitemap so your current approach is the only one to solve this.

How can I test to see if an item is UnInitialized?

MyItem.state == Undefined


MyItem.state == Uninitialized

I don’t remember which one means what.

For a string Uninitialized worked…

Of course I tried that but mispelled it :slight_smile:


Well I have it working, here is what I did:


Group gEventLog "Event Log" (All)

String EventLog00   " 1: [%s]" (gEventLog)
String EventLog01   " 2: [%s]" (gEventLog)
String EventLog02   " 3: [%s]" (gEventLog)
String EventLog03   " 4: [%s]" (gEventLog)
String EventLog04   " 5: [%s]" (gEventLog)
String EventLog05   " 6: [%s]" (gEventLog)
String EventLog06   " 7: [%s]" (gEventLog)
String EventLog07   " 8: [%s]" (gEventLog)
String EventLog08   " 9: [%s]" (gEventLog)
String EventLog09   "10: [%s]" (gEventLog)
String EventLog10   "11: [%s]" (gEventLog)
String EventLog11   "12: [%s]" (gEventLog)
String EventLog12   "13: [%s]" (gEventLog)
String EventLog13   "14: [%s]" (gEventLog)
String EventLog14   "15: [%s]" (gEventLog)
String EventLog15   "16: [%s]" (gEventLog)
String EventLog16   "17: [%s]" (gEventLog)
String EventLog17   "18: [%s]" (gEventLog)
String EventLog18   "19: [%s]" (gEventLog)
String EventLog19   "20: [%s]" (gEventLog)

Group gEventInternal "Event Vars" (All)
String EventLog     "Latest [%s]" (gEventInternal)


rule "New Event Log"
    Item EventLog changed
    val String PATTERN = " HH:mm"
    var String ts = now.toString(PATTERN)

    if (EventLog18.state != Uninitialized) postUpdate(EventLog19, EventLog18.state)
    if (EventLog17.state != Uninitialized) postUpdate(EventLog18, EventLog17.state)
    if (EventLog16.state != Uninitialized) postUpdate(EventLog17, EventLog16.state)
    if (EventLog15.state != Uninitialized) postUpdate(EventLog16, EventLog15.state)
    if (EventLog14.state != Uninitialized) postUpdate(EventLog15, EventLog14.state)
    if (EventLog13.state != Uninitialized) postUpdate(EventLog14, EventLog13.state)
    if (EventLog12.state != Uninitialized) postUpdate(EventLog13, EventLog12.state)
    if (EventLog11.state != Uninitialized) postUpdate(EventLog12, EventLog11.state)
    if (EventLog10.state != Uninitialized) postUpdate(EventLog11, EventLog10.state)
    if (EventLog09.state != Uninitialized) postUpdate(EventLog10, EventLog09.state)
    if (EventLog08.state != Uninitialized) postUpdate(EventLog09, EventLog08.state)
    if (EventLog07.state != Uninitialized) postUpdate(EventLog08, EventLog07.state)
    if (EventLog06.state != Uninitialized) postUpdate(EventLog07, EventLog06.state)
    if (EventLog05.state != Uninitialized) postUpdate(EventLog06, EventLog05.state)
    if (EventLog04.state != Uninitialized) postUpdate(EventLog05, EventLog04.state)
    if (EventLog03.state != Uninitialized) postUpdate(EventLog04, EventLog03.state)
    if (EventLog02.state != Uninitialized) postUpdate(EventLog03, EventLog02.state)
    if (EventLog01.state != Uninitialized) postUpdate(EventLog02, EventLog01.state)
    if (EventLog00.state != Uninitialized) postUpdate(EventLog01, EventLog00.state)
    if (EventLog.state != Uninitialized) postUpdate(EventLog00, EventLog.state + ts)

add to sitemap

  Frame label="Event Log" {
    Group item=gEventLog

This was done with OH 1.8.2
and then anywhere I want to add to the log I just do

postUpdate(EventLog, "This is a Status")

Haha I do the same with 12 items. It is importand to have a log


@w2vy Thanks for sharing this. Quite handy to have!

For anyone wanting to do with OH2, replace “Uninitialized” with “NULL” in the rule.


1 Like

Hi. I can not make it work in Openhab 2. It just saves the first event.

Sounds like your rule doesn’t run, then. What does openhab.log tell you?

You were right the rule was not running.
I found the error. In Openhab 2. you need to use in the " When" part of the .rules file:

rule "New Event Log"
    Item EventLog received update
    val String PATTERN = " HH:mm"
    var String ts = now.toString(PATTERN)


received update insted of changed.

That did the trick for me.


changed works just fine in OH2 … but obviously only when the log message actually changes. You may or may not want repeated logs of similar events.

Yes, but in my case I am logging who opens a deadbolt. So sometimes it is the same log with different timestamps.

That’s fine, it’s not an error just a choice of triggers to suit yourself.