All, this is my first post and I have been playing around with Openhab 2 and HabPanel since 2 weeks now. Thank you all for providing this great scripts and tweaks. Please let me briefly share how I tweaked the scripts and rules to have the last calls read into items and presentend them in a template:
(1) I took the initial script posted at the start of this thread and added one line at the end to create a short file with 10 lines only. Then I wrote a 1-liner called extrac.sh which gives back only one line of the caller log, by providing the line number, e.g. ā./extract.sh 5ā gives you call number 5 from the short file.
grep ā^1|^2|^3|^4ā -m 10 /etc/openhab2/persistence/fritzcalls.txt > /etc/openhab2/persistence/fritzcalls-short.txt
extract.sh:
#!/bin/bash
head -$1 /etc/openhab2/persistence/fritzcalls-short.txt | tail -1 | grep ''
(2) Items definition:
Group gFritzCalls
String fritzCall1 āCall 1ā (gFritzCalls)
String fritzCall2 āCall 2ā (gFritzCalls)
String fritzCall3 āCall 3ā (gFritzCalls)
String fritzCall4 āCall 4ā (gFritzCalls)
String fritzCall5 āCall 5ā (gFritzCalls)
String fritzCall6 āCall 6ā (gFritzCalls)
(3) Rules: obviously the one getting (and shortening) the Fritz caller log. And then the one raeding the files into the above items by going through the group:
rule āUpdate calllistā
when
Time cron ā0 0/2 * ? * * *ā // every two minutes
then
logInfo(āFritzboxā," Calllist wird neu geladen")
executeCommandLine("/etc/openhab2/scripts/callmonitor.sh")
end
rule āUpdate callitemsā
when
Time cron ā0 0/5 * * * ?ā
then
val index = 1
gFritzCalls.members.forEach [ item |
postUpdate(item,executeCommandLine("/etc/openhab2/scripts/extract.sh " + index, 1000))
index++
]
end
(4) Template in HabPanel, having the phone icons stored as fritz-1.gif etc. representing the call type from the call-list. Splitting the items by ā;ā
<table class="table-standard">
<caption>Anrufe</caption>
<tr>
<th>Typ</th>
<th>Datum</th>
<th>Name</th>
<th>Nummer</th>
<th>Dauer</th>
</tr>
<tr ng-repeat="item in itemsInGroup('gFritzCalls')" align="left" cellpadding="2px" border="none">
<td><img src="/static/icons/own/fritz-{{itemValue(item.name).split(';')[0]}}.gif"</td>
<td>{{itemValue(item.name).split(';')[1]}}</td>
<td>{{itemValue(item.name).split(';')[2]}}</td>
<td>{{itemValue(item.name).split(';')[3]}}</td>
<td>{{itemValue(item.name).split(';')[6]}}</td>
</tr>
(5) Result: > I am very happy with the result!