I connected my pv system (SolarEdge) to Domoticz, but sometimes the API connection gets lost.
I wrote scome scripts to connect my room lights te the actual power generation.
When it is dark (no actual generation) my lights will switch on.
In cases the actual power generation will not be updated my light will not switch on. So I wrote a script to reset te actual power generation when the actual generation is greater than 0 and the the last update of the device is more than 15 minutes ago.
The problem is the log shows an error "attempt to call a nil value (field 'updateEnergy')"
Does anyone have an idea?
Code: Select all
local pv = 114
return {
on = {
timer = {
'every 5 minutes',
}
},
logging = { level = domoticz.LOG_DEBUG },
execute = function(dz, item)
local pvActual = dz.devices(pv).actualWatt
local pvLastupdated = dz.devices(pv).lastUpdate.minutesAgo
if (pvLastupdated > 15 and pvActual > 0)
then
dz.devices(pv).updateEnergy('0')
dz.log('Actuele opwekking: ' .. pvActual .. ' watt',LOG_DEBUG)
dz.log('Laatst bijgewerkt: ' .. pvLastupdated .. ' minuten geleden',LOG_DEBUG)
dz.log('Bijgewerkt: Ja',LOG_DEBUG)
else
dz.log('Actuele opwekking: ' .. pvActual .. ' watt',LOG_DEBUG)
dz.log('Laatst bijgewerkt: ' .. pvLastupdated .. ' minuten geleden',LOG_DEBUG)
dz.log('Bijgewerkt: Niet nodig',LOG_DEBUG)
end
end
}