Get rid of 'Couldn't connect to server' in log when httpResponses server is down
Posted: Tuesday 17 January 2023 19:12
I am using a script to monitor the production of a Omnik/Hosola solar inverter (see below if you would like to reuse this, it also include a warning when the production is too low and a daily report of production).
When the sun is not shining, the inverter is powered down. Which means that the http response will give an error in the domoticz log:
2023-01-17 19:11:03.558 Error: Error opening url: http://xx/js/status.js
2023-01-17 19:11:03.658 Error: dzVents: Error: (3.1.8) Omnik Solar: HTTP/1.1 response: 7 ==>> Couldn't connect to server
Is there a way to prevent that this error message is shown for this particular script? It pollutes my error log every night
When the sun is not shining, the inverter is powered down. Which means that the http response will give an error in the domoticz log:
2023-01-17 19:11:03.558 Error: Error opening url: http://xx/js/status.js
2023-01-17 19:11:03.658 Error: dzVents: Error: (3.1.8) Omnik Solar: HTTP/1.1 response: 7 ==>> Couldn't connect to server
Is there a way to prevent that this error message is shown for this particular script? It pollutes my error log every night
Code: Select all
local MANUAL_OVERRIDE_SWITCH = 383
local SWITCH_OMVORMER = 382
return {
active = true,
on = {
timer = {
'every minute', -- starting from xx:00 triggers every xx minutes (0 > xx < 60)
},
httpResponses = { "Omnik" }, -- do not change this
devices = {
MANUAL_OVERRIDE_SWITCH,
SWITCH_OMVORMER
},
},
logging = {
level = domoticz.LOG_ERROR,
marker = 'Omnik Solar',
},
data =
{
last_production =
{
initial = "0"
},
},
execute = function(dz, item)
local script_name = 'Zonnepanelen 🌞: '
-- uitschakelen van script
local manualOverrideSwitch = dz.devices(MANUAL_OVERRIDE_SWITCH)
if (item == manualOverrideSwitch and manualOverrideSwitch.state == 'On') then
telegram.sendText(telegram.getId('rik'), script_name .. 'het script is handmatig uitgeschakeld (disable script switches)')
dz.log(script_name .. 'is handmatig uitgeschakeld (disable script switches)', dz.LOG_DEBUG)
return
end
local maxResponseSeconds = 720
local OmnikIP = 'xx' -- Your local Omnik inverter IP Address
local production_device = 379 -- IDX of dummy electricity instant and counter device
local total_device = 380 -- IDX of dummy custom sensor (total kwh)
local current_device = 381
local switch_omvormer = dz.devices(SWITCH_OMVORMER)
local alert = dz.devices(378) -- Alert device
local round = dz.utils.round
local function checkWebpageResponse()
local deltaSeconds = dz.time.dDate - dz.data.previousRainSample
if ( maxResponseSeconds > 0 ) and ( deltaSeconds > maxResponseSeconds ) then
dz.notify(scriptVar, 'Omnik Inverter did not respond within ' .. tostring(maxResponseSeconds) .. ' seconds.')
end
end
local function getOmnikData()
local urlstring = 'http://' .. OmnikIP .. '/js/status.js'
dz.openURL ({ url = urlstring, callback = "Omnik" })
end
local function processHTM()
OmnikData = (item.data):gsub('"',''):gsub("'","")
OmnikArray = string.match(OmnikData, 'myDeviceArray%[0%].+,;')
--dz.log('Omnik Array: ' .. OmnikArray,dz.LOG_INFO)
splittedResult = dz.utils.stringSplit(OmnikArray,',')
strOmnikCurrentWatt = splittedResult[2] -- Amount in Watt
strOmnikkWhToday = splittedResult[3] -- Amount in kWh of the day, not used
strOmnikTotalkWh = splittedResult[4] -- Total generated kWh needs to be converted to Wh
OmnikCurrentWatt = tonumber(strOmnikCurrentWatt)
OmnikkWhToday = tonumber(strOmnikkWhToday)/100
OmnikTotalWh = tonumber(strOmnikTotalkWh)*100
--dz.log("Received Data: Current Power: " .. OmnikCurrentWatt ..' W',dz.LOG_INFO)
--dz.log("Received Data: Daily Power: " .. OmnikkWhToday .. ' kWh',dz.LOG_INFO)
--dz.log("Received Data: Total Power: " .. OmnikTotalWh/1000 .. ' kWh',dz.LOG_INFO)
-- update Omnik electricity instant and counter device
dz.devices(production_device).updateElectricity(OmnikCurrentWatt, OmnikTotalWh)
dz.devices(total_device).updateCustomSensor(OmnikTotalWh/1000)
dz.devices(current_device).updateCustomSensor(OmnikCurrentWatt)
end
-- Main
if item.isTimer then
--checkWebpageResponse()
getOmnikData()
elseif item.isHTTPResponse and item.ok then -- statusCode == 2xx
processHTM(item.data)
switch_omvormer.switchOn().checkFirst()
--dz.log(item.data,dz.LOG_DEBUG)
elseif item.isHTTPResponse then -- Inverter staat uit
--telegram.sendText(telegram.getId('rik'), 'Zonnepanelen komt geen data binnen')
--dz.log('Could not get (good) data from ' .. OmnikIP,dz.LOG_ERROR)
--dz.log(item.data,dz.LOG_DEBUG)
switch_omvormer.switchOff().checkFirst()
elseif item == switch_omvormer then
if switch_omvormer.state == 'Off' then
telegram.sendText(telegram.getId('rik'), script_name .. 'Omvormer schakelt uit, dagproductie:' .. dz.devices(production_device).counterToday .. 'kWh')
elseif switch_omvormer.state == 'On' then
telegram.sendText(telegram.getId('rik'), script_name .. 'Omvormer schakelt in')
end
end
if item.isTimer and dz.time.matchesRule('at 22:00') then
local solar_production = dz.devices(production_device).counterToday -- IDX van Productie zonnepanelen in W en totaal kWh
if round(tonumber(solar_production),1) == 0 then
telegram.sendText(telegram.getId('rik'), 'đź”´ Zonnepanelen lijken niet te werken. Dagproductie: ' .. solar_production .. 'kWh')
alert.updateAlertSensor(dz.ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')
elseif dz.data.last_production == solar_production then
telegram.sendText(telegram.getId('rik'), 'đź”´ Zonnepanelen lijken niet te werken. Productie gelijk aan gisteren: ' .. solar_production .. 'kWh')
alert.updateAlertSensor(dz.ALERTLEVEL_RED, 'Zonnepanelen lijken niet meer te werken')
elseif round(tonumber(solar_production),1) >= 1 then
alert.updateAlertSensor(dz.ALERTLEVEL_GREEN, 'Zonnepanelen werken naar behoren')
-- telegram.sendText(telegram.getId('rik'), 'Zonnepanelen dagproductie:' .. solar_production .. 'kWh')
elseif round(tonumber(solar_production),1) > 0 then
alert.updateAlertSensor(dz.ALERTLEVEL_ORANGE, 'Zonnepanelen lijken slechter te werken')
telegram.sendText(telegram.getId('rik'), '🟡 Zonnepanelen lijken slechter te werken. Dagproductie: ' .. solar_production .. 'kWh')
end
dz.data.last_production = solar_production
end
end
}