Occasional huge outliers in virtual energy meter's cumulative counter value
Posted: Wednesday 23 February 2022 10:46
I have created a few virtual meters, one of which is used to track how much of my PV production is being immediately consumed rather than being returned onto the grid. The virtual meters are being fed from a LUA script (below). My issue is that occasionally the virtual meter's log shows huge values being logged for the energy component of the virtual meter, which are almost immediately compensated for a large negative log entry.
What might the cause be?
Here is the script. The graph corresponds with ownconsmeter (id 123).
What might the cause be?
Here is the script. The graph corresponds with ownconsmeter (id 123).
Code: Select all
function timeOffset( sDate_ )
local t1 = os.time()
local t2 = parseDate( sDate_ )
return os.difftime( t1, t2 )
end
function parseDate( sDate_ )
local sYear = string.sub( sDate_, 1, 4 )
local sMonth = string.sub( sDate_, 6, 7 )
local sDay = string.sub( sDate_, 9, 10 )
local sHour = string.sub( sDate_, 12, 13 )
local sMinutes = string.sub( sDate_, 15, 16 )
local sSeconds = string.sub( sDate_, 18, 19 )
return os.time{ year=sYear, month=sMonth, day=sDay, hour=sHour, min=sMinutes, sec=sSeconds }
end
commandArray = {}
debug = false
smartmeter = "Grid 3P energy"
solarmeter = "Solar energy"
dummymeter = "Consumption"
dummymeter_id = 20
ownconsmeter = "Own consumption"
ownconsmeter_id = 123
dummymeter_trigger = smartmeter
ownconspercent_id = 124
for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName == solarmeter or deviceName == smartmeter) then
smart_p, smart_e = otherdevices_svalues[smartmeter]:match("([^;]+);([^;]+)")
solar_p, solar_e = otherdevices_svalues[solarmeter]:match("([^;]+);([^;]+)")
consumption_p = tonumber(solar_p) - tonumber(smart_p)
consumption_e = solar_e - smart_e
if (tonumber(smart_p) >= 0) then -- if we're currently supplying the grid
own_p = tonumber(solar_p) - tonumber(smart_p)
own_e = tonumber(solar_e) - tonumber(smart_e)
else
own_p = tonumber(solar_p)
own_e = tonumber(solar_e)
end
if (tonumber(solar_p) == 0) then
ownpercent=100
else
ownpercent=100 * tonumber(own_p) / tonumber(solar_p)
end
commandArray[1] = {['UpdateDevice'] = dummymeter_id .. "|0|" .. consumption_p} -- .. ";" .. consumption_e}
if (timeOffset(otherdevices_lastupdate[solarmeter]) < 120) then -- only trust the solar meter if recently updated
commandArray[2] = {['UpdateDevice'] = ownconsmeter_id .. "|0|".. own_p .. ";" .. own_e}
commandArray[3] = {['UpdateDevice'] = ownconspercent_id .. "|0|" .. ownpercent}
end
end
end
return commandArray