Logbook of automatically performed actions

Hi,

my idea is to provide the residents of my smart home with a kind of logbook. This should visualize all actions that have been automatically performed by the system. Ideally, the entries could be categorized so that they can be filtered accordingly.

How could I implement something like this on a separate page?

Best regards
Daniel

I don’t think there’s an easy way to do this.

First of all you need to define what constitutes an “automatically performed action”. It’s receiving a temperature sensor reading and calculating the dew point a reportable action?

Then you’ll need to add code to your rules to record those things that qualify as actions in some way.

Now the hard part is showing this list in a meaningful way. There are lots of options but the best choice depends on information you’ve not provided such as which UI you are using, text or graphics, how much information per row, etc.

One approach could be to store the actions in an Item as JSON and use an oh-repeater card to parse that JSON into rows. You’ll have to do book keeping though and remove stuff that agrees out.

Yes, I think that makes sense: such an ‘action’ will be stored accordingly in the rules.

Do I understand this correctly? I store the log information in the state of an item? And then I use the persistence service to read this data?

Yes and no. UI Widgets can’t read persistence data so persistence is not involved (except for maybe restoreOnStartup).

You’ll have to store the full log of the actions as the state of the one Item encoded as a JSON array. Then the oh-repeater widget can parse that JSON, iterate over the entries and render a separate list widget for each entryt as a separate row in a card widgert. And then of course you’ll have to use a rule or rules to remove the old entries from the JSON as they age out and are no longer relevant.

I use this exact approach to track some recent history of my sprinkler system. My system sends brief text descriptions of its events, but the channel for this is only the current event, so I have a second item that collects the information.

My item is string item:

The rule is fairly straightforward. When the sprinkler event item linked to the channel changes this rule fires:

var tStamp = time.ZonedDateTime.now();
var timeForm = time.DateTimeFormatter.ISO_OFFSET_DATE_TIME;

historyItem = items.getItem('Sprinkler_TimerBox_History');
historyState = historyItem.state

history = JSON.parse(historyState);
history.unshift({"time": `${tStamp.format(timeForm)}`,"event": `${items.getItem('Sprinkler_TimerBox_ScheduleInfo').state}`});
while (history.length > 10) history.pop();

historyItem.sendCommand(JSON.stringify(history));

It gets the current list string and parses that back into an array. It adds the newest event (and a timestamp) to the 0 position of the array shifting all previous events down. Then if there are more than 10 events in the list it removes the oldest one before turning the array back into a string to be stored in the item again.

Then, a simple repeater which parses that JSON string:

- component: oh-repeater
  config:
    for: event
    in: =JSON.parse(items.Sprinkler_TimerBox_History.state)
    sourceType: array
  slots:
    default:
      - component: oh-list-item
        config:
          after: =loop.event.event
          title: =dayjs(loop.event.time).fromNow()

leads to a list in my sprinkler widget with that log history:

4 Likes

Thanks JustinG for the Details! I will try this out.