Email me upon new Log error
Posted: Sun Oct 30, 2016 3:28 pm
As I start trusting more and more critical activities to my Indigo home automation system (i.e. irrigation, security, etc.),I would like to be notified whenever an error appears in the Log. I know that the SQL Logger plugin will generate an event when a new error happens in the Log file, but here is a short AppleScript with shell script to email me whenever there is a new error in the Log file. This doesn't require configuring a separate database.
The script above requires a second, short script scheduled just after midnight to prepare for tomorrow's first Log file:
I wanted to make the first AppleScript into a "Folder Action", but I learned that there is no automatic action when a file is CHANGED -- only when a file is added or deleted. So I made this an Indigo schedule every hour. I hope you can use it.
- Joe
- Code: Select all
-- Schedule Indigo to run this script at 00:57 every hour
-- Do NOT include the word "error" in the name of this schedule or any other Indigo device, trigger, or group
set file1 to "/Library/Application Support/Perceptive Automation/Indigo 6/Logs/indigo_log.txt"
set file2 to "/Library/Application Support/Perceptive Automation/Indigo 6/Logs/Compare.txt"
set result1 to ""
try
do shell script "diff " & quoted form of file1 & space & quoted form of file2 & "| grep --ignore-case \"error\""
set result1 to result
end try
try
if result1 ≠ "" then
-- display dialog "Error" & result1
set value of variable "alarmCause" to "Indigo Log error:" & result1
execute group "Email Me"
-- assumes an Indigo action group to email you whatever is in the variable "alarmCause"
end if
end try
-- now copy current Log file over previous "Compare.txt" file for next time
do shell script "cp " & quoted form of file1 & space & quoted form of file2
The script above requires a second, short script scheduled just after midnight to prepare for tomorrow's first Log file:
- Code: Select all
-- Schedule Indigo to run this script every 12:01 am
set file1 to "/Library/Application Support/Perceptive Automation/Indigo 6/Logs/indigo_log.txt"
set file2 to "/Library/Application Support/Perceptive Automation/Indigo 6/Logs/Compare.txt"
try
do shell script "cp " & quoted form of file1 & space & quoted form of file2
end try
I wanted to make the first AppleScript into a "Folder Action", but I learned that there is no automatic action when a file is CHANGED -- only when a file is added or deleted. So I made this an Indigo schedule every hour. I hope you can use it.
- Joe