Is it possible to setup PLEG to detect if there is downtime on the system?
I am thinking about the kind of errors that would be shown in the UI “display”.
Lua failed to start, something failed in a PLEG etc…
So sort of what I am asking is if the UI display is available as a device propertie or trigger?
I definitely want to know if a PLEG is not running for some reason. Of course I can not use PLEG1 to detect if there is something wrong with PLEG1 
regards
I’m not sure a PLEG is the best place to check if another PLEG is OK. Some problems could bust them all.
You could add some code to Startup Lua that, after a delay of one minute, uses luup.is_ready() to see if each PLEG completed startup. If any return false, you could fire some appropriate action.
The following code checks all the device IDs listed in the table “{ID1, ID2,…IDN}” in the first line. Add code for whatever action is required when a device is not ready.
[code]luup.call_delay(“checkPLEGs”,60,“{21,46,77,113}”)
function checkPLEGs(devstring)
assert(loadstring(“devtable=”…devstring))()
for i=1, #devtable do
if not luup.is_ready(devtable[i]) then
–
– Take appropriate action for PLEG not ready
–
end
end
end[/code]
Could this be something that could be implemented in the PLEG as a feature?
If PLEG is considered to fail to load a scene can be set to run?
Awesome, I can use this idea to provide a voice TTS notification if any of my two Vera’s get error on start.
Would the code below allow the code to loop without a memory leak? That way if I’m sleeping or the audio isn’t on, it will repeat every minute.
luup.call_delay("checkPLEGs",60,"{21,46,77,113}")
function checkPLEGs(devstring)
assert(loadstring("devtable="..devstring))()
for i=1, #devtable do
if not luup.is_ready(devtable[i]) then
-- TTS Code
local ttsMsg = "Alert, Home Automation Error Detected on Primary Vera Unit"
local socket = require("socket")
local udp = socket.try(socket.udp())
ttshost = "192.168.0.100"
socket.try(udp:sendto("tts.speak&&" .. ttsMsg, ttshost, 33000))
-- Repeat in 1 minute
luup.call_delay("checkPLEGs",60,"{21,46,77,113}")
end
end
end
Also, could I expand this to give me an error status for any device that fails to start? Not PLEG specific, so may be better for my to post in another forum category if preferred.
Would the code below allow the code to loop without a memory leak?
My only reservation is that you are potentially calling for a recheck of the whole list of devices each time any one of them is not ready. That could result in an exponential growth in the number of outstanding calls. A better approach would be to only recheck the device that is not ready.
...
-- Repeat in 1 minute
luup.call_delay("checkPLEGs",60,"{devtable[i]}")
...
Also, could I expand this to give me an error status for any device that fails to start?
It should work for any plugin that fails to initialise.
Thanks Rex!
I used your idea to have:
- Message box on my TV on every Vera Restart
- Voice and Message box repeats every 5 minutes if PLEG (device #436) or my Z-Wave network fails (device #1, untested)
luup.call_delay("checkDevice",60,"{436,1}")
local wmcMsg = "Primary Vera Unit has finished restarting"
local socket = require("socket")
wmchost = "192.168.0.100"
tcp = assert(socket.connect(wmchost, 40500))
tcp:send("msgbox \"Alert\" \"" .. wmcMsg .. "\" 15")
tcp:close()
function checkDevice(devstring)
assert(loadstring("devtable="..devstring))()
for i=1, #devtable do
if not luup.is_ready(devtable[i]) then
-- TTS Code
local ttsMsg = "Alert, Home Automation Error Detected on Primary Vera Unit. Please logon to the IP address 192.168.0.3 to investigate."
local wmcTitle = "Alert"
local wmcMsg = "Home Automation Error Detected on Primary Vera Unit. Please logon to the IP address 192.168.0.3 to investigate."
host = "192.168.0.100"
local socket = require("socket")
local udp = socket.try(socket.udp())
socket.try(udp:sendto("tts.speak&&" .. ttsMsg, host, 33000))
tcp = assert(socket.connect(host, 40500))
tcp:send("msgbox \"" .. wmcTitle .. "\" \"" .. wmcMsg .. "\" 8")
tcp:close()
-- Repeat in 5 minutes
luup.call_delay("checkDevice",300,"{436,1}")
end
end
end
I’m happy to hear it was useful but I’m not sure you intended to leave this in your code:
-- Repeat in 1 minute
luup.call_delay("checkDevice",60,"{21,46,77,113}")
Oh, thanks! Missed those device id’s
I’m looking forward to searching the forums on some similar code I’m sure you’ve already posted that can warn me if any battery device is under 25% full. Maybe every hour instead message box or a TTS alert.
[quote=“AgileHumor”]Oh, thanks! Missed those device id’s
I’m looking forward to searching the forums on some similar code I’m sure you’ve already posted that can warn me if any battery device is under 25% full. Maybe every hour instead message box or a TTS alert.[/quote]
Have you consider looking at using Battery Monitor rather than code?
http://apps.mios.com/search.php?key=Battery
@Brientim-Never saw that plugin before. THanks! 
The only thing is once it is installed it to setup the scene in the Advanced tab for Battery Monitor to Check and schedule frequency… You then have the Ability to set notification for known limits.
This is the code I used based on @Brientim. I use a scene external from PLEG that runs the bettary check event every 30 minutes.
Triggers
Low_Battery_Detected Battery Monitor Low Level true 2014-03-10 10:44:46.483 2014-03-10 10:44:46.380
Warning_Battery_Detected Battery Monitor Warning Level false 0 2014-03-10 10:44:46.483
Schedules
Name Type Time Days Random On Delay Off After Type Off Time Off Days Random Off Delay State Last On Last Off
Repeat4hrs Interval 04:00:00 None None None false 2014-03-10 10:54:20.321 0
Repeat1hr Interval 1:00:00 None None None false 2014-03-10 10:54:05.755 0
Conditions
Conditions
Name Repeat Expression State Last True Last False
Low_Battery_Detected_Alert Yes Low_Battery_Detected and Repeat1hr true 2014-03-10 10:54:05.785 0
Warning_Battery_Detected_Alert Yes Warning_Battery_Detected and Repeat4hrs false 0 2014-03-10 10:54:20.355
Actions
LUA for Condition: Low_Battery_Detected_Alert
local ttsAction = “VC.TriggerEvent&&MainScreen”
local ttsMsg = “Critical Low Battery Alarm Detected.”
local wmcTitle = “Alarm”
local wmcMsg = “Critical Low Battery Alarm Detected. Please investigate Primary Home Automation Control System for specific device”
host = “192.168.0.100”
local socket = require(“socket”)
local udp = socket.try(socket.udp())
socket.try(udp:sendto(ttsAction, host, 33000))
luup.sleep(500)
socket.try(udp:sendto(ttsMsg, host, 33000))
luup.sleep(250)
tcp = assert(socket.connect(host, 40500))
tcp:send(“msgbox "” … wmcTitle … “" "” … wmcMsg … “" 8”)
tcp:close()
LUA for Condition: Warning_Battery_Detected_Alert
local ttsAction = “VC.TriggerEvent&&Intercom”
local wmcTitle = “Alert”
local wmcMsg = “Low Battery Alarm Detected. Please investigate Primary Home Automation Control System for specific device”
host = “192.168.0.100”
local socket = require(“socket”)
local udp = socket.try(socket.udp())
socket.try(udp:sendto(ttsAction, host, 33000))
luup.sleep(500)
tcp = assert(socket.connect(host, 40500))
tcp:send(“msgbox "” … wmcTitle … “" "” … wmcMsg … “" 8”)
tcp:close()