Found this discusion because i want the same thing. Copied the script and edited to my need. Works as a charme. I have one question. Is it normaal that it logs in the error log of domoticz every time it finds a error message?
this is the script i have running every three minutes.
Code: Select all
-- WLED: No transport, write directive to 'JSONConn' ignored.
myHttpResponse = "getDomoticzErrorLog"
return {
on = { httpResponses = { myHttpResponse },
timer = { "every 3 minutes"},
},
logging = { level = domoticz.LOG_DEBUG,
marker = "getStr from log" },
data = { lastlogtime = { initial = 0 }},
execute = function(dz, trigger)
local searchStr = "WLED: No transport, write directive to 'JSONConn' ignored." -- Change to reflect the messages you want to catch
local function askDomoticzForLogLines()
local lastLogTime = dz.data.lastlogtime -- get time last logrequest
local logLevel = 4 -- loglevel (1=normal,2=Status,4=error,268435455=all
local jsonString = "/json.htm?type=command" ..
"¶m=getlog" ..
"&lastlogtime=" .. tostring(lastLogTime) ..
"&loglevel=" .. tostring(logLevel)
local logURL = dz.settings["Domoticz url"] .. jsonString
dz.openURL ({ url = logURL,
method = "GET",
callback = myHttpResponse
})
dz.data.lastlogtime = dz.time.dDate -- store current Time as seconds from epoch
end
local function findString()
if trigger.json.result ~= nil then -- Only when there are errormessages in the log
local resultTable = trigger.json.result
for i = #resultTable,1,-1 do -- traverse backwards to get latest violation first
local s = resultTable[i].message
local found = s:find(searchStr,1,true) -- searcg plain string starting at pos 1 (no pattern)
local dzVents = s:find("dzVents")
if found and not(dzVents) then
return true
end
end
end
end
if trigger.isDevice or trigger.isTimer then
askDomoticzForLogLines() -- get the relevant loglines
elseif trigger.ok then
dz.log("Show ALL: \n" .. trigger.data,dz.LOG_DEBUG)
if findString() then
dz.log("string " .. searchStr .. " found!!!!!!!!!! ",dz.LOG_DEBUG)
if dz.devices('Vir_Openhaard').state == 'On' then
dz.log("Zou Openhaard aan moeten gaan",dz.LOG_DEBUG)
dz.devices('Openhaard').switchOff()
-- else
-- dz.devices('Openhaard').switchOn()
end
-- dz.notify('Openhaard gereset vanwege WLED foutmelding',dz.PRIORITY_LOW)
-- dz.notify("searchStr", searchStr, dz.PRIORITY_NORMAL, nil, nil, dz.NSS_PUSHOVER)
else
dz.log("No (new) occurrences of string " .. searchStr .. " in the domoticz log ",dz.LOG_DEBUG)
end
else
dz.log("Access problem to log. Data found: " .. trigger.data,dz.LOG_ERROR)
end
end
}
In the error log of domoticz it looks like this:
2023-02-09 14:22:16.581 Error: Error parsing http request address: ::ffff:35.216.132.205
2023-02-09 14:22:16.591 Error: dvVents: Debug: getStr from log: Show ALL:
2023-02-09 14:22:16.591 {
2023-02-09 14:22:16.591 "LastLogTime" : "1675948936",
2023-02-09 14:22:16.591 "result" :
2023-02-09 14:22:16.591 [
2023-02-09 14:22:16.591 {
2023-02-09 14:22:16.591 "level" : 4,
2023-02-09 14:22:16.591 "message" : "2023-02-09 14:22:16.581 Error parsing http request address: ::ffff:35.216.132.205"
2023-02-09 14:22:16.591 }
2023-02-09 14:22:16.591 ],
2023-02-09 14:22:16.591 "status" : "OK",
2023-02-09 14:22:16.591 "title" : "GGetlog"
2023-02-09 14:22:16.591 }
2023-02-09 14:22:16.591
Any idea why this appears in the error log? Is it something to wory about?