Sorry, this programming language is completly new to me. Learning every day. How can I separate the values wanted from the tables?
This is the complete script, without the additions it works fine:
Code: Select all
--[[
dzVents script to Parse P1 Smart Meter Electricity value into separate Meter Readings.
Please note that initially counter today will show wrong value at the GUI until next day
To be used for domoticz version >= V4.11305
]] --
local fetchIntervalMins = 1 -- (Integer) Minutes frequency of this script execution 1 = every minute, 10 = every 10 minutes, etc ) must be one of (1,2,3,4,5,6,10,12,15,20,30)
local ScriptVersion = '0.1.8' -- domoticz > V4.11305 / dzVents >= 2.4.28
return {
on = {
timer = { 'every ' .. fetchIntervalMins .. ' minutes' }
},
logging = {
level = domoticz.LOG_DEBUG, -- Uncomment this line to override the dzVents global logging setting
marker = 'SME '.. ScriptVersion
},
data = { lastP1 = { initial = {} }},
execute = function(dz, item)
-- Add device-names between quotes or device idx without quotes
local P1 = dz.devices(32) -- Electra, P1 Smart Meter device (idx or "name") (required)
-- Enter names / idx for devices you want below these comment-lines
-- These devices must be created as new incremental counters. Script might produce wrong values
-- when used with existing ones that already contain values
-- The remaining lines can be removed or commented
local usageLow = dz.devices('Verbruik Laag') -- Meter Usage low, Virtual device, counter incremental
local usageHigh = dz.devices('Verbruik Hoog') -- Meter Usage High, Virtual device, counter incremental
local returnLow = dz.devices('Teruglevering Laag') -- Meter Return Low, Virtual device, counter incremental
local returnHigh = dz.devices('Teruglevering Hoog') -- Meter Return High, Virtual device, counter incremental
-- These devices must be created as Usage (electric)
local usage = dz.devices('Huidig verbruik') -- current Usage
local usageDelivered = dz.devices('Huidige teruglevering') -- current Return
local usagePVdelivered = dz.devices(54) -- current Usage PV production -- added to original script
local usageReal = dz.devices(59) -- current Usage PV excluded -- added to original script
-- No changes required below this line ---
lastP1 = dz.data.lastP1
local function updateCounter(dv, value, previousValue )
if not(dv) then return end
if not(previousValue) then
dz.log("No previous data for " .. dv.name .. " yet; skipping this run",dz.LOG_DEBUG)
return
end
if dv.counter ~= 0 then
value = value - previousValue
end
dv.updateCounter(value)
dz.log("Increment " .. dv.name .. " with: " .. value,dz.LOG_DEBUG)
end
local function updateEnergy(dv, value )
if not(dv) then return end
dv.updateEnergy(value)
dz.log("Set " .. dv.name .. " to: " .. value,dz.LOG_DEBUG)
end
-- Update the device
updateCounter(usageLow, P1.usage1, lastP1.usage1)
updateCounter(usageHigh, P1.usage2, lastP1.usage2)
updateCounter(returnLow, P1.return1, lastP1.return1)
updateCounter(returnHigh, P1.return2, lastP1.return2)
updateEnergy(usage, P1.usage)
updateEnergy(usageDelivered, P1.usageDelivered)
lastP1.usage1 = P1.usage1
lastP1.usage2 = P1.usage2
lastP1.return1 = P1.return1
lastP1.return2 = P1.return2
-- calculate usage with PV-production excluded
usageReal = usagePVdelivered + usage - usageDelivered -- this does not work!
end
}
---------------------------
The additions result in:
2020-08-26 22:34:00.430 Error: dzVents: Error: (3.0.2) SME 0.1.8: An error occurred when calling event handler ElektriciteitInDetail
2020-08-26 22:34:00.430 Error: dzVents: Error: (3.0.2) SME 0.1.8: ...ipts/dzVents/generated_scripts/ElektriciteitInDetail.lua:81: attempt to perform arithmetic on a table value (local 'usagePVdelivered')