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?
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 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.
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: