I have a single RM rule (effectively, it's an API) to speak and notify devices of events. It also logs each event with a prefixed timestamp to a local log file. I'd like to display the last 2 or 3 lines of the file in a dashboard tile. Setting a variable to the file's content overruns the variable's maximum byte size but heads the file, not tails it. Is there a way to set the variable to the last n lines of the file? Or perhaps there's a different/better way to show the last 2 or 3 events from the log file on the dashboard?
Since I assume you have access to the log message in Rule Machine before writing it to the log file, maybe it is easier to just deal with the messages in RM and not try to pull them back out of the file after writing to it.
This may not be very efficient, but one way would be to cascade the messages through different variables. Assuming RM can see a value called log_msg, create local variables: msg_1, msg_2, msg_3, and global hub variable msg_to_display:
On change of log_msg:
set variable msg_3 to %msg_2%
set variable msg_2 to %msg_1%
set variable msg_1 to %log_msg%
set variable msg_to_display to %msg1% %msg2% %msg3% (or vice-versa)
msg_to_display will always contain the 3 latest log messages.
That's what I have right now for n-1 instances. I just added the file logging so I can look back much further so figured I'd try and optimize the rule. The linked variable dashboard tile works as-is for 2 events and has a button tile stacked atop it that links to the Hubitat filesystem to display the entire log. That works locally but I can't get it working via remote admin from the app. It does, however, work remotely from a legit browser.
Appreciate the input.