w2vy
(Thomas Moulton)
1
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?
Tom
// Example pseudo-code
items Log_Current, Log_Old1, LOg_Old2, Log_Old3, etc
rule "update log"
when
Item Log_Current changed
then
postUpdate(Log_Old3, Log_Old2.state)
postUpdate(Log_Old2, Log_Old1.state)
postUpdate(Log_Old1, Log_Current.state)
end
Then have a page that displays then in order newest to oldest
Log_Old1
Log_Old2
Log_Old3
etc
thoughts?
Tom
rlkoshak
(Rich Koshak)
2
You can only put an Item’s current state on the sitemap so your current approach is the only one to solve this.
w2vy
(Thomas Moulton)
3
How can I test to see if an item is UnInitialized?
rlkoshak
(Rich Koshak)
4
MyItem.state == Undefined
or
MyItem.state == Uninitialized
I don’t remember which one means what.
w2vy
(Thomas Moulton)
5
For a string Uninitialized worked…
Of course I tried that but mispelled it
thanks
w2vy
(Thomas Moulton)
6
Well I have it working, here is what I did:
items/event_log.items
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)
rules/event_log.rules
rule "New Event Log"
when
Item EventLog changed
then
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)
end
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")
5 Likes
glufonec
(glufonec)
7
Haha I do the same with 12 items. It is importand to have a log
https://dl.dropboxusercontent.com/u/13936640/Untitled.png
greg
(Greg)
8
@w2vy Thanks for sharing this. Quite handy to have!
For anyone wanting to do with OH2, replace “Uninitialized” with “NULL” in the rule.
Cheers,
Greg
1 Like
andrezero
(Andrés Córdova)
9
Hi. I can not make it work in Openhab 2. It just saves the first event.
rossko57
(Rossko57)
10
Sounds like your rule doesn’t run, then. What does openhab.log
tell you?
andrezero
(Andrés Córdova)
11
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"
when
Item EventLog received update
then
val String PATTERN = " HH:mm"
var String ts = now.toString(PATTERN)
...
received update insted of changed.
That did the trick for me.
Thanks!
rossko57
(Rossko57)
12
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.
andrezero
(Andrés Córdova)
13
Yes, but in my case I am logging who opens a deadbolt. So sometimes it is the same log with different timestamps.
rossko57
(Rossko57)
14
That’s fine, it’s not an error just a choice of triggers to suit yourself.