This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Event log creation and presentation

Is it possible to have an event log presentation in the LM visualization?
For example, each time a door or window contact opens or a PIR is triggered a log line to be created with a time stamp like this:

- Mon 21/7/2016
  12:32:     Door opened
  10:32:     Movement detection in living room
- Tue  22/7/2016
  21:01:     Bedroom window opened
  22:12:     Door opened
  00:00:     AC turned off


This log needs to be stored in memory for a configurable max number of events (lets say up to 1000) and after that limit, any new events will delete the older one etc so anytime you can have the last 1000 events.
Is there a way to create and present in LM visualization such an event log?
Thank you in advance
You can use storage engine to create a queue, here's a function that adds an item to a list named eventlog and trims the list to contain up to 1000 entries. Date/time is added automatically, so you only need to supply event text. Create event scripts to log whichever info you need.
function eventlog(text)
  local max = 1000 -- max number of entries

  -- add formatted date
  text ='%a %d/%m/%Y %T ') .. text

  storage.exec('lpush', 'eventlog', text)
  storage.exec('ltrim', 'eventlog', 0, max - 1)

To output the list to client side you can create an .lp page and display it in the visualization via iframe. Create a file called eventlog.lp and upload it to user folder via FTP. Set iframe URL to /user/eventlog.lp
items = storage.exec('lrange', 'eventlog', 0, 999)
<!DOCTYPE html>
  <meta charset="UTF-8">
  <title>Event log</title>
  <script src="/apps/js/jquery.js.gz"></script>
  <link rel="stylesheet" href="/apps/css/bootstrap.css">
$(function() {
  var items = <? json.write(items) ?>
    , container = $('.container')
    , header;

  $.each(items, function(index, item) {
    var chunks = item.split(' ')
      , newheader = chunks.shift() + ' ' + chunks.shift();

    // output data header each time it changes
    if (newheader != header) {
      header = newheader;

    // output log entry
    $('<p></p>').text(chunks.join(' ')).appendTo(container);
<div class="container"></div>

Note that newest items come on top of the list.
FTP upload docs:
Wow, thank you very much for this fast and delicate solution...
I will try it this weekend... Smile
Well it works like a charm, thank you once again.
Can I ask if I should be able to see this list in the storage tab?
Also, is it possible to access this log outside the LM or export it for backup or use the information with other programs like excel etc?
Thank you
For now, item type "list" is not supported directly by storage.get, so you won't be able to see it in storage viewer. As for export you can adapt previously published scripts. This command returns all log entries as a Lua table (plain array) and converts them to plain text with each log item on a new line:
items = storage.exec('lrange', 'eventlog', 0, 999)
text = table.concat(items, '\r\n')
Is it possible show the list with more color ?

For example:
- green for alert finished
- red for alert started
KNX Advanced Partner + Tutor
(03.05.2019, 09:16)toujour Wrote: Is it possible show the list with more color ?

For example:
- green for alert finished
- red for alert started

Try Alert Manager app.

Forum Jump: