I've made the script for uploading my electricity tot pvoutput.
I've onli made the calculatin part.
What i don't understand is the difference between the graph from my P1 smart meter en the calculation.
This is my script:
-- /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
-- This script collects the values below from Domoticz
-- * The Power and energy values (import and export) from a smartmeter
-- * The Power and energy values from a Solar power inverter
-- It then calculates the consumed power and energy from the values above with the formula's
-- * EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
-- * PowerConsumption = PowerGeneration + PowerImport - PowerExport
-- It then updates a virtual device which displays the consumed power and energy in Domoticz
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
local GenerationDeviceName = "Zonnepanelen" -- Device name of the Generated energy
local EnergyDeviceName = "Elektra" -- Name of the energy device that shows imported and exported energy
local ConsumptionIDX = 41 -- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "Verbruik" -- Name of the energy device that shows calculated Consumption
----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("socket.http")
----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
EnergyImportLow = 0 -- in Watt hours
EnergyImportHigh = 0 -- in Watt hours
EnergyExportLow = 0 -- in Watt hours
EnergyExportHigh = 0 -- in Watt hours
EnergyGeneration = 0 -- in Watt hours
PowerGeneration = 0 -- in Watts
EnergyImport = 0 -- in Watt hours
PowerImport = 0 -- in Watts
EnergyConsumption = 0 -- in Watt hours
PowerConsumption = 0 -- in Watts
Debug = "YES" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Lua Functions
----------------------------------------------------------------------------------------------------------
function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end
----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
-- Generated
PowerGeneration, EnergyGeneration = otherdevices_svalues[GenerationDeviceName]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- PowerGeneration = " .. PowerGeneration .. " W");
print(" ----- EnergyGeneration = " .. EnergyGeneration .. " Wh");
end
EnergyImportLow, EnergyImportHigh, EnergyExportLow, EnergyExportHigh, PowerImport, PowerExport = otherdevices_svalues[EnergyDeviceName]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
EnergyImport = EnergyImportLow + EnergyImportHigh
EnergyExport = EnergyExportLow + EnergyExportHigh
if Debug=="YES" then
print(" ----- PowerImport = " .. PowerImport .. " W");
print(" ----- EnergyImportLow = " .. EnergyImportLow .. " Wh");
print(" ----- EnergyImportHigh = " .. EnergyImportHigh .. " Wh");
print(" ----- EnergyImport = " .. EnergyImport .. " Wh");
print(" ----- PowerExport = " .. PowerExport .. " W");
print(" ----- EnergyExportLow = " .. EnergyExportLow .. " Wh");
print(" ----- EnergyExportHigh = " .. EnergyExportHigh .. " Wh");
print(" ----- EnergyExport = " .. EnergyExport .. " Wh");
end
-- Calculate consumption
PowerConsumption = PowerGeneration + PowerImport - PowerExport
if Debug=="YES" then
print(" ----- PowerConsumption = " .. PowerConsumption .. " W");
end
EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
if Debug=="YES" then
print(" ----- EnergyConsumption = " .. EnergyConsumption .. " Wh");
end
-- Update comsumption device in Domoticz
if devicechanged[EnergyDeviceName] then
update(ConsumptionDeviceName, ConsumptionIDX, PowerConsumption, EnergyConsumption, 1)
end
return commandArray
And this are the graphs:
Graph P1 smart meter and calculation added as files.
The graphs are still different while as my opinion they must equal
Can somebody explain me what's going wrong?
Lua Script uploading to PVoutput
Moderator: leecollings
-
- Posts: 4
- Joined: Saturday 09 December 2017 21:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Contact:
Lua Script uploading to PVoutput
- Attachments
-
- calculation.jpg (366.72 KiB) Viewed 479 times
-
- P1 smart meter.jpg (394.29 KiB) Viewed 479 times
Who is online
Users browsing this forum: Bing [Bot] and 1 guest